Discord.js v12 MessageReactionAdd

时间:2020-09-16 11:05:33

标签: javascript node.js discord discord.js

我对javascript和discord.js还是很陌生,谁能帮助我并告诉我如何设置做出反应的用户的角色?我一直很难做到这一点。

client.on('messageReactionAdd', async (reaction, user) => {
 if (reaction.message.partial) await reaction.message.fetch();
 if (reaction.message.id === '755695010657206323') {
  switch (reaction.emoji.id) {
   case '753885482298900510':
    break;
  }
 }
});

1 个答案:

答案 0 :(得分:0)

使用user对象来解析成员:

client.on('messageReactionAdd', async (reaction, user) => {
 if (reaction.message.partial) await reaction.message.fetch();
 if (reaction.message.id === '755695010657206323') {
  switch (reaction.emoji.id) {
   case '753885482298900510':
    const member = await reaction.message.guild.members.fetch(user.id);
    member.roles.add('ROLE_ID');
    break;
  }
 }
});