简体   繁体   English

我正在尝试在对嵌入做出反应时将用户添加到角色中并且不会添加它们

[英]I'm trying to add a user to a role when reacting to an embed and won't add them

I made a command when using an embed the bot reacts to it and when anyone else reacts to it, it will add them to a rule.我在使用嵌入时发出命令,机器人对其作出反应,当其他人对其作出反应时,它会将它们添加到规则中。 But it isn't adding the user to the role and I'm unsure why.但它没有将用户添加到角色中,我不确定为什么。

const { MessageEmbed } = require('discord.js');

const Discord = require('discord.js');
module.exports = {
    name: 'reactionrole',
    async execute(message, args, client) {
        const channel = client.channels.cache.get('911914917295161354');

        const emojireact = '👍';

        let embed = new MessageEmbed()
            .setColor('#e42643')
            .setTitle('Title')
            .setDescription('description')
            if(message.member.roles.cache.some(r => r.name === "Admin" || r.name === "Badmin" || r.name === "Owner")){
                channel.send({ embeds: [embed]}).then(msg => msg.react(emojireact));
            }
        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 === emojireact) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(Members);
                }
            }else {
                return;
            }
        });
            
    }
};

The command shows the embed and the bot reacts but the user isn't added.该命令显示嵌入,机器人做出反应,但未添加用户。

Not sure how are you not getting a ReferenceError but you are passing an unknown variable to the parameter.不确定您如何没有收到ReferenceError但您将未知变量传递给参数。
At .add(Members) , I don't see Members defined anywhere in the code you sent..add(Members) ,我看不到您发送的代码中任何地方定义的Members

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Discord JS // 尝试通过对消息做出反应来添加角色 - Discord JS // Trying to add role by reacting to the message Discord.js 通过对消息做出反应来添加角色 - Discord.js add role by reacting to message 我正在尝试为我的脚本标签添加一个事件侦听器,以防它中止但不会注册“onabort”事件也不会中止 - I'm trying to add an Event Listener for my script tag incase it aborts but won't register the "onabort" event nor abort 我正在尝试将“成绩”添加到数组中,但并没有按计划进行 - I'm trying to add “grades” to an array and it isn't going as planned 尝试在成员加入服务器时添加角色 - trying to add a role when a member joins the server 我正在尝试使用我自己的不和谐机器人来制作反应角色,但由于某种原因,即使它添加了反应,它也没有添加角色 - I'm trying to make reaction roles using my own discord bot but for some reason it doesn't add the role even though it adds the reactions 我有一个公式来计算多个用户生成的值,当我尝试将所有值相加时,它只是将两者串联 - i have a formula to calculate multiple user generated values and when i'm trying to add to values together it just concatenates the two 尝试使用Javascript嵌入时,Tableau Workbook不会出现在网站中 - Tableau Workbook won't appear in website when trying to embed with Javascript 我正在尝试在javascript中制作文本框,并将输入的值发送到数组中的文本框中以添加它们 - I'm trying to make text box in javascript, and to send the entered values in a textbox in a array to add them 检查反应用户是否有角色 - Check if a reacting user has a role
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM