|
1 | 1 | import "dotenv/config"; |
2 | | -import { Client, Collection } from "discord.js"; |
| 2 | +import { Client, Collection, LimitedCollection } from "discord.js"; |
3 | 3 | import { MyContext } from "./interfaces"; |
4 | 4 | import { loadCommands, commandHandler } from "./handlers/CommandHandler"; |
| 5 | +import { messageHandler } from "./handlers/MessageHandler"; |
5 | 6 |
|
6 | 7 | (async function () { |
7 | 8 | const context: MyContext = { |
8 | 9 | client: new Client({ |
9 | | - intents: ["GUILDS"], |
| 10 | + intents: ["GUILDS", "GUILD_MESSAGES"], |
10 | 11 | presence: { |
11 | | - activities: [{ type: "WATCHING", name: "Discord.JS channel" }], |
| 12 | + activities: [{ type: "PLAYING", name: "Read the docs" }], |
12 | 13 | status: "online", |
13 | 14 | }, |
14 | | - // For DMs, a partial channel object is received, in order to receive dms, CHANNEL partials must be activated |
| 15 | + // For DMs, a partial channel object is received, in order to receive dms, CHANNEL partials must be activated |
15 | 16 | partials: ["CHANNEL"], |
| 17 | + makeCache: (manager) => { |
| 18 | + //! Disabling these caches will break djs funcitonality |
| 19 | + const unsupportedCaches = [ |
| 20 | + "GuildManager", |
| 21 | + "ChannelManager", |
| 22 | + "GuildChannelManager", |
| 23 | + "RoleManager", |
| 24 | + "PermissionOverwriteManager", |
| 25 | + ]; |
| 26 | + if (unsupportedCaches.includes(manager.name)) return new Collection(); |
| 27 | + // Disable every supported cache |
| 28 | + return new LimitedCollection({ maxSize: 0 }); |
| 29 | + }, |
16 | 30 | }), |
17 | 31 | commands: new Collection(), |
18 | 32 | cooldownCounter: new Collection(), |
19 | 33 | }; |
20 | 34 | const docsBot = context.client; |
21 | 35 | await loadCommands(context); |
| 36 | + |
22 | 37 | docsBot.on("error", console.error); |
23 | 38 | docsBot.on("warn", console.warn); |
24 | | - docsBot.on("ready", (client) => { |
| 39 | + |
| 40 | + docsBot.once("ready", (client) => { |
25 | 41 | console.info(`Logged in as ${client.user.tag} (${client.user.id})`); |
26 | 42 | }); |
| 43 | + |
| 44 | + docsBot.on("messageCreate", messageHandler); |
27 | 45 | docsBot.on("interactionCreate", commandHandler.bind(null, context)); |
28 | 46 |
|
29 | 47 | docsBot.login(process.env.TOKEN); |
|
0 commit comments