Discord.js message.react fails when adding specific unicode emotes

和自甴很熟 提交于 2021-02-08 05:10:19

问题


Yesterday I started coding a bot using the guide from discord.js. The core is just with what you finish the Command Handler part with.
I was working on a voting command, where the bot would react with Unicode symbols like :one: :two: :three:.
This is where I encounter my problem. Using:

module.exports = {
name: 'testing',
description: 'creates a reaction',
aliases: ['test'],
cooldown: 1,
execute(message, args) {
    if (!args.length) {
        message.react(':one:');
    }      
}

}; Gives me a DiscordAPIError: Unknown Emoji

I spend some time trying different emotes like 🔥 and they are working as expected. Using the emote ID (422515569623957504) does not work as well for me.

Is this a mistake on my side or a bug?


回答1:


In Discord.js to react a message with a emoji you need to write the emoji (with 🔥 or 😀, full list here) or with a Emoji. To react with numbers you can use this:

0⃣ 1⃣ 2⃣ 3⃣ 4⃣ 5⃣ 6⃣ 7⃣ 8⃣ 9⃣ 🔟

Just copy the number you need and you're all set.
To react a message with a custom message, you need to do something like this:

message.react(message.guild.emojis.get('123456789012345678'))
  .then(console.log)
  .catch(console.error);

Note: Bots can use emojis from all servers (like Nitro). client.emojis returns a Collection of all emojis the bot can use, client.emojis.get('id') to get the emoji from another server.



来源:https://stackoverflow.com/questions/49225971/discord-js-message-react-fails-when-adding-specific-unicode-emotes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!