discordjs / discord.js

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

Cannot read properties of undefined (reading 'reduce') #10377

Closed xcjs closed 3 months ago

xcjs commented 3 months ago

Which package is this bug report for?

discord.js

Issue description

  1. Provide a bot with buttons.
  2. Click one of the buttons.

Code sample

const self = this;

this.#client.on(Events.InteractionCreate, async (interaction) => await this.#onInteraction.call(self, interaction));

async #onInteraction(interaction: ButtonInteraction): Promise<void> {

}

Versions

"discord.js": "^14.14.1"

Issue priority

Low (slightly annoying)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

MessageContent

I have tested this issue on a development release

No response

xcjs commented 3 months ago

Stacktrace here:

Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'reduce')
    at BaseInteraction (node_modules\discord.js\src\structures\BaseInteraction.js:106:43)
    at MessageComponentInteraction (node_modules\discord.js\src\structures\MessageComponentInteraction.js:17:5)
    at ButtonInteraction (node_modules\discord.js\src\structures\ButtonInteraction.js:9:1)
    at handle (node_modules\discord.js\src\client\actions\InteractionCreate.js:90:25)
    at module.exports (node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at handlePacket (node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
    at <anonymous> (node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
    at emit (node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
    at <anonymous> (node_modules\@discordjs\ws\dist\index.js:1190:51)
    at emit (node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
    at onMessage (node_modules\@discordjs\ws\dist\index.js:1005:14)
    at processTicksAndRejections (internal/process/task_queues:95:5)

This appeared to work fine over the last week.

santiherzfeld commented 3 months ago

Got same issue in all my bots suddenly

J4Wx commented 3 months ago

Yeah - seemingly for any interaction type too, not just for buttons. I suspect this is a Discord API issue or change?

TypeError: Cannot read properties of undefined (reading 'reduce')
application-1  |     at new BaseInteraction (node_modules/discord.js/src/structures/BaseInteraction.js:106:43)
application-1  |     at new CommandInteraction (node_modules/discord.js/src/structures/CommandInteraction.js:16:5)
application-1  |     at new ChatInputCommandInteraction (node_modules/discord.js/src/structures/ChatInputCommandInteraction.js:13:5)
application-1  |     at InteractionCreateAction.handle (node_modules/discord.js/src/client/actions/InteractionCreate.js:90:25)
application-1  |     at module.exports [as INTERACTION_CREATE] (node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
application-1  |     at WebSocketManager.handlePacket (node_modules/discord.js/src/client/websocket/WebSocketManager.js:355:31)
application-1  |     at WebSocketManager.<anonymous> (node_modules/discord.js/src/client/websocket/WebSocketManager.js:239:12)
application-1  |     at WebSocketManager.emit (node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:282:31)
application-1  |     at WebSocketShard.<anonymous> (node_modules/@discordjs/ws/dist/index.js:1190:51)
application-1  |     at WebSocketShard.emit (node_modules/@vladfrangu/async_event_emitter/dist/index.cjs:282:31)
falcao-g commented 3 months ago

My bot that was running fine for 21 days has shown this also, it seems to be in all types of interactions

xcjs commented 3 months ago

@J4Wx I'm suspecting this is some kind of infrastructure issue. I noticed a few other large service web sites acting odd recently, which makes me assume some cloud provider is having issues.

J4Wx commented 3 months ago

Yeah - this bot has been running (unmodified) for months without issue. I don't believe that this is a Discord JS issue.

TAEMBO commented 3 months ago

This is a known issue due to unexpected API behavior changes. The current workaround for now is to downgrade to discord.js v14.14.1.

zastlx commented 3 months ago

same issue

xcjs commented 3 months ago

@TAEMBO I'm seeing a completely different issue now - unknown interactions. My interactions are keyed to an enum, so that shouldn't be a problem.

falcao-g commented 3 months ago

downgrading, (in my case, upgrading), fixed the issue for me in my bot, the funny thing is that both my bots were in ˆ14.9.0 version of discord.js and only one of them was affected, the bigger one

xcjs commented 3 months ago

@falcao-g What version did you upgrade to?

falcao-g commented 3 months ago

14.14.1

xLittleJ commented 3 months ago

So, to fix it, change this.entitlements = data.entitlements.reduce to this.entitlements = data.entitlements?.reduce

Jaynarol commented 3 months ago

14.15.3

same issue just happened today after stable for a long time and did not touch anything.

CrusherNotDrip commented 3 months ago

Same thing happened to me just downgraded to 14.15.1 for now (works for me)

pfgtater commented 3 months ago

14.15.3

Downgraded to 14.14.1 and issue fixed. No idea what caused it

falcao-g commented 3 months ago

this is an issue caused by Discord, from what i have seem, they are already aware of it, for us, we have two options, either changing the line of code to something like this: this.entitlements = (data.entitlements ?? []).reduce or changing the discord.js version to 14.14.1

pfgtater commented 3 months ago

That makes sense. Easiest solution is downgrading to 14.14.1

SENPAY98K commented 3 months ago

Same problem for latest version as well v14.15.3

TundraShark commented 3 months ago

This is a known issue due to unexpected API behavior changes. The current solution for now is to downgrade to discord.js v14.14.1.

Thank you so much, I thought I was going absolutely crazy since my code has not changed at all and suddenly everything just broke. After banging my head against the wall for two hours and seeing your post, setting the version to 14.14.1 fixed it for me.

Romijoxx commented 3 months ago

Downgrading to 14.14.1 did not solve this issue for me. Which version are you using for discord-api-types, @discordjs/builders, @discordjs/rest?

(Manually changing the code to this.entitlements = (data.entitlements ?? []).reduce worked)

ImmaUgc commented 3 months ago

Same issue!

Issuko-Adam commented 3 months ago

this is an issue caused by Discord, from what i have seem, they are already aware of it, for us, we have two options, either changing the line of code to something like this: this.entitlements = (data.entitlements ?? []).reduce or changing the discord.js version to 14.14.1

saved my life

TheFalloutOf76 commented 3 months ago

downgrading to 14.14.1 worked for me 👍

Rollphes commented 3 months ago

A similar error occurred in 14.14.1. Perhaps it is not a continuous occurrence, but rather a rare case of data.entitlements being undefined.

hamidmirza1 commented 3 months ago

any ideas on when it will be fixed?

DJj123dj commented 3 months ago

I have the same issue on v14.15.3

Jiralite commented 3 months ago

This was a Discord issue that is now resolved.