aboutsummaryrefslogtreecommitdiff
path: root/174bg/discord-bot
diff options
context:
space:
mode:
Diffstat (limited to '174bg/discord-bot')
-rw-r--r--174bg/discord-bot/.env.example3
-rw-r--r--174bg/discord-bot/main.js15
-rw-r--r--174bg/discord-bot/package.json3
3 files changed, 18 insertions, 3 deletions
diff --git a/174bg/discord-bot/.env.example b/174bg/discord-bot/.env.example
index 4e6e4bf..c262567 100644
--- a/174bg/discord-bot/.env.example
+++ b/174bg/discord-bot/.env.example
@@ -1,2 +1,3 @@
DISCORD_CLIENT_ID=
-DISCORD_BOT_TOKEN= \ No newline at end of file
+DISCORD_BOT_TOKEN=
+DISCORD_GUILD_ID= \ No newline at end of file
diff --git a/174bg/discord-bot/main.js b/174bg/discord-bot/main.js
index deef3ff..bcf0cea 100644
--- a/174bg/discord-bot/main.js
+++ b/174bg/discord-bot/main.js
@@ -164,17 +164,30 @@ client.on(Events.ClientReady, async (readyClient) => {
process.env.DISCORD_BOT_TOKEN,
);
+ // clear global commands
await rest.put(Routes.applicationCommands(process.env.DISCORD_CLIENT_ID), {
+ body: [],
+ });
+
+ console.log("Cleared global application commands.");
+
+ // register guild-scoped commands
+ await rest.put(Routes.applicationGuildCommands(process.env.DISCORD_CLIENT_ID, process.env.DISCORD_GUILD_ID), {
body: commands.map((command) => command.data.toJSON()),
});
- console.log("Successfully registered application commands.");
+ const guild = await client.guilds.fetch(process.env.DISCORD_GUILD_ID);
+
+ console.log(`Successfully registered application commands for guild ${process.env.DISCORD_GUILD_ID} (${guild ? guild.name : "Unknown"}).`);
} catch (error) {
console.error(error);
}
});
client.on(Events.InteractionCreate, async (interaction) => {
+ // only respond to interactions in the specified guild
+ if (interaction.guild.id !== process.env.DISCORD_GUILD_ID) return;
+
if (interaction.isChatInputCommand()) {
if (
commands.some((command) => command.data.name === interaction.commandName)
diff --git a/174bg/discord-bot/package.json b/174bg/discord-bot/package.json
index d881ea2..d3e8dac 100644
--- a/174bg/discord-bot/package.json
+++ b/174bg/discord-bot/package.json
@@ -9,5 +9,6 @@
"bufferutil": "^4.1.0",
"discord.js": "^14.26.4",
"zlib-sync": "^0.1.10"
- }
+ },
+ "type": "module"
}