Automatically delete a old slash command that has been renamed?
How would I achieve this, I am using sapphire 3.1.3, and I want it to automatically delete the old one when it detects a change.
18 Replies
Sapphire currently doesn't have a feature to automatically delete slash commands. You can use the DJS methods for now. In the future we'll add a feature where we would use the Build Overwrite endpoint of the API meaning on every boot all your commands get wiped and reset - with the caveat that
idHints
will lose its use case when that is configured.is it possible to make a listener of sort
in the
ready
listener you could check which commands are in the Command store and which you can find through the DJS application commands methods, diff those lists and remove any that are not in the Commands storeyeah thats what im doing rn
would this line of code work
client.application?.commands.cache.forEach((command: ApplicationCommand) => {command.delete()})
I actually have absolutely no idea lol sorry
im testing it rn
lets see
client.application?.commands.set([])
I think this works too
at least the docs say it doesclient.application?.commands.set([]);
but you cannot use that in the ready listener because you'll delete everything sapphire just registered ofr you
you need to diff the lists
how would I list the commands then
you compare https://discord.js.org/#/docs/discord.js/v13/class/ApplicationCommandManager to
container.stores.get('commands')
which is https://www.sapphirejs.dev/docs/Documentation/api-framework/classes/CommandStore so you can compare names for exampleexcuse me
where did container come from
oh wait nvm
Sapphire Framework
Using and extending container | Sapphire
The container is a way in which Sapphire achieves Dependency Injection. This is a very useful feature, since it
?
it's not a promise
I'm not going to spoonfeed you code fyi. I gave you the directions to go for, you're on your own from there on.
I suggest making a script file to delete all of the slash commands at once (or just give the IDs) with rest api and rust that file wheneber you want to reset the commands.
yeah I cant figure this out
I never even told you to spoonfeed me
so ok
Solution
A PR has been created that will add this as a feature