-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
server.ts
71 lines (64 loc) · 1.69 KB
/
server.ts
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
import { Client } from "discordx";
import {
Interaction,
Message,
Options,
GatewayIntentBits,
Partials,
} from "discord.js";
import * as utils from "./utils.js";
import { dirname, importx } from "@discordx/importer";
const log = utils.getLogger("bot");
log.info(`booting up...`);
// initialize the bot and all modules
const bot = new Client({
shards: "auto",
makeCache: Options.cacheWithLimits({
MessageManager: {
maxSize: 100,
},
}),
intents: [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.Guilds,
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
botGuilds: process.env.DEV_GUILD ? [process.env?.DEV_GUILD] : undefined,
});
bot.on("interactionCreate", (interaction: Interaction) => {
bot.executeInteraction(interaction);
});
/* Bot event listeners */
bot.on("guildCreate", (guild: any) => {
log.info(utils.prettyLog({ guild }, "joined"));
utils.updateServerCount(bot);
});
bot.on("guildDelete", (guild: any) => {
log.info(utils.prettyLog({ guild }, "left"));
utils.updateServerCount(bot);
});
bot.on("error", (error: any) => {
log.error("client error received");
log.error(error);
console.log(error);
});
bot.once("ready", async () => {
await bot.initApplicationCommands();
log.info(
"Bot is ready! Username:",
bot.user?.username,
"/ Servers:",
bot.guilds.cache.size
);
utils.updateServerCount(bot);
});
// start the engines!
if (utils.token) {
await importx(dirname(import.meta.url) + "/modules/*.js");
await bot.login(utils.token);
} else {
log.error("No token provided");
}