memati.js
Version:
Bot yapabileceğiniz modüldür.
32 lines (28 loc) • 974 B
JavaScript
const fetch = require('node-fetch');
const Constants = require('../util/Constants');
class RequestHandler {
constructor(client, token) {
this.client = client;
this.token = token;
}
async request(method, endpoint, stringify) {
const url = `https://discord.com/api/${endpoint}`;
const header = {
"Content-Type": "application/json",
"Authorization": `Bot ${this.token}`
};
const bodys = JSON.stringify(stringify);
const res = await fetch(url, {
method: method,
headers: header,
body: bodys
}).catch(async (err) => {
return this.sendError(err.message, Constants.ErrorTypes.INVALID_REQUEST);
});
return res.json();
}
async sendError(msg, type) {
return console.log(`(node:1938) UnhandledPromiseRejectionWarning: Error [${type}]: ${msg}`);
}
}
module.exports = RequestHandler;