discord-nestjs: DiscordAPIError: Bots cannot use this endpoint

Describe the bug I’ve updated my Discord NestJS to version (3.3.4) but unfortunately I’m still running into issues with registering Discord slash commands with permissions.

[Nest] 16152  - 16/06/2022, 21:34:10     LOG [NestApplication] Nest application successfully started +747ms
[Nest] 16152  - 16/06/2022, 21:34:31     LOG [RegisterCommandService] All guild commands removed!
[Nest] 16152  - 16/06/2022, 21:34:31     LOG [RegisterCommandService] All guild commands are registered!

...\node_modules\discord.js\src\rest\RequestHandler.js:350
      throw new DiscordAPIError(data, res.status, request);
            ^
DiscordAPIError: Bots cannot use this endpoint
    at RequestHandler.execute (...\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at RequestHandler.push (...\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at ApplicationCommandPermissionsManager.set (...\node_modules\discord.js\src\managers\ApplicationCommandPermissionsManager.js:168:20)

To Reproduce My configuration is as follows (I have removed all commands that were not required to produce the error, it looks like any command triggers it):

{
    token: appConfiguration.token,
    discordClientOptions: {
        intents: Object.keys(Intents.FLAGS).map(
            (i) => Intents.FLAGS[i] // temporary, while developing
        )
    },
    removeGlobalCommands: true,
    registerCommandOptions: [
        {
            forGuild: appConfiguration.guildId,
            removeCommandsBefore: true
        }
    ],
    slashCommandsPermissions: [
        {
            commandClassType: URLCommand,
            permissions: [
                {
                    id: permissionConfiguration.staffRole, // string id
                    type: ApplicationCommandPermissionTypes.ROLE,
                    permission: true // default false, in the @Command()
                }
            ]
        }
    ]
};
"dependencies": {
    "@discord-nestjs/common": "^3.3.4",
    "@discord-nestjs/core": "^3.3.4",
    "@nestjs/common": "^8.0.0",
    "@nestjs/config": "^1.2.0",
    "@nestjs/core": "^8.0.0",
    "@nestjs/event-emitter": "^1.1.0",
    "@nestjs/mapped-types": "*",
    "@nestjs/platform-express": "^8.0.0",
    "@nestjs/schedule": "^1.1.0",
    "@nestjs/typeorm": "^8.0.3",
    "@shockbyte/nest-common": "^0.0.5",
    "discord.js": "^13.*",
    "husky": "^7.0.4",
    "mysql2": "^2.3.3",
    "nestjs-dynamic-providers": "^0.1.2",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0",
    "typeorm": "^0.2.45"
}

Expected behavior Prior to the DiscordAPI command changes, this configuration worked as expected and commands were protected by the needed permissions.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Alright, so this will be fairly easy to accomplish once this is complete – we may just need to rework how the permissions are handled a little, but the tools should be there: https://github.com/discordjs/discord.js/pull/8162

We would basically need to change await command.permissions.set({ permissions }); to use the command.setDefaultXXX methods when this PR is accessible for us to use in DiscordJS v13.

@fjodor-rybakov Since this error is still occuring and easily replicatable with slashComandPermissions in use on the sample projects, is it possible we could re-open this issue so that we can track our resolution process?