This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.js
83 lines (62 loc) · 3.32 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const Discord = require("discord.js");
const chalk = require('chalk');
class DotwoodClient extends Discord.Client {
constructor(settings = {}) {
super(settings);
this.config = require("./configs/client")(settings);
this.messageFunctions = require("./util/messageFunctions");
this.interactionFunctions = require("./util/interactionFunctions");
this.handler = require("./util/handlers");
require("./util/clientFunctions")(this);
this.handler.checkForUpdates();
this.config.token = this.config.token ? this.config.token : undefined;
if (this.config.token == undefined || this.config.token == "") throw new Error(`Bot token is required!`);
this.config.id = this.config.id ? this.config.id : undefined;
if (this.config.id == undefined || this.config.id == "") throw new Error(`Bot id is required!`);
this.config.prefix = this.config.prefix ? this.config.prefix : undefined;
if (this.config.prefix == undefined || this.config.prefix == "") throw new Error(`Bot prefix is required!`);
super.on("ready", () => {
if (!this.config.commands) console.log(chalk.green(`${this.user.username} is ready to use on ${this.getGuilds().size} servers!`));
if (this.config.commands) console.log(chalk.green(`${this.user.username} is ready to use on ${this.getGuilds().size} servers! Loaded ${this.commands.size} commands`));
setInterval(() => {
let text = this.config.status;
const randomText = text[Math.floor(Math.random() * text.length)];
this.user.setActivity(randomText, { type: this.config.statusType });
}, 50000)
});
if (this.config.commands) this.commands = this.handler.loadCommands(this.config.commands);
if (this.config.events) this.handler.loadEvents(this.config.events, this);
if (this.config.slashcommands && (this.config.slashcommandsType && this.config.slashcommandsType == "ALL")) this.slashCommands = this.handler.loadSlashCommands(this.config.slashcommands, this);
if (this.config.slashcommands && (this.config.slashcommandsType && this.config.slashcommandsType !== "ALL")) this.slashCommands = this.handler.loadGuildSlashCommands(this.config.slashcommands, this.config.slashcommandsType, this);
if (this.config.slashcommands && !this.config.slashcommandsType) throw new Error(`Slash commands type is required!`);
const messageEvent = require(`dotwood.js/events/messageCreate`);
this.on("messageCreate", messageEvent.bind(null, this));
const interactionEvent = require(`dotwood.js/events/interactionCreate`);
this.on("interactionCreate", interactionEvent.bind(null, this));
}
async login() {
this.handler.startup();
await super.login(this.config.token);
this.config.id = this.user.id;
}
getGuilds() {
return this.guilds.cache;
}
setPrefix(prefix) {
this.config.prefix = prefix;
return this;
}
setStatus(status) {
this.config.status = status;
return this;
}
setStatusType(statusType) {
this.config.statusType = statusType;
return this;
}
setEmbedColor(color) {
this.config.embedColor = color;
return this;
}
}
module.exports = DotwoodClient;