discordx-ts / discordx

🤖 Create a discord bot with TypeScript and Decorators!

Home Page:https://discordx.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: DiscordAPIError: Bots cannot use this endpoint

OmgImAlexis opened this issue · comments

What happened?

My guild was moved to v2 of the permissions system and now it's failing to start.

Reproduction

From the demo repo.

// init permissions; enabled log to see changes
await client.initApplicationPermissions(true);

Package

discordx

Version

Stable

Relevant log output

Charlotte >> command: kick >> permissions >> updating >> guild: #The lobby
C:\Users\xo\code\OmgImAlexis\charlotte\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 (C:\Users\xo\code\OmgImAlexis\charlotte\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\xo\code\OmgImAlexis\charlotte\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async ApplicationCommandPermissionsManager.set (C:\Users\xo\code\OmgImAlexis\charlotte\node_modules\discord.js\src\managers\ApplicationCommandPermissionsManager.js:168:20)
    at async file:///C:/Users/xo/code/OmgImAlexis/charlotte/node_modules/discordx/src/Client.ts:833:15
    at async Promise.all (index 12)
    at async Client.initGuildApplicationPermissions (file:///C:/Users/xo/code/OmgImAlexis/charlotte/node_modules/discordx/src/Client.ts:816:5)
    at async Promise.all (index 0)
    at async Client.initApplicationPermissions (file:///C:/Users/xo/code/OmgImAlexis/charlotte/node_modules/discordx/src/Client.ts:776:5)
    at async Client.<anonymous> (file:///C:/Users/xo/code/OmgImAlexis/charlotte/src/client.ts:37:5) {
  method: 'put',
  path: '/applications/962572053003796551/guilds/927461441051701280/commands/968148318783942756/permissions',
  code: 20001,
  httpStatus: 403,
  requestData: { json: { permissions: [] }, files: [] }
}

Code of Conduct

  • I agree to follow this project's Code of Conduct

disable permission usage, discord has decommissioned that API for permissions v2, see discord/discord-api-docs#4830

Can confirm removing await client.initApplicationPermissions(true); fixes the issue.

Would guild specific commands be effected? As in does the Permission decorator need to be reworked?

Can confirm removing await client.initApplicationPermissions(true); fixes the issue.

Would guild specific commands be effected? As in does the Permission decorator need to be reworked?

we will wait for discord.js update

Can confirm removing await client.initApplicationPermissions(true); fixes the issue.

Would guild specific commands be effected? As in does the Permission decorator need to be reworked?

Yes. From what I've seen, the new way is simply for us to report to discord what the default permissions are in the form of a bit mask.
This change has been made in the discord api types package.

However, discord dropped change out of nowhere and without 1 day warning removed the API for permission and every seems to be pretty mad about it.

The new way (eventually) would thag there will be one permission decorator that takes a string of "default permissions", this effectually changes the current decorator that takes the boolean and removes the resolver decorator.

Effectively making a lot more simple for us. But discord haven't even made the documentation for the API public yet...

Update:

the docs have been merged, and the API still exists, however, the reason why you where getting this error is because there is a NEW authentication needed to call the Permission set api: https://discord.com/developers/docs/interactions/application-commands#permissions

Command permissions can only be updated using a Bearer token. Authenticating with a bot token will result in an error.

As we can see, the API is still the same https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions but now requires a Bearer token with the applications.commands.permissions.update

HOWEVER, there IS a new field called default_member_permissions https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-using-default-permissions

Adding default permissions doesn't require any Bearer token since it's configured during command creation and isn't targeting specific roles, users, or channels.

This is likely replacing the permission decorator we have with the boolean as it says:

Added default_member_permissions field, which is a bitwise OR-ed set of permissions, expressed as a string. This replaces the default_permission field, which will soon be deprecated.

https://discord.com/developers/docs/change-log#updated-command-permissions

with v9.6.0, this feature is temporary disabled in discordx. We will update accordingly discord.js.