Ben855 - How are most of y'all using IDhints in pr...
How are most of y'all using IDhints in production? Are you just manually hard coding them every time you decided to add a command or is there a better option?
29 Replies
That’s what I do too, hardcode it 😦
oof
There’s no way to inject it somehow too which is hard sometime
wdym buy that? If I have a map or something that was setup before the bot is constructed, wouldn't I be able to set the IDhint to
map.get('some other id that I use in places')
?Yeah you gotta override a lot of things then, when the registry calls start
Why would that be the case though? If the hint resolves before the registry even exists why would that matter.
If you resolve the hint before the registry exists then in that case you will have to hardcode the Id again
Because you won’t like to make the API call twice
One from sapphires side and one from yours side to get the command ids
I'm not following you. Why would the API get called before the client is instantiated?
When the Ids aren’t hardcoded and you want to resolve it dynamically
Else it will be justi what it’s now
Right but I'm not resolving it from the API. I'm planning to resolve them from my database before the client is instantiated.
Then you can just make a custom command class and inject the id from there I think
ooh thats a good idea. If its injected in the command constructor that will be before any registry calls are made right?
Yeah, I do that to register the command using decorator. Pretty quick setup, you can see the implementation here https://github.com/r-priyam/goblin/blob/main/src/lib/extensions/GoblinCommand.ts
I've already got a custom command class set up for some global permissions and global subcommand stuff. I can probably add the id hint resolution there as long as the constructor runs to completion before any registry api calls are made.
I use it to register the command for myself so that I don’t have to call an extra method lol
Yeah that probably would work. I'll give it a shot I guess.
Cool
I use environment
One environment var for every command?
Thats a lot of environment variables.
well, not in my case because I use group of subcommands
And well, in the case of individual commands, well, that would be enough if you have enough commands, but this way you can update the id hints without having to change your code
Yeah thats gonna be a hard pass.
I marked as a solution mostly to make Answer Overflow happy and because thats what I'm currently attempting to do. I'm still very much open to any ideas though.
Okay heres my final solution for anyone wondering. About a minute and a half after my bot starts, I save all command IDs (not discord snowflakes, just identifiers I have for each command that wont change even if the name changes) and their interaction IDs into my database. This way any new commands are always saved after they are created. Before bot startup, I populate a map with that information from the DB and make it accessible on container. I then can use that map when registering commands to get any idHints for that specific command. So far this has worked pretty well in testing.
Or use env vars
It seems to me a very complex system for that
almost 40 commands remember
Well in my opinion I don't see the problem of having several environment
and more to be added on later. This way I dont have to start my bot in prod, get the id once its registered, add it to my env vars, and then restart my bot to have it actually take affect. Its a whole lot of manual work in what I currently have as a completely automated build and deployment process.
Having a lot is only a minor issue to me tbh. Its more that I want something automatic since everything else about my deployments doesnt require any manual intervention other than a single commit.
Remember that the ids do not change, that is, it is something that you will only do once
And you don't need to restart your bot to see the new ids, you can use apps (https://slash-commands-gui.androz2091.fr/) to manage your slash commands and see their ids
Then put it in the environment variables and that's it.
* once every time I slashify a command or add a new one. So thats already almost 40 times with more to come in the future. It might not be a ton of effort but its more than my new no effort setup.
Now I just never have to worry about it. They should always just work™️ on startup.