我正在尝试执行Autorole命令,然后它将用户想要的角色赋予每个新成员。
我的代码: main.js:
const mentionedRole = require("./cmds/autorole")
bot.on('guildMemberAdd', member => {
member.roles.add(mentionedRole);
})
autorole命令:
module.exports.run = async (bot, message, args) => {
const mentionedRole = message.mentions.roles.first();
if (!mentionedRole) return message.channel.send(`I cannot to use the role: ${mentionedRole}`);
message.channel.send(`Autorole successfully added (${mentionedRole}).`);
}
它给出的错误:
Supplied roles is not an Role, Snowflake or Array or Collection of Roles or Snowflakes.
答案 0 :(得分:0)
要通过提及message.mentions.roles.first()
来扮演角色,您需要@testRole
所以我建议这样做:
const mentionedRole = message.guild.roles.cache.find(r => r.name === args.slice(1).join(" "));
if (!mentionedRole) return message.channel.send(`I cannot to use the role: ${mentionedRole}`);
message.channel.send(`Autorole successfully added (${mentionedRole}).`);
现在应该看起来像这样:
例如?autorole testRole
不是?autorole @testRole