Register/delete guild commands on call
As the title already should explain my question but here I go in depth: Is it possible to register/delete guild commands on a specific guild in the runtime?
21 Replies
Discord.js
Discord.js is a powerful node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Oh and also uh
You also have to add it to the command store so it gets recognised
Just keep in mind that you're treading in the advanced territory. It's possible yes but you'll have to write a fair bit of code
For example you also have to track the commands in an external database or similar to re-register them on next reboot
Oh yeah I did that in the past myself but I thought maybe there is a way for sapphire to do so but it's fine then I'll have to re-use my old code 😄
Thx for the answers <:PES_Ok:493353112501747712>
yeah so the only sapphire thing you need to add is something along the lines of
Assuming of course it's not there yet. From the top of my head we don't check
guildIds
when a command interaction comes in so you could also just have a command in the store at boot time (by having a file for it) and only register it in your test guild through guildIds (or don't register it at all) then add additional guilds later.
@vladdy what do you think of exposing that function we call in CoreReady to register all commands so people can use the out-of-command way of adding to the registries (by acquiring them) and then calling that function to do registration?I would rather first get an example use case haha
Realistically speaking, registries are pretty self contained
So it shouldn't take too much code
I'll think about how to properly expose this when I'm back home as I'd rather we didn't just expose our register methods (esp since this wouldn't be compatible with bulk override)
Correct me if I'm wrong here ShowCast but I think it's something like this
1. Some commands are either opt-in on a per-guild basis through a dashboard or there are premium commands so they are selectively made available
2. The command availability is tracked in a database. For this example we will reason this from boot time, so in our own Ready event.
dummy code:
I feel like instead we can as a method on registries that trigger just that commands registries and handles everything else for the user, but definitely an advanced feature not for most users to use
@ShowCast if you can share an example of current code that would be lovely
definitely that latter part yes
My code base is an old use case.
My use case would be the following:
There is a premium system. If a server owner redeems a premium key for his server the command /premium should get registered.
My old code was for some other use case where on boot a repository posted the command to every guild but with a configurationable command per server.
I created this earlier before I started to use sapphire so this isn't compatible yet
Oh i see
So question
Would appreciate that as then I would only need to call it on guild base when like the redeemd premium key command is ran on that guild
Why can't you add this into the register application command method?
And then reload just that command
Cause then you can fetch this at bootup from a db of ids
And whenever you reload
Wait shit that won't handle deleted unless you use bulk overwrite
The delete would happen in my case when premium expired or the key on the guild is unlinked with a command
So yeah that would be possible aswell
Hmmmm
Let me get home
ofc 😄
And I'll see what i can concoct
Perfect, I'm curious what your mind will print out
Might not even need any code on our part
Do you use bulk overwrite? @ShowCast
Nope
@ShowCast something like this should be enough
Only thing it wont handle is if you register the cmd while the bot is offline
but i'm sure you can figure that out in a ready listener :3
hope it helps!
(hope it works >~>)
technically speaking you can inline newGuildIds with the for loop
This way you get to reuse as much work as there already is for command registration, and have to only deal with deletions
(if you dont wanna deal with tracking those too, bulk overwrite MIGHT WORK but no guarantees)
I will try that thanks for the code snippet <:PES2_LovePat:513350757333073930>