简体   繁体   English

Discord.JS反应角色

[英]Discord.JS Reaction Roles

I don't know why my reaction role code won't work.我不知道为什么我的反应角色代码不起作用。 If anyone could help me that would be appreciated!如果有人可以帮助我,将不胜感激!

client.on('messageReactionAdd', async (reaction, person) => {
    if (reaction.partial) {
        try {
            await reaction.fetch();
        } catch (error) {
            console.error('Something went wrong when fetching the message: ', error);
            return;
        };
    };

    if (reaction.emoji.name == ':tools:') {
        if (reaction.message.id === '769855387394375681')
        var server = client.guilds.cache.get('769100711593771038');
        let personMember = server.members.cache.get(person);
        const devRole = server.roles.cache.get('769428024609079319')
        personMember.roles.add(devRole);
    };

});

client.on('message', message => {
    return; //For now, gotta code more stuff later
});

The message function is there to cache the messages so that the bot can detect reactions on that message, Idk if it's really needed though.消息 function 用于缓存消息,以便机器人可以检测对该消息的反应,Idk 如果真的需要的话。

There's also no errors, it just won't give me the role.也没有错误,只是不会给我这个角色。

You need to specify an emoji ID, rather than just :tools: in your if statement.您需要在 if 语句中指定表情符号 ID,而不仅仅是:tools: You can get this by typing the emoji in Discord, then putting a backslash in front of it.你可以通过在 Discord 中输入表情符号,然后在它前面加上一个反斜杠来获得它。 Send the message and you will get something like <:tools:213812938712938713> .发送消息,你会得到类似<:tools:213812938712938713>的信息。 The numerical part is your ID.数字部分是您的 ID。

EDIT: You will need to do if (reaction.emoji.id === 'IDHERE')编辑:你需要做if (reaction.emoji.id === 'IDHERE')

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

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