我得到的只是这个(在那里,当写作(!+)时,他履行了这个角色,但即便如此她是一个非工人,请帮忙)
bot.on('message', msg => {
if (msg.content === prefix + '+') {
member.roles.remove(801095844044341279).catch(console.error);
}
});
消除这个错误
C:\Users\user\Desktop\bot\index.js:40
member.roles.remove(801095844044341279).catch(console.error);
^
ReferenceError: member is not defined
at Client.<anonymous> (C:\Users\user\Desktop\bot\index.js:40:5)
at Client.emit (events.js:327:22)
at MessageCreateAction.handle (C:\Users\user\Desktop\bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\user\Desktop\bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\user\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\user\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\user\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\user\Desktop\bot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Users\user\Desktop\bot\node_modules\ws\lib\websocket.js:825:20)
答案 0 :(得分:0)
您需要使用 Message 对象从中获取成员。
像这样:
bot.on('message', msg => {
if (msg.content === prefix + '+') {
msg.member.roles.remove('801095844044341279').catch(() => {
console.error("failed to remove role");
});
}
});
我还修复了您的 console.error
,因为它的语法无效,如果它无法删除角色,它现在会正确地向控制台出错。