Meowhal / osu-ahr

irc bot for osu multi lobby auto host rotation
MIT License
129 stars 37 forks source link

After the discord bot connects, disconnects with DiscordAPIError: Bots cannot use this endpoint #62

Closed xayanide closed 2 years ago

xayanide commented 2 years ago

Fixed by #81

Describe the bug Discord bot logins then abruptly disconnects after a few seconds.

I think something is going on around here, trace it from there I guess. Or there was a change in Discord that made this occur. It seems like Discord just rolled out some changes.

More info: https://discord.com/blog/slash-commands-permissions-discord-apps-bots https://github.com/discord/discord-api-docs/pull/4830 https://github.com/oceanroleplay/discord.ts/issues/661

https://github.com/Meowhal/osu-ahr/blob/04fc1fb65dc71e8b0228096305b8301b5c6eb295/src/discord/DiscordBot.ts#L51-L53

https://github.com/Meowhal/osu-ahr/blob/04fc1fb65dc71e8b0228096305b8301b5c6eb295/src/discord/DiscordBot.ts#L119

dist https://github.com/Meowhal/osu-ahr/blob/04fc1fb65dc71e8b0228096305b8301b5c6eb295/dist/discord/DiscordBot.js#L36-L38

https://github.com/Meowhal/osu-ahr/blob/04fc1fb65dc71e8b0228096305b8301b5c6eb295/dist/discord/DiscordBot.js#L100

Tried with all 3 intents in the Developer portal.

Prior to this issue, I did not encounter a problem even with all these 3 intents disabled.

Affected version 1.5.17

Steps to reproduce If haven't compiled yet run.

npm run clean
npm run build
  1. Run osu-ahr discord cli from compiled dist
    node dist/discord/index.js

Expected behavior Cleanly continue operating.

Actual behavior Logins then disconnects after a few seconds.

Event type: unhandledRejection

PS C:\Users\Ava\Documents\GitHub\osu-ahr> node dist/discord/index.js
starting up...
[02:35:22.117][INFO] discord - discord bot is ready.
[02:35:22.124][INFO] discord - invite link => https://discord.com/api/oauth2/authorize?client_id=869623432512413795&scope=bot+applications.commands&permissions=268443664
C:\Users\Ava\Documents\GitHub\osu-ahr\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\Ava\Documents\GitHub\osu-ahr\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\Ava\Documents\GitHub\osu-ahr\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async ApplicationCommandPermissionsManager.set (C:\Users\Ava\Documents\GitHub\osu-ahr\node_modules\discord.js\src\managers\ApplicationCommandPermissionsManager.js:168:20) {
  method: 'put',
  path: '/applications/869623432512413795/guilds/785457308054061085/commands/917607543033970809/permissions',
  code: 20001,
  httpStatus: 403,
  requestData: {
    json: {
      permissions: [ { id: '917607544921395211', permission: true, type: 1 } ]
    },
    files: []
  }
}

Node.js v17.9.0
PS C:\Users\Ava\Documents\GitHub\osu-ahr> 
Meowhal commented 2 years ago

The permissions V2 seem to be the cause of the error.

Similar problems have been reported here. 403 Error when setting application command permissions on Discord

And there seems to be an issue that bot owners who do not have 2-step pediatrics cannot create roles. Permissions Calculator

I intend to review the system around roles.

Meowhal commented 2 years ago

The problem should be solved, but If the old #maches channel is still there, we will need to delete it once. In addition, it is now necessary to manually authorize the command if it is used by someone other than the owner.