最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Discord.js v12.2.0

IT培训 admin 10浏览 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

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

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

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论