【问题标题】:discord.js - give role by reacting - return value problemdiscord.js - 通过反应赋予角色 - 返回值问题
【发布时间】:2020-07-21 23:58:03
【问题描述】:

所以我想要一个命令进入我的机器人,如果你对消息做出反应,它能够赋予服务器角色。通过 google/youtube 我做到了这一点。我的问题是,如果我对消息做出反应,如果我对服装表情符号做出反应,我的算法也不会进入我的开关,它甚至不会检测到我对它做出反应。可能某处返回值不同,但我还找不到它。 Sy 可以检查一下吗?

const { MessageEmbed } = require('discord.js');
const { config: { prefix } } = require('../app');

exports.run = async (client, message, args) => {

    await message.delete().catch(O_o=>{});

    const a = message.guild.roles.cache.get('697214498565652540'); //CSGO
    const b = message.guild.roles.cache.get('697124716636405800'); //R6
    const c = message.guild.roles.cache.get('697385382265749585'); //PUBG
    const d = message.guild.roles.cache.get('697214438402687009'); //TFT

    const filter = (reaction, user) => ['????' , '????' , '????' , '<:tft:697426435161194586>' ].includes(reaction.emoji.name) && user.id === message.author.id;

    const embed = new MessageEmbed()
        .setTitle('Available Roles')
        .setDescription(`

        ???? ${a.toString()}
        ???? ${b.toString()}
        ???? ${c.toString()}
        <:tft:697426435161194586> ${d.toString()}

        `)
        .setColor(0xdd9323)
        .setFooter(`ID: ${message.author.id}`);

    message.channel.send(embed).then(async msg => {

        await msg.react('????');
        await msg.react('????');
        await msg.react('????');
        await msg.react('697426435161194586');

        msg.awaitReactions(filter, {
            max: 1,
            time: 15000,
            errors: ['time']
        }).then(collected => {

            const reaction = collected.cache.first();

            switch (reaction.emoji.name) {
                case '????':
                    message.member.addRole(a).catch(err => {
                        console.log(err);
                        return message.channel.send(`Error adding you to this role **${err.message}.**`);
                    });
                    message.channel.send(`You have been added to the  **${a.name}** role!`).then(m => m.delete(30000));
                    msg.delete();
                    break;
                case '????':
                    message.member.addRole(b).catch(err => {
                        console.log(err);
                        return message.channel.send(`Error adding you to this role **${err.message}.**`);
                    });
                    message.channel.send(`You have been added to the  **${b.name}** role!`).then(m => m.delete(30000));
                    msg.delete();
                    break;
                case '????':
                    message.member.addRole(c).catch(err => {
                        console.log(err);
                        return message.channel.send(`Error adding you to this role **${err.message}.**`);
                    });
                    message.channel.send(`You have been added to the  **${c.name}** role!`).then(m => m.delete(30000));
                    msg.delete();
                    break;
                case '<:tft:697426435161194586>':
                    message.member.addRole(d).catch(err => {
                        console.log(err);
                        return message.channel.send(`Error adding you to this role **${err.message}.**`);
                    });
                    message.channel.send(`You have been added to the  **${d.name}** role!`).then(m => m.delete(30000));
                    msg.delete();
                    break;
            }
        }).catch(collected => {
            return message.channel.send(`I couldn't add you to this role!`);
        });
    });
};

exports.help = {
    name: 'roles'
};

【问题讨论】:

    标签: javascript node.js discord discord.js chatbot


    【解决方案1】:

    从 discord.js v12 开始,添加角色的新方法是 message.member.roles.add(role),而不是 message.member.addRole。有关详细信息,请参阅documentation

    【讨论】:

      【解决方案2】:

      您需要使用roles.add() 而不是addRole()

      【讨论】:

        【解决方案3】:

        朋友,您不能在代码中使用表情符号的 id(发送消息时除外)。因此,必须将自定义表情符号替换为真实的表情符号,该表情符号在您的编辑器中显示一个框,并且在不和谐中完美运行。如果你能找到它,那么这可能是完整的,因为 discord API 找不到表情符号 <:tft:697426435161194586>。您可以通过在不和谐中使用它并在浏览器中打开不和谐并通过检查元素来获取表情符号。

        否则,您将不得不使用不同的表情符号。

        【讨论】:

          猜你喜欢
          • 2021-06-06
          • 2020-10-07
          • 2021-11-18
          • 2018-06-10
          • 2021-01-07
          • 2017-07-07
          • 2021-02-07
          • 1970-01-01
          相关资源
          最近更新 更多