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/main.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to '174bg/discord-bot/main.js') 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) -- cgit v1.2.3