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') #10378

Closed ShadowMask17 closed 3 months ago

ShadowMask17 commented 3 months ago

Which package is this bug report for?

discord.js

Issue description

As i updated the package to v14.15.3, i started to get the error of: TypeError: Cannot read properties of undefined (reading 'reduce')

i had no idea why until i took attention on where, which was the entitlements part, line 103 of BaseInteraction.js, i made a change to the internal code adding an error handler and it worked after that, i don't know if I'm the only one that had this issue.

Full error log: TypeError: Cannot read properties of undefined (reading 'reduce') at new BaseInteraction (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\discord.js\src\structures\BaseInteraction.js:114:45) at new CommandInteraction (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\discord.js\src\structures\CommandInteraction.js:16:5) at new ChatInputCommandInteraction (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\discord.js\src\structures\ChatInputCommandInteraction.js:13:5) at InteractionCreateAction.handle (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\discord.js\src\client\actions\InteractionCreate.js:90:25) at module.exports [as INTERACTION_CREATE] (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36) at WebSocketManager.handlePacket (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31) at WebSocketManager. (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12) at WebSocketManager.emit (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:285:31) at WebSocketShard. (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\@discordjs\ws\dist\index.js:1190:51) at WebSocketShard.emit (C:\Users\bendi\OneDrive\Desktop\Testing\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:285:31)

Code sample

//This is the original code in the BaseInteraction.js file that caused me the error
/**
     * The entitlements for the invoking user, representing access to premium SKUs
     * @type {Collection<Snowflake, Entitlement>}
     */
    this.entitlements = data.entitlements.reduce(
      (coll, entitlement) => coll.set(entitlement.id, this.client.application.entitlements._add(entitlement)),
      new Collection(),
    );

//This is the modifications i made to make my bot finall work without the "TypeError: Cannot read properties of undefined (reading 'reduce')" error

/**
     * The entitlements for the invoking user, representing access to premium SKUs
     * @type {Collection<Snowflake, Entitlement>}
     */
    this.entitlements = new Collection();
    if (data.entitlements) {
      this.entitlements = data.entitlements.reduce(
        (coll, entitlement) => coll.set(entitlement.id, this.client.application.entitlements._add(entitlement)),
        this.entitlements,
      );
    }

Versions

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

mods-hd commented 3 months ago

This could help you: https://github.com/discordjs/discord.js/issues/10377#issuecomment-2204782096

didinele commented 3 months ago

Duplicate of #10377