TrojanerHD / TrojanerBot

My discord bot
MIT License
4 stars 2 forks source link

Slash command permissions throw error #52

Closed TrojanerHD closed 2 years ago

TrojanerHD commented 2 years ago

Discord changed in an update that bot tokens can't change command permissions so now the following steps are required to automatically set permissions:

  1. Make a local redirect server (e. g. using express)
    • Validate redirect server by adding http://localhost:<PORT> to https://discord.com/developers/applications/<CLIENT_ID>/oauth2/general
  2. Let a server admin / owner authenticate via https://discord.com/oauth2/authorize?client_id=<CLIENT_ID>&scope=applications.commands.permissions.update&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A<PORT>
  3. Store Bearer token of authentication
  4. Make PUT request to Discord endpoint /applications/<APPLICATION_ID>/guilds/<GUILD_ID>/commands/<COMMAND_ID>/permissions for each command with payload permissions: {id: string, type: 1 | 2 | 3, permission: boolean}[] (See https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions for more information, specifically https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-structure for permission array)
    • <APPLICATION_ID> can be globally received via DiscordClient._client.application?.id