简体   繁体   中英

Discord.js v12 MessageReactionAdd

I'm pretty new to javascript and discord.js, can anyone help me and tell me how I can set the role of the user that reacted? I've been having trouble doing this myself.

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;
  }
 }
});

Use the user object to resolve the member:

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;
  }
 }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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