dotnize / Dodong

An easy-to-setup music bot made with discord.js and discord-player
MIT License
60 stars 15 forks source link

Player crashes when issued ping #37

Closed bitterpeanut closed 2 years ago

bitterpeanut commented 2 years ago

Player crashes when issued ping.

Updated config.json with botToken and clientId.

❯ npm start

> dodong@1.0.0 start
> node index.js

25 commands loaded.
Global slash commands registered successfully.
3 client events loaded.
7 player events loaded.
No Genius API token provided. Lyrics feature might not work properly.
--------- Dodong is ready! ---------
node:events:491
      throw er; // Unhandled 'error' event
      ^

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: VIEW_CHANNEL.
    at Function.resolve (./node_modules/discord.js/src/util/BitField.js:168:11)
    at ./node_modules/discord.js/src/util/BitField.js:163:54
    at Array.map (<anonymous>)
    at Function.resolve (./node_modules/discord.js/src/util/BitField.js:163:40)
    at PermissionsBitField.has (./node_modules/discord.js/src/util/BitField.js:60:28)
    at PermissionsBitField.has (./node_modules/discord.js/src/util/PermissionsBitField.js:92:82)
    at ./events/interactionCreate.js:9:70
    at Bot.emit (node:events:513:28)
    at InteractionCreateAction.handle (./node_modules/discord.js/src/client/actions/InteractionCreate.js:81:12)
    at Object.module.exports [as INTERACTION_CREATE] (./node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
Emitted 'error' event on Bot instance at:
    at emitUnhandledRejectionOrErr (node:events:394:10)
    at processTicksAndRejections (node:internal/process/task_queues:85:21) {
  code: 'BitFieldInvalid'
}

During the evaluation of the has clause at ./events/interactionCreate.js:9:70:

if(!interaction.guild.members.me.permissionsIn(interaction.channel).has(client.requiredTextPermissions)) return;

The list is fed into the BitField resolver inside. That doesn't know anything about the requiredVoicePermissions and requiredTextPermissions. (Maybe this was a change in discordjs, I'm new to it, but it looks like the BitField resolver uses this file: (node_modules/@discordjs/voice/node_modules/discord-api-types/payloads/common.d.ts)

...
export declare const PermissionFlagsBits: {
    readonly CreateInstantInvite: bigint;
    readonly KickMembers: bigint;
    readonly BanMembers: bigint;
    readonly Administrator: bigint;
    readonly ManageChannels: bigint;
    readonly ManageGuild: bigint;
    readonly AddReactions: bigint;
    readonly ViewAuditLog: bigint;
    readonly PrioritySpeaker: bigint;
    readonly Stream: bigint;
    readonly ViewChannel: bigint;
...

This uses a CamelCase to resolve the bits rather than the _VIEWCHANNEL. I made the changes in my own fork to test and everything else works as expected. Do I have some dependencies wrong?

❯ npm list
dodong@1.0.0 .
├── @discord-player/extractor@3.0.2
├── @discordjs/opus@0.8.0
├── @discordjs/rest@1.1.0
├── discord-player@5.3.1
├── discord.js@14.3.0
├── ffmpeg-static@5.0.2
├── node-bin-setup@1.1.0 extraneous
├── node@16.17.0
└── play-dl@1.9.5
dotnize commented 2 years ago

Do I have some dependencies wrong?

No, this is a breaking change that I overlooked while upgrading discord.js to v14.

Feel free to submit a PR with your fix!