【问题标题】:Discord.js v12 MessageReactionAddDiscord.js v12 消息反应添加
【发布时间】:2021-01-03 04:54:21
【问题描述】:

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

【问题讨论】:

标签: javascript node.js discord discord.js


【解决方案1】:

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

【讨论】:

  • 不用guild.members.fetch(user.id),你可以写guild.member(user)
  • 如果我没记错的话,成员在反应时会被缓存。
  • 确实看起来成员对象也被发送了discord.com/developers/docs/topics/… 它是相同的(discord.js 无论如何都会使用缓存)并且确保我几乎在任何地方都使用 fetch
  • 非常感谢您的帮助!我真的很感激!
猜你喜欢
  • 2020-11-30
  • 2021-11-13
  • 2021-08-11
  • 2020-10-25
  • 2021-03-31
  • 2022-01-21
  • 2021-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多