This content is in progress and is expected to continue to evolve.

Discord Slash Commands

It is common for the discord bot libraries to expect having an active bot hosted on a server, also known as a gateway bot. One of the valuable things about slash commands is that it doesn't require that gateway bot connection and persistence. It can use the alternative approach of providing an API endpoint that the command can hit.

  1. You need to create a bot for some of the permissions.[^1] Let's assume we will use those permissions and create on. Click the Bot option on the sidebar and create a bot. It seems easier to just use a bot in my case since I will want to hit those APIs eventually.
  2. You also need to authorize the bot to set commands. Go to bot and OAuth2, generate a url and visit it. Choose to bot and applications.commands checkboxes, and it should produce a url for you to visit.
  3. We need to set our function to verify the signature is coming from discord. They have a library that can help with this. Note, if you don't do this, they will remove your command. (
  4. We need to reply with a ping/pong {type: 1} so discord knows that it is active. If it fails security or is not active, then the command will be removed.
  5. We need to host the endpoint somewhere so it is able to respond with the "pong". I did it through Netlify in my specific case. For testing purposes, I used netlify dev --live to start a server and test out the bot.
  6. The bot needs the endpoint url in the developer portal. We can use the test one for now, and swap it out later. It can also be removed for it to switch back to the "gateway API" version of the bot.
  7. We need to post the JSON so discord can offer up the /command options within the client.
  8. The command should be active!

[^1]: In many cases, you may still need a bot user. If you need to receive gateway events, or need to interact with other parts of our API (like fetching a guild, or a channel, or updating permissions on a user), those actions are all still tied to having a bot token. However, if you don't need any of those things, you never have to add a bot user to your application at all.