Issue with Duplicate Commands When Bot Is Added to Another Server

Hi everyone, I’m facing an issue with my bot’s deploy script, and I’d appreciate your help in resolving it. Here’s the situation: 1. The bot works perfectly when added to a new server via top.gg. Commands deploy as expected, with global commands available and no duplication. 2. The bot is also in an admin server (used for managing guild-specific commands). In this admin server, both global commands and admin commands work fine — no duplication issues. 3. The problem arises when someone from the admin server uses the “Add to Server” option to invite the bot to their own server: • The user ends up with duplicate global commands. • Additionally, they also get the admin commands, which should not be available in their server. It seems like the commands for the admin server are being improperly scoped or carried over during the re-invite process. Here’s what my deploy script does: • Cleans up global commands and admin guild-specific commands before deployment. • Deploys global commands across all servers and admin commands only in the admin server. Despite this, the issue persists when someone from the admin server invites the bot to a new server. How can I prevent global command duplication and restrict admin commands to the admin server in such scenarios? Any guidance or best practices would be greatly appreciated! please checkout the code here -> https://gist.github.com/Kiran-Alex/71d139ff426e19477d2969d2a9c11abd
Gist
gist:71d139ff426e19477d2969d2a9c11abd
GitHub Gist: instantly share code, notes, and snippets.
17 Replies
d.js toolkit
d.js toolkit2d ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Amgelo
Amgelo2d ago
why are you cleaning global commands? or why are you even cleaning (both global and guild commands) in the first place?
Kbone22
Kbone22OP2d ago
IDK what im doing man , im just mad that im getting duplicate commands and just doing whatever that works with help of ai
Amgelo
Amgelo2d ago
a rest.put isn't a push, it's more like a set it "replaces" all existing commands with the ones you pass so it deletes extra commands, creates new ones and doesn't do anything for existing (exact) ones that being said, the code you shared should work fine, but it has unnecessary extra api calls, you only need the last two put calls is this the only place where you deploy commands? are you running this on guild join or something?
Kbone22
Kbone22OP2d ago
Thanks for clarifying! That makes sense about rest.put essentially replacing all commands with the ones I pass. I realize now I might be overcomplicating things with the cleanup calls. To answer your questions: 1. Yes, this is the only place where I deploy commands. 2. No, I’m not deploying commands on guild join or in any other place. This script is run manually to deploy or update commands. However, the issue I’m facing is that when someone from the admin server invites the bot to their own server using the “Add to Server” option: • They end up with duplicate global commands. • They also get admin-specific commands in their server, which shouldn’t happen. Could it be something with how permissions or command scopes are being handled when the bot is invited from the admin server? Or am I missing something in my deployment process?
Amgelo
Amgelo2d ago
what do you mean by "duplicate global commands"? two global commands can't have the same name, even if you did want that, that'd result in an error the only way you can end up with two commands with the same name is if you deploy one in the guild, and one globally
Kbone22
Kbone22OP2d ago
By “duplicate global commands,” I mean that when someone from the admin server uses the “Add to Server” option to add the bot to their server, the new server ends up seeing: 1. The global commands appearing twice. 2. The admin commands (which should be exclusive to the admin server) also showing up in the new server.
Amgelo
Amgelo2d ago
if this is the only deploy script and it's ran manually then that shouldn't happen I'd recommend you double check whether this is really the only place where you're deploying commands maybe this is happening somewhere else
Kbone22
Kbone22OP2d ago
I usually deploy commands on linode but i used do it in my pc (i made sure im using other env variables)
Amgelo
Amgelo2d ago
I mean in your code
Kbone22
Kbone22OP2d ago
ahhhhhhhh is see
Amgelo
Amgelo2d ago
the issue makes it sound like you're deploying all commands, as guild commands to that guild, whenever you join it
Kbone22
Kbone22OP2d ago
Actually, I deploy the commands in two steps. In the first step, I deploy all commands except the admin commands. In the second step, I deploy guild-specific commands, which are the admin commands. However, whenever someone joins the support server (the guild with both admin commands and other global commands) and tries to add the bot to their server using the "Add to Server" option, they end up with duplicate global commands. Interestingly, the guild-specific commands do not appear twice.
No description
Amgelo
Amgelo2d ago
this again
they end up with duplicate global commands
- one set of commands is deployed globally, so it's present in all guilds (depends on contexts but let's forget that for simplicity) - the other duplicate set would come from deploying to that guild (they're deployed as guild commands) the mix of both would end up with you seeing "duplicate commands"
Interestingly, the guild-specific commands do not appear twice.
because those commands aren't deployed globally, you would've only deployed them to that guild only basically the whole issue is explained if you somewhere do this the code you shared does not do that so it would be somewhere else
Kbone22
Kbone22OP2d ago
True Man cuz that's the only issue even i can think of Thanks Alot G
Amgelo
Amgelo2d ago
you should search in your code with something like vscode or grep for rest.put, application.commands or guild.commands usages if you've changed host providers or something like that it could be possible that you have some old code that used to do that still running somewhere you can try changing your token for that
Kbone22
Kbone22OP2d ago
Thanks Alottt Mann , You saved me Today

Did you find this page helpful?