Open Wissididom opened 1 year ago
Just wanted to add to this. I really like this idea, especially the commands. I would say
/admin update
. I am not sure about the delete command, but maybe we can add this to admin config options.
But most importantly, this is going to be useless for anyone running the bot the first time who hasn't set up the commands yet. For this reason, I think we can have a feature where it runs the setupCommands.ts
once on first run. Additionally, we can have a check for version number so that if the version changes, it runs the updated setupCommands.ts
when the bot restarts.
I think we can achieve this pretty easily by saving the version to the database and comparing it to the hardcoded version every new release, so that a git pull would trigger the commands to be readded.
I am not sure about the delete command, but maybe we can add this to admin config options.
My thinking for the delete command was that while updating the commands, currently I call the create endpoint which autmatically updates the commands if they exist and create them if they don't exist. With that you could also remove a command if it was implemented earlier and for some reason isn't needed anymore. I would put those commands behind bot-owner-only anyways. I might even look into slash command permissions, if it is possible to hide the commands from people that are not, but I think that won't be possible, because afaik Discord always shows all commands to Server Owner and Admins regardless of permissions.
For this reason, I think we can have a feature where it runs the setupCommands.ts once on first run. Additionally, we can have a check for version number so that if the version changes, it runs the updated setupCommands.ts when the bot restarts.
That would only work if we make releases in between of command changes I think, because if we change something without making a new version. As for the first run I think it would be easiest to maybe have a table in the DB called e. g. data or config with a name, a value and a configtype column where we have an entry like the following (which if non-existent is assumed a value of true):
name |
value | configtype |
---|---|---|
FIRST_RUN | true | BOOLEAN |
Also for that I think I'd either create a separate setupCommands.ts
file or edit that file to be callable by index.ts
without creating a second WebSocket Connection to Discord's Gateway, because currently it would do that and then call process.exit
when finished.
I think we can achieve this pretty easily by saving the version to the database and comparing it to the hardcoded version every new release, so that a git pull would trigger the commands to be readded.
I think the easiest options for that are:
git
installed and the directory is a git repo we maybe could also simply call git describe
to get the version by using the child_process
module.package.json
because there already is a version field.version.ts
file that gets imported everywhere where we need to know the version. As for the Database I think we could use the same table we used above for the FIRST_RUN
, maybe:name | value | configtype |
---|---|---|
VERSION | 1.0.0 | STRING |
I'm curious how existing bots check the existing commands and update them. Ideally I would like to look into ways of completely removing it as a manual process.
I can see some of the commands being toggled through admin options. Regarding this, I think that the commands should always exist on the server but maybe an ephemeral message saying that the command is disabled. That way we don't have to constantly add and delete commands.
I think I mainly took it from https://discordjs.guide/creating-your-bot/command-deployment.html#command-registration how we could register commands, but there it was less of a Problem because they used JavaScript which Node can run by itself. I might Look into some Open Source Bots on how they implemented it.
Also interesting to see that there is daily limits to registering commands. It is also strange that they are displaying a manual process that can be used to deploy commands to the local guild or all guilds. I would imagine the bot itself is what deploys the commands, but they make it seem like the bot owner has to manually run node deploy-commands.js
even when the bot is used by thousands of devices.
Just found https://togithub.com/discordjs/discord.js/issues/10458, which might be related.
Just copying it here from Discord, maybe in more detail...
Describe the new feature
Improve the workflow for updating slash commands.
Planning
There are a few options we decided on.
index.ts
and have it run at every bot start./commands update
,/commands delete <ID>
. The first one to update each command and the second one for the case that we might remove a command, but that would still need to be looked into and discussed.