Is there a way to use Sapphire to reset previously registered slash commands?

So, I've got a bot I'm working on that uses Sapphire and recently, just as an example, I generated a unban.ts slash command while I had npm run:watch running (so it registered the command with the bot). I then moved the unban.ts file to the Moderation folder I created for commands like this one, and now I need the previous unban command to become unregistered. Is there any way I could have Sapphire automatically unregister slash commands created like this one upon finding that the files for the commands no longer exist? Or am I gonna have to do it the old fashioned way using discord.js?
Solution:
Then it would probably be because TypeScript does not delete old files from the dist folder when you move them in the src folder. Clean your dist folder and rebuild.
Jump to solution
17 Replies
Favna
Favna7mo ago
You have several options 1. Enable BulkOverwrite mode for the Sapphire registry. This means that on every boot all your commands are overwritten by the Sapphire registry, regardless of what was there before - Advantage is that you also dont need to track idHints - Disadvantage is that you give Sapphire full control over your registry, for what it's worth - One day I'll somehow convince Vladdy to make this the default but he's stubborn angery You enable this by calling this early on in your application startup (i.e. in a setup file or at the top of your index file):
import { ApplicationCommandRegistries, RegisterBehavior } from '@sapphire/framework';

ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(RegisterBehavior.BulkOverwrite);
import { ApplicationCommandRegistries, RegisterBehavior } from '@sapphire/framework';

ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(RegisterBehavior.BulkOverwrite);
2. Use the DiscordJS methods as you mentioned 3. Use https://slash-commands-gui.androz2091.fr
Slash Commands GUI
Graphical User Interface to explore and edit your bot's slash commands!
Doc Snipes
Doc Snipes7mo ago
Yeah I have that already set in my setup.ts file in the image provided, it doesn't seem to be working on the unban command, I think because I moved it from the root of the Commands folder and into a Moderation subfolder
No description
Solution
Favna
Favna7mo ago
Then it would probably be because TypeScript does not delete old files from the dist folder when you move them in the src folder. Clean your dist folder and rebuild.
Doc Snipes
Doc Snipes7mo ago
Ahhhhhh okay thank you so much, I just started getting into using TS and I didn't even think about that
Favna
Favna7mo ago
btw just out of curiosity but what is that "5x" in your screenshot think ?
Doc Snipes
Doc Snipes7mo ago
ah it's an extension, one sec ill link it
Doc Snipes
Doc Snipes7mo ago
Power Mode - Visual Studio Marketplace
Extension for Visual Studio Code - Your code is powerful, unleash it! The extension made popular by Code in the Dark has finally made its way to VS Code.
Doc Snipes
Doc Snipes7mo ago
does it take a while for the commands to refresh/re-register? because I'm still not seeing any changes with the /unban slash command despite deleting the dist folder and re-running my bot. I removed the unban.ts file entirely and removed the dist/ folder, but the slash command is still appearing, although the bot doesn't do anything when it's run nvm I found the issue, I had set the following in client.ts file:
const guildIds = ['1175382045623586877']; ApplicationCommandRegistries.setDefaultGuildIds(guildIds);
const guildIds = ['1175382045623586877']; ApplicationCommandRegistries.setDefaultGuildIds(guildIds);
so the commands in my guild weren't updating after I removed that code. re-adding it has the issue sorted
HealthCareUSA
HealthCareUSA6mo ago
@Favna @vladdy why is this a thing? how does a bot in more than one server (e.g., a public bot) avoid this issue? does it "eventually" propogate properly? i have a feeling i have found the information https://www.sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/what-is-it please verify
Favna
Favna6mo ago
Normally commands should always re-register regardless as based on your config. If they removed it then the commands got registered globally and would've probably showed up double (or if they used bulk overwrite single but as global commands). Ultimately I'm not entirely sure what Doc's problem was truth be told. I've never had problems with bots like @Dragonite and @Gemboard
HealthCareUSA
HealthCareUSA6mo ago
So what happened when I switched my bot from Python to Sapphire with the same secret key and all of the old commands still showed up (until I specified the guild ID)? If I add a new slash command without the guild ID specified I imagine it wouldn’t show up for the same reason
Favna
Favna6mo ago
because sapphire doesnt delete old commands unless you use bulk overwrite if you add no guild id then it's global
HealthCareUSA
HealthCareUSA6mo ago
okay that would explain that then thank you
Doc Snipes
Doc Snipes5mo ago
It was half-not knowing that I needed to delete my /dist folder, and half-going on a completely wrong tangent to fix it. The setting default guilds thing was something I did hoping it would "reset" my bot's commands, at least for my server... Or something. Can't remember exactly what the logic was but I was sorta just breaking it until it worked again I guess lol
HealthCareUSA
HealthCareUSA5mo ago
wait what about deleting dist?
Favna
Favna5mo ago
sapphire will not unregister commands of which the files no longer exist (unless you use bulk overwrite)
Doc Snipes
Doc Snipes5mo ago
If you dont delete your dist folder after moving/removing a slash command it will continue to persist in the JS compiled /dist folder