discordjs / discord.js

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

Typings for creating select values with emoji incorrect, blocking creation of dropdown menus with emoji #6555

Closed Nephrited closed 3 years ago

Nephrited commented 3 years ago

Please describe the problem you are having in as much detail as possible: When attempting to create a select dropdown with an emoji, the TS enforces a full emoji object of type EmojiIdentifierResolvable, when the Discord API requires only a partial Emoji object consisiting of at most the id, name and animated fields.

Include a reproducible code sample here, if possible:

const actionRow = new MessageActionRow().addComponents(
    new MessageSelectMenu()
        .setCustomId('exampleSelect')
        .setPlaceholder('Nothing selected')
        .addOptions([
            {
                label: 'Label',
                description: 'A description',
                value: 'value-1',
                emoji: {
                    name: "♥",
                    //id: "1234", // optional field for custom emoji
                    //animated: false, // optional field for custom emoji
                }
            },
        ])
);

await interaction.reply({
    content: 'This is a test',
    components: [actionRow],
});

Further details:

Workaround

emoji: {
    name: "♥",
} as any

Relevant client options:

N/A

Jiralite commented 3 years ago

Odd? This method accepts this type definition for which the emoji property is ultimately this:

export type EmojiIdentifierResolvable = string | EmojiResolvable;
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;

I fail to see how this could even occur. It looks like you're passing a RawEmoji instead, which isn't documented nor typed to be sent across?

Nephrited commented 3 years ago

RawEmoji looks to be exactly what the DiscordAPI accepts for this call, as documented here on the Discord API, and it does work if forced through.

With that said, an EmojiResolvable looks to be the right way to handle this via the library, so perhaps a non-issue after all. I'll update my code to use it.

Jiralite commented 3 years ago

This is a library, so things can be altered! If you have a custom emoji, just pass the id. If you want to use a default emoji, just pass the Unicode variant. Under-the-hood, this is transformed to the necessary payload (RawEmoji) to be sent across. Simply specifying an id or the Unicode variant is a convenience here.

TS enforces a full emoji object of type EmojiIdentifierResolvable

This can be a string or an id, so it's not always an object!

Nephrited commented 3 years ago

Makes total sense to me. I'll close this out, hopefully anyone with a similar problem will run into it!

monbrey commented 3 years ago

Arguably this is just a typings issue then, and RawEmoji could be added to resolvable items.