簡體   English   中英

在表情符號反應后讓 discord 機器人分配角色時遇到問題

[英]Having trouble getting discord bot to assign role after an emoji reaction

我在嘗試讓我的 discord 機器人添加基於表情符號反應的角色時遇到問題。 當我使用該命令時,我的機器人將嵌入消息和表情符號,但表情符號不可點擊。 此外,當我鍵入命令時,我收到錯誤 (node:12916) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Emoji

module.exports = {
name: 'reactionrole',
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client) {
    const channel = '810124665870325648';
    const Pug_Role = message.guild.roles.cache.find(role => role.name === "Pugs");
    

    const Pug_Emoji = ':gun:';
    

    let embed = new Discord.MessageEmbed()
        .setColor('#e42643')
        .setTitle('Pugs Click Here!')
        .setDescription('Choosing Pug will allow you to join some channels!\n\n'
            + `${Pug_Emoji} Pugs`
            );

    let messageEmbed = await message.channel.send(embed);
    messageEmbed.react(Pug_Emoji);
    

    client.on('messageReactionAdd', async (reaction, user) => {
        if (reaction.message.partial) await reaction.message.fetch();
        if (reaction.partial) await reaction.fetch();
        if (user.bot) return;
        if (!reaction.message.guild) return;

        if (reaction.message.channel.id == channel) {
            if (reaction.emoji.name === Pug_Emoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.add(Pug_Role);
            }
            
        } else {
            return;
        }

    });

    client.on('messageReactionRemove', async (reaction, user) => {

        if (reaction.message.partial) await reaction.message.fetch();
        if (reaction.partial) await reaction.fetch();
        if (user.bot) return;
        if (!reaction.message.guild) return;


        if (reaction.message.channel.id == channel) {
            if (reaction.emoji.name === Pug_Emoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.remove(Pug_Role);
            }
            
        } else {
            return;
        }
    });
}

}

您的Pug_Emoji變量必須是 unicode 字符或表情符號的 ID,例如const Pug_Emoji = '12317236871638731'; const Pug_Emoji = '' unicode 表情符號的有用網站在這里: https://emojipedia.org 這個答案提供了有關獲取表情符號 ID 的更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM