Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(actions): Handle missing poll object #10266

Merged
merged 2 commits into from May 11, 2024

Conversation

Jiralite
Copy link
Member

Please describe the changes this PR makes and why it should be merged:
poll will be missing if GUILD_MESSAGE_POLLS is enabled but MESSAGE_CONTENT is not, or if a message containing a poll was uncached but the appropriate partials were enabled. This caused a crash:

/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/packages/discord.js/src/client/actions/MessagePollVoteRemove.js:16
    const answer = poll.answers.get(data.answer_id);
                        ^

TypeError: Cannot read properties of null (reading 'answers')
    at MessagePollVoteRemoveAction.handle (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/packages/discord.js/src/client/actions/MessagePollVoteRemove.js:16:25)
    at module.exports [as MESSAGE_POLL_VOTE_REMOVE] (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/packages/discord.js/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js:4:40)
    at WebSocketManager.handlePacket (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/packages/discord.js/src/client/websocket/WebSocketManager.js:355:31)
    at WebSocketManager.<anonymous> (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/packages/discord.js/src/client/websocket/WebSocketManager.js:239:12)
    at WebSocketManager.emit (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/node_modules/.pnpm/@vladfrangu+async_event_emitter@2.2.4/node_modules/@vladfrangu/async_event_emitter/src/index.ts:360:28)
    at WebSocketShard.<anonymous> (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/packages/ws/src/strategies/sharding/SimpleShardingStrategy.ts:32:47)
    at WebSocketShard.emit (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/node_modules/.pnpm/@vladfrangu+async_event_emitter@2.2.4/node_modules/@vladfrangu/async_event_emitter/src/index.ts:360:28)
    at WebSocketShard.onMessage (/Users/jiralite/Documents/code/GitHub/discordjs/discord.js/packages/ws/src/ws/WebSocketShard.ts:640:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The optional chaining operator will be enough to cause an exit on the next line with no error.
Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Copy link

vercel bot commented May 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
discord-js ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 11, 2024 8:44am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview May 11, 2024 8:44am

@Jiralite Jiralite added this to the discord.js 14.15.3 milestone May 10, 2024
@kodiakhq kodiakhq bot merged commit 7816ec2 into main May 11, 2024
7 checks passed
@kodiakhq kodiakhq bot deleted the fix/poll-voters-answers-optional branch May 11, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants