如果我编写命令 !rang moderator 4af7d4
,我的机器人会发送一条消息说“新角色已创建”,并且它会创建一个名为 "new role"
而不是名称 { {1}}(命令后的第一个参数)。
这是我当前的代码:
"moderator"
答案 0 :(得分:2)
RoleManager#create()
接受一个 options
对象,该对象具有两个可选属性,data
和 reason
。 data
是一个 RoleData
,它具有 name
、color
、position
、permissions
等属性。
问题是你提供了一个带有两个键的对象; name
和 color
,但它们应该像这样在 data
对象内:
roles.create({
data: {
name: args[0],
color: args[1],
},
})
我对您的代码进行了一些更改,以下是您的完整代码和注释:
client.on('message', (message) => {
const args = message.content.slice(prefix.length).split(/ +/);
// move the first args to a variable named command
const command = args.shift().toLowerCase();
// you only need to check the command now, not the prefix
if (command === 'rang') {
if (!message.member.hasPermission('MANAGE_ROLES'))
return message.channel.send('Nincs jogod ehhez!');
// send an error message if role name is not provided
if (!args[0])
return message.channel.send('Rang nevének megadása kötelező');
message.guild.roles
.create({
data: {
name: args[0],
// you can add a random colour if the color is not provided
color: args[1] || 'RANDOM',
},
})
.then((role) => {
message.channel.send(`${role} rang létrehozva`);
})
.catch((err) => console.log(err));
}
});
结果如下: