我无法从 message.mentions.roles.first() 和 message.mentions.members.first() 获取正确信息
这是我在 Index.js 中的命令处理程序
bot.on('message', async (message, guild, helpList, roles) => {
if (!message.content.startsWith(prefix) || message.author.bot || !message.member.hasPermission('MANAGE_ROLES')) return;
const args = message.content.slice(prefix.length).split(' ') ;
const command = args.shift().toLowerCase();
const aRole = message.mentions.roles.first();
const Role = aRole.id
const name = args.join(' ');
const User = message.mentions.members.first();
if (!Role && command !== 'create' && command !== 'give' && command !== 'take' && command !== 'help' && command !== 'list') {return message.channel.send('Sorry, that role was not found.')}
if (!User && (command == 'give' || command == 'take') ) {return message.reply ("That name doesnt match a user.");}
try{
bot.commands.get(command).execute(message, Role, name, User, guild, helpList);
} catch(e){
console.log(e)
}
});
bot.commands.get(command).execute(message, Role, name, User, guild, helpList);
} catch(e){
console.log(e)
}
});
这是我的 take.js,一个从指定成员中删除角色的命令。
module.exports = {
name: 'take',
description: '',
execute(message, Role, User, roles){
try{
User.roles.remove(Role);
return message.channel.send (`${Role} has been removed from ${User}'s list of rolls.`);
}catch(e){
console.log(e);
console.log(Role)
console.log(User)
}}}
这是我得到的错误。
TypeError: Cannot read property 'remove' of undefined
at Object.execute (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/commands/take.js:6:16)
at Client.<anonymous> (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/index.js:34:33)
at Client.emit (events.js:310:20)
at MessageCreateAction.handle (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:437:22)
at WebSocketShard.onMessage (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:294:10)
at WebSocket.onMessage (/mnt/c/Users/bgera/OneDrive/Desktop/BOTT/RoleBot/node_modules/ws/lib/event-target.js:125:16)
at WebSocket.emit (events.js:310:20)
711442214043254854
<@&711442214043254854> <@!271438275619586062>
为什么角色不起作用?任何帮助是极大的赞赏。