From a36bee323d7de1d55b92e9c6bf6e4fb3badd4381 Mon Sep 17 00:00:00 2001 From: "Alex Pooley (@zuedev)" Date: Wed, 15 Jul 2026 11:32:32 +0100 Subject: guild scoping --- 174bg/discord-bot/.env.example | 3 ++- 174bg/discord-bot/main.js | 15 ++++++++++++++- 174bg/discord-bot/package.json | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) (limited to '174bg') 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" } -- cgit v1.2.3