Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiscordAPIError: Bots cannot use this endpoint #766

Closed
TheFlash787 opened this issue Jun 16, 2022 · 16 comments · Fixed by #810
Closed

DiscordAPIError: Bots cannot use this endpoint #766

TheFlash787 opened this issue Jun 16, 2022 · 16 comments · Fixed by #810
Labels
help wanted Extra attention is needed

Comments

@TheFlash787
Copy link

TheFlash787 commented Jun 16, 2022

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
Copy link
Owner

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

@TheFlash787
Copy link
Author

TheFlash787 commented Jun 17, 2022

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
Copy link
Author

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
Copy link
Owner

My URLCommand file looks like this:

13.8.0 latest

@fjodor-rybakov
Copy link
Owner

Update to latest, please

@DezziCool
Copy link

@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
Copy link
Author

TheFlash787 commented Jun 22, 2022

@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
Copy link
Author

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:

DiscordJS:
image

@fjodor-rybakov
Copy link
Owner

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:

DiscordJS: image

Can you make pull request?

@TheFlash787
Copy link
Author

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:

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
Copy link
Author

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

@fjodor-rybakov fjodor-rybakov added bug Something isn't working help wanted Extra attention is needed labels Jun 24, 2022
@TheFlash787
Copy link
Author

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.

@fjodor-rybakov
Copy link
Owner

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
Copy link
Author

I will migrate to v14 and let you know 🙂

@TheFlash787
Copy link
Author

TheFlash787 commented Jul 19, 2022

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 fjodor-rybakov linked a pull request Jul 20, 2022 that will close this issue
@fjodor-rybakov fjodor-rybakov removed the bug Something isn't working label Jul 20, 2022
@fjodor-rybakov
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants