discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.44k stars 3.97k forks source link

Error when bot reacts to messages with Channel partial enabled #10468

Closed cobaltt7 closed 2 months ago

cobaltt7 commented 2 months ago

Which package is this bug report for?

discord.js

Issue description

  1. Replace placeholder token & channel ID
  2. Run code sample
  3. Observe error in console. The message is sent and reacted to, but it appears that processing the reaction throws the error. Likely regressed from #9336 (cc @jaw0r3k)

Error:

.\node_modules\discord.js\src\structures\MessageReaction.js:164
      else this.countDetails.normal++;
                ^

TypeError: Cannot read properties of undefined (reading 'normal')
    at MessageReaction._add (.\node_modules\discord.js\src\structures\MessageReaction.js:164:17)
    at MessageReactionAdd.handle (.\node_modules\discord.js\src\client\actions\MessageReactionAdd.js:43:14)
    at Message.react (.\node_modules\discord.js\src\structures\Message.js:844:51)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ./test.js:11:1

Node.js v20.10.0

This does not happen without the Channel partial and the Guilds intent. Adding other intents or partials does not fix the error.

This also does not happen if a user other than the client user reacts to a message.

Marked as high priority as this is a regression that throws an error and should be fixed before release (which looks like it's soon)

Code sample

import { Client, GatewayIntentBits, Partials } from "discord.js";

const client = new Client({
    intents: GatewayIntentBits.Guilds,
    partials: [Partials.Channel],
});
await client.login("TOKEN");

const channel = await client.channels.fetch("CHANNEL_ID");
const message = await channel.send("test");
await message.react("👍"); // ERROR

Versions

Issue priority

High (immediate attention needed)

Which partials do you have configured?

Channel

Which gateway intents are you subscribing to?

Guilds

I have tested this issue on a development release

a5afc406b