Discord.js v12.2.0

编程入门 行业动态 更新时间:2024-10-10 03:26:01

Discord.<a href=https://www.elefans.com/category/jswz/34/1771451.html style=js v12.2.0"/>

Discord.js v12.2.0

我正在使用反应使机器人具有自动角色系统。这是我当前相关代码的简化版本:

client.on("messageReactionAdd", (reaction, user) => {
  if(!user || user.bot || !reaction.message.channel.guild) {
    return;
  }
  const msg = reaction.message;
  const role = msg.channel.guild.roles.cache.find(role => role.name == "Verified");
  // I would like to add the role to the user here.
});

我只想知道如何使用user对象向用户添加角色。我已经尝试过reaction.message.channel.guild.member(user).addRole(role);,但我认为v12.2.0不推荐使用,因为它只会产生错误...).addRole() is not a function。任何帮助表示赞赏!

回答如下:

由于discord.js v12 addRole()被替换为roles.add(),所以它实际上不是功能。

reaction.message.guild.member(user).roles.add(role);

更多推荐

Discord.js v12.2.0

本文发布于:2024-05-07 13:46:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:js   Discord

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!