fjodor-rybakov / discord-nestjs

👾 NestJS package for discord.js
MIT License
271 stars 49 forks source link

DiscordAPIError: Bots cannot use this endpoint #766

Closed TheFlash787 closed 2 years ago

TheFlash787 commented 2 years ago

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.

fjodor-rybakov commented 2 years ago

Hi! I cant reproduce your issue. What version discord.js do you have installed?(Check in node_modules folder)

TheFlash787 commented 2 years ago

Hi! I cant reproduce your issue. What version discord.js do you have installed?(Check in node_modules folder)

Hey! In ./node_modules/discord.js, the version is 13.7.0. 🙂

TheFlash787 commented 2 years ago

My URLCommand file looks like this:

import { Command } from '@discord-nestjs/core';
import { URLCreateCommand } from './subcommand/create/create.command';
import { URLDeleteCommand } from './subcommand/delete/delete.command';
import { URLGetCommand } from './subcommand/get/get.command';

@Command({
    name: 'url',
    description: 'Manage all shortened URLs with this command',
    include: [URLCreateCommand, URLDeleteCommand, URLGetCommand],
    defaultPermission: false
})
export class URLCommand {}
fjodor-rybakov commented 2 years ago

My URLCommand file looks like this:

13.8.0 latest

fjodor-rybakov commented 2 years ago

Update to latest, please

DezziCool commented 2 years ago

@TheFlash787 hi your mistake is due to the fact that "slashCommandsPermissions" is no longer used. Starting from mid-April, the rights to use the team are now set only by guild administrators. link: https://discordjs.guide/interactions/slash-commands.html#slash-command-permissions

TheFlash787 commented 2 years ago

@TheFlash787 hi your mistake is due to the fact that "slashCommandsPermissions" is no longer used. Starting from mid-April, the rights to use the team are now set only by guild administrators. link: https://discordjs.guide/interactions/slash-commands.html#slash-command-permissions

Unfortunately I'm not too sure what you mean here. slashCommandsPermissions is a Discord NestJS implementation, not DiscordJS.

Update to latest, please

Huge apologies for the delay! I have updated to DiscordJS 13.8, and also made sure my Discord NestJS versions were up to date however I'm still experiencing this issue.

I have replicated this using your command sample. It looks like, simply adding slashCommandsPermissions with the PlayCommand causes it to occur and print out 'Bots cannot use this endpoint' -- even if I leave permissions empty after specifying the command class type.

If you do the same, do you run into this issue? @fjodor-rybakov

TheFlash787 commented 2 years ago

The issue must be caused here, surely, as it hasn't been updated to match the new Discord integration permission system they released a month or so ago: https://github.com/fjodor-rybakov/discord-nestjs/blob/8e5faf5d11cdf795f229d0c103afbbcc216b15f7/packages/core/src/services/register-command.service.ts#L228

DiscordJS: image

fjodor-rybakov commented 2 years ago

The issue must be caused here, surely, as it hasn't been updated to match the new Discord integration permission system they released a month or so ago:

https://github.com/fjodor-rybakov/discord-nestjs/blob/8e5faf5d11cdf795f229d0c103afbbcc216b15f7/packages/core/src/services/register-command.service.ts#L228

DiscordJS: image

Can you make pull request?

TheFlash787 commented 2 years ago

The issue must be caused here, surely, as it hasn't been updated to match the new Discord integration permission system they released a month or so ago: https://github.com/fjodor-rybakov/discord-nestjs/blob/8e5faf5d11cdf795f229d0c103afbbcc216b15f7/packages/core/src/services/register-command.service.ts#L228

DiscordJS: image

Can you make pull request?

Unfortunately I'm not too confident that I can commit time to this, but if I can, I will for sure take a look. Nonetheless, if you have anything down the line you would like my help testing, please don't hesitate to let me know.

TheFlash787 commented 2 years ago

@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?

TheFlash787 commented 2 years ago

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 commented 2 years ago

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: discordjs/discord.js#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.

Hi! Can you check your issue in the new version?

TheFlash787 commented 2 years ago

I will migrate to v14 and let you know 🙂

TheFlash787 commented 2 years ago

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: discordjs/discord.js#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.

Hi! Can you check your issue in the new version?

@fjodor-rybakov After updating, it looks like this still occurs -- but with a different error. Do you know why this might be? It continues only to occur when slashCommandPermissions is populated.

slashCommandsPermissions: [
    {
        commandClassType: MyCommand,
        permissions: [
            {
                id: '000-my-role-id',
                type: ApplicationCommandPermissionType.Role,
                permission: true
            }
        ]
    }
]

image

fjodor-rybakov commented 2 years ago

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: discordjs/discord.js#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.

Hi! Can you check your issue in the new version?

@fjodor-rybakov After updating, it looks like this still occurs -- but with a different error. Do you know why this might be? It continues only to occur when slashCommandPermissions is populated.

slashCommandsPermissions: [
    {
        commandClassType: MyCommand,
        permissions: [
            {
                id: '000-my-role-id',
                type: ApplicationCommandPermissionType.Role,
                permission: true
            }
        ]
    }
]

image

Since you can no longer set permissions through the bot, I removed the misleading functionality