memati.js
Version:
Bot yapabileceğiniz modüldür.
36 lines (31 loc) • 1.36 kB
JavaScript
const RequestHandler = require('../rest/RequestHandler');
const Constants = require('../util/Constants');
class Bot {
constructor(client, token) {
this.client = client;
this.token = token;
this.handler = new RequestHandler(client, token);
}
async sendMessage(channelId, cont, { embeds } = {}) {
const getChannel = this.client.channels.cache.get(channelId);
if (!getChannel) return this.handler.sendError(Constants.Errors.UNKNOWN_CHANNEL, Constants.ErrorTypes.UNKNOWN_CHANNEL);
const data = {
content: cont,
embeds: embeds
};
return this.handler.request("POST", `channels/${channelId}/messages`, data);
}
async deleteMessage(channelId, messageId) {
const getChannel = this.client.channels.cache.get(channelId);
if (!getChannel) return this.handler.sendError(Constants.Errors.UNKNOWN_CHANNEL, Constants.ErrorTypes.UNKNOWN_CHANNEL);
return this.handler.request("DELETE", `channels/${channelId}/messages`, messageId);
}
async run(token = this.token) {
this.client.login(token).then(() => {
console.log(`Bot stated with ${this.client.user.tag}`);
}).catch(async (err) => {
throw new Error(err.message);
});
}
}
module.exports = Bot;