Skip to content

Commit 8c84e1e

Browse files
committed
Fixed autocomplete not working issues
1 parent df23f19 commit 8c84e1e

File tree

11 files changed

+927
-783
lines changed

11 files changed

+927
-783
lines changed

src/bot.ts

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,80 @@ import { loadCommands, interactionCreateHandler } from "./handlers/InteractionCr
44
import { messageHandler } from "./handlers/MessageHandler.js";
55
import { deleteButtonHandler } from "./utils/CommandUtils.js";
66
import {
7-
ActivityType,
8-
Client,
9-
Collection,
10-
GatewayIntentBits,
11-
LimitedCollection,
12-
Partials
7+
ActivityType,
8+
Client,
9+
Collection,
10+
GatewayIntentBits,
11+
Interaction,
12+
LimitedCollection,
13+
Partials
1314
} from "discord.js";
1415

1516
(async function () {
16-
const context: MyContext = {
17-
client: new Client({
18-
intents: [
19-
GatewayIntentBits.Guilds,
20-
GatewayIntentBits.GuildMessages
21-
],
22-
presence: {
23-
activities: [{ type: ActivityType.Playing, name: "Read the docs" }],
24-
status: "online",
25-
},
26-
// For DMs, a partial channel object is received, in order to
27-
// receive dms, Partials.Channel must be activated
28-
partials: [
29-
Partials.Channel
30-
],
31-
makeCache: (manager) => {
32-
//! Disabling these caches will break djs functionality
33-
const unsupportedCaches = [
34-
"GuildManager",
35-
"ChannelManager",
36-
"GuildChannelManager",
37-
"RoleManager",
38-
"PermissionOverwriteManager",
39-
];
40-
if (unsupportedCaches.includes(manager.name)) return new Collection();
41-
// Disable every supported cache
42-
return new LimitedCollection({ maxSize: 0 });
43-
},
44-
}),
45-
commands: {
46-
buttons: new Collection(),
47-
selectMenus: new Collection(),
48-
slashCommands: new Collection(),
49-
},
50-
cooldownCounter: new Collection(),
51-
};
52-
const docsBot = context.client;
53-
await loadCommands(context);
54-
// Add delete button handler
55-
context.commands.buttons.set("deletebtn", { custom_id: "deletebtn", run: deleteButtonHandler });
17+
const context: MyContext = {
18+
client: new Client({
19+
intents: [
20+
GatewayIntentBits.Guilds,
21+
GatewayIntentBits.GuildMessages
22+
],
23+
presence: {
24+
activities: [{ type: ActivityType.Playing, name: "Read the docs" }],
25+
status: "online",
26+
},
27+
// For DMs, a partial channel object is received, in order to
28+
// receive dms, Partials.Channel must be activated
29+
partials: [
30+
Partials.Channel
31+
],
32+
makeCache: (manager) => {
33+
//! Disabling these caches will break djs functionality
34+
const unsupportedCaches = [
35+
"GuildManager",
36+
"ChannelManager",
37+
"GuildChannelManager",
38+
"RoleManager",
39+
"PermissionOverwriteManager",
40+
];
41+
if (unsupportedCaches.includes(manager.name)) return new Collection();
42+
// Disable every supported cache
43+
return new LimitedCollection({ maxSize: 0 });
44+
},
45+
}),
46+
commands: {
47+
buttons: new Collection(),
48+
selectMenus: new Collection(),
49+
slashCommands: new Collection(),
50+
},
51+
cooldownCounter: new Collection(),
52+
};
53+
const docsBot = context.client;
54+
await loadCommands(context);
55+
// Add delete button handler
56+
context.commands.buttons.set("deletebtn", { custom_id: "deletebtn", run: deleteButtonHandler });
5657

57-
docsBot.on("error", console.error);
58-
docsBot.on("warn", console.warn);
58+
docsBot.on("error", console.error);
59+
docsBot.on("warn", console.warn);
5960

60-
docsBot.once("ready", (client) => {
61-
console.info(`Logged in as ${client.user.tag} (${client.user.id})`);
62-
});
61+
docsBot.once("ready", (client) => {
62+
console.info(`Logged in as ${client.user.tag} (${client.user.id})`);
63+
});
6364

64-
docsBot.on("messageCreate", messageHandler);
65-
docsBot.on("interactionCreate", interactionCreateHandler.bind(null, context));
65+
docsBot.on("messageCreate", messageHandler);
66+
docsBot.on("interactionCreate", (interaction: Interaction<"cached">) => {
67+
interactionCreateHandler(context, interaction);
68+
});
6669

67-
docsBot.login(process.env.TOKEN);
70+
docsBot.login(process.env.TOKEN);
6871
})();
6972

7073
process.on("unhandledRejection", async (err) => {
71-
console.error("Top Level Unhandled Promise Rejection:\n", err)
72-
})
74+
console.error("Top Level Unhandled Promise Rejection:\n", err);
75+
});
7376

7477
process.on("uncaughtException", async (err) => {
75-
console.error("Top Level Uncaught Promise Exception:\n", err)
76-
})
78+
console.error("Top Level Uncaught Promise Exception:\n", err);
79+
});
7780

7881
process.on("uncaughtExceptionMonitor", async (err) => {
79-
console.error("Top Level Uncaught Promise Exception (Monitor):\n", err)
80-
})
82+
console.error("Top Level Uncaught Promise Exception (Monitor):\n", err);
83+
});

0 commit comments

Comments
 (0)