Discord.js:您如何在新的12.0.0更新中使用机器人添加角色?

时间:2020-04-28 18:11:32

标签: javascript discord.js

我正在尝试执行softmute命令,但出现此错误:TypeError: Cannot read property 'add' of undefined

const muteduser = message.mentions.users.first();
const muterole = message.guild.roles.cache.find(r => r.name == 'Muted')
if (message.guild.member(muteduser).bannable) {
  const ismember = message.guild.member(muteduser)
  muteduser.roles.add(muterole.id);

1 个答案:

答案 0 :(得分:0)

您遇到的问题是由于您将muteduser定义为User而不是GuildMember

您需要将const muteduser = message.mentions.users.first();替换为const muteduser = message.mentions.members.first();