我遇到了一些问题,我正试图添加一个名为Simon Says Player的角色,有人能帮帮我吗?
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]) {
case 'join':
let person = message.guild.member
if (!person) {
return message.reply('Couldn`t find the user!');
}
let mainRole = (role => role.name === "Simon Says Player");
member.addRole(mainRole.id);
message.channel.send('Successfully Entered The Game!!')
break;
}
})
member
其实是 undefined
你没有说明预期的功能,但在我看来,你是想给发送了 join
命令。
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]) {
case 'join':
let person = message.guild.member
if (!person) {
return message.reply('Couldn`t find the user!');
}
let mainRole = message.guild.roles.cache.find(role => role.name === "Simon Says Player");
message.member.roles.add(mainRole.id);
message.channel.send('Successfully Entered The Game!!')
break;
}
})
试试 message.member.addRole(mainRole.id)
而不是 member.addRole(mainRole.id)
这在你的例子中应该是有效的。
switch (args[0]) {
case 'join':
let person = message.member
if (!person) {
return message.reply('Couldn`t find the user!');
}
let mainRole = message.guild.roles.cache.find(role => role.name === "Simon Says Player");
message.member.roles.add(mainRole);
message.channel.send('Successfully Entered The Game!!')
break;
}