首页 > 解决方案 > 当我对消息做出反应时,机器人不会赋予角色

问题描述

没有错误,但当我对我编码的消息做出反应时,它没有发挥作用。实际上我在 Top.gg 服务器上问过这个问题,但 1 人告诉我我的“命令处理程序”不支持功能。

代码在这里

const { MessageEmbed, Client, Message, Discord } = require('discord.js');
module.exports = {
    name: 'rectrole',
    description: "If anyone reacts to msg gains role.",
    async execute(msg, args, Discord, Client){
            const Role = msg.guild.roles.cache.find(role => role.name === "Member");
            const channel = '878990757615247410';
            const Emoji = '878990351753429073';
    
            const reactionchannel = msg.channel
            const reactionEmbed = new MessageEmbed()
            .setColor('#ffffff')
            .setTitle('REACT TO GET ROLE')
            .setDescription('Reacting for get role is important for u to be verified.');
            const embed = await reactionchannel.send({ embeds: [reactionEmbed] });
            embed.react(Emoji)
            
            Client.on('messageReactionAdd', async (reaction, user) => {
                if(reaction.msg.partial) await reaction.msg.fetch();
                if(reaction.partial) await reaction.fetch();
                if(user.bot) return;
                if(!reaction.msg.guild) return;
                if(reaction.msg.channel.id == channel){
                    if(reaction.Emoji.id === Emoji){
                        await reaction.guild.members.cache.get(user.id).roles.add(Role);
                    }
                }
            });
    }
}

标签: javascript

解决方案


推荐阅读