GeorgeCiesinski / poke-guesser-bot

Discord bot that lets you guess pokemon
MIT License
0 stars 3 forks source link

Different ways to setup commands #116

Open Wissididom opened 1 year ago

Wissididom commented 1 year ago

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.

GeorgeCiesinski commented 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.

Wissididom commented 1 year ago

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:

name value configtype
VERSION 1.0.0 STRING
GeorgeCiesinski commented 1 year ago

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.

Wissididom commented 1 year ago

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.

GeorgeCiesinski commented 1 year ago

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.

Wissididom commented 2 months ago

Just found https://togithub.com/discordjs/discord.js/issues/10458, which might be related.