简体   繁体   English

Discord.js v13 反应角色

[英]Discord.js v13 Reaction Roles

I already have this code to post an embed and to add a reaction, I'm just wondering how I would go about adding a role to a user when they add the reaction?我已经有了这个代码来发布嵌入和添加反应,我只是想知道当他们添加反应时我将如何向用户添加角色?

if (message.content.startsWith(`${prefix}rr`)) {
    let embed = new MessageEmbed()
        .setColor("#ffffff")
        .setTitle("📌 Our Servers Rules 📌")
        .setDescription("To keep our server safe we need a few basic rules for everyone to follow!")
        .setFooter("Please press ✅ to verify and unlock the rest of the server!")
        .addFields(
            {
                name: "1.",
                value: "Stay friendly and don't be toxic to other users, we strive to keep a safe and helpful environment for all!",
            },
            {
                name: "2.",
                value: "Keep it PG-13, don't use racist, homophobic or generally offensive language/overly explicit language!",
            },
            {
                name: "3.",
                value: "If you want to advertise another server/website etc please contact me first!",
            },
            { name: "4.", value: "Don't cause drama, keep it civil!" },
            {
                name: "5.",
                value: "If you have any questions please contact me @StanLachie#4834",
            }
        );
    message.channel.send({ embeds: [embed] }).then((sentMessage) => {
        sentMessage.react("✅");
    });
}

You may want to check this Discord.js Guide page .您可能需要查看此Discord.js 指南页面 But in summary...但总而言之...

const filter = (reaction, user) => {
    return reaction.emoji.name === '✅' && user.id === message.author.id;
};

const collector = message.createReactionCollector({ filter });

collector.on('collect', (reaction, user) => {
    const role = await message.guild.roles.fetch("role id");
    
    message.guild.members.fetch(user.id).then(member => {
         member.roles.add(role);  
    });
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM