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(MessageReaction): Address undefined burst properties #10597

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Jiralite
Copy link
Member

Please describe the changes this PR makes and why it should be merged:

When receiving a non-burst reaction over the gateway, we get this (example) payload:

{
  user_id: '618976181026422814',
  type: 0,
  message_id: '1307361477182754877',
  message_author_id: '618976181026422814',
  member: {
    user: {
      username: 'jiralite',
      public_flags: 4210944,
      id: '618976181026422814',
      global_name: 'Jiralite',
      display_name: 'Jiralite',
      discriminator: '0',
      clan: null,
      bot: false,
      avatar_decoration_data: null,
      avatar: '096240dfad1c926c33f0a92b111aaaeb'
    },
    roles: [],
    premium_since: null,
    pending: false,
    nick: null,
    mute: false,
    joined_at: '2024-06-08T17:57:51.599000+00:00',
    flags: 0,
    deaf: false,
    communication_disabled_until: null,
    banner: null,
    avatar: null
  },
  emoji: { name: 'SkyLook', id: '649013670625542155' },
  channel_id: '1089254519268974712',
  burst: false,
  guild_id: '1089217648996401242'
}

This data is shoved into the cache here:

const reaction = message.reactions._add({
emoji: data.emoji,
count: message.partial ? null : 0,
me: user.id === this.client.user.id,
burst_colors: data.burst_colors,
});

burst_colors is not here, but we make sure the property exists. This means here, it's set to undefined:

if ('burst_colors' in data) {
/**
* Hexadecimal colors used for this super reaction
* @type {?string[]}
*/
this.burstColors = data.burst_colors;
}

me_burst is also not here, which means this is undefined too:

Interestingly, there does not seem to be a way for bots to burst react, so doing Boolean(data.me_burst) should be enough. For burst_colors... since that is always present, I've added an array check. If it's not an array, then it's likely missing and should be left alone.

Tested also with no partials and [Partials.Channel, Partials.GuildMember, Partials.GuildScheduledEvent, Partials.Message, Partials.Reaction, Partials.ThreadMember, Partials.User].

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 Nov 16, 2024

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

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Nov 16, 2024 4:20pm
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Nov 16, 2024 4:20pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants