Skip to content

Typescript type for Emoji.id is wrong, or there's a bug somewhere else #9948

@jeremy-rifkin

Description

@jeremy-rifkin

Which package is this bug report for?

discord.js

Issue description

I have had a very difficult time reproducing this bug.

Background: I have observed buggy behavior in a starboard component in my bot. Messages can get stuck in a state where the the bot doesn't put them on the starboard despite setting the right reaction counts. Rebooting the bot allows the messages to get onto the starboard.

In order to reproduce I have to leave my bot running for hours while people react to messages.

Through triage I have found that the error is I'm relying on a check reaction.emoji.id === null, but somehow reaction.emoji.id is undefined instead of null.

What I observe when printing Discord.MessageReaction objects to the console is the following:
Sometime for a ⭐ reaction the emoji looks like the following

  _emoji: ReactionEmoji {
    animated: null,
    name: '⭐',
    id: null,
    reaction: [Circular *2]
  },

Other times I see the following:

  _emoji: ReactionEmoji {
    animated: false,
    name: '⭐',
    id: undefined,
    reaction: [Circular *2]
  },

This is the _emoji field of Discord.MessageReaction, but based on https://github.com/discordjs/discord.js/blob/dbb92e5bc416d4fc3cbe7197baa941a1583d95b5/packages/discord.js/src/structures/MessageReaction.js#L81C1-L93C4 it should match.

Code sample

// The code looks something like this
    meets_threshold(reaction: Discord.MessageReaction) {
        assert(reaction.emoji.name);
        if (!(reaction.emoji instanceof Discord.GuildEmoji || reaction.emoji.id === null)) {
            return false;
        }
        // ...

Versions

  • discord.js 14.13.0
  • node v18.18.0
  • typescript 4.9.3
  • Ubuntu 20.04

Note: I have had issues with odd behavior with message reactions going back to 14.8. At that point the reaction counts were buggy.

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

User, Channel, Message, Reaction

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildModeration, GuildEmojisAndStickers, GuildIntegrations, GuildWebhooks, GuildInvites, GuildVoiceStates, GuildMessages, GuildMessageReactions, GuildMessageTyping, DirectMessages, DirectMessageReactions, DirectMessageTyping, MessageContent

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions