【发布时间】:2021-01-13 08:12:20
【问题描述】:
我的代码有点问题。下面是给我带来问题的代码。
client.on('messageReactionAdd', (reaction, user) => {
if(user.bot) return;
let message = reaction.message, emoji = reaction.emoji;
if (emoji.name == '✅') {
message.guild.fetchMember(user.id).then(member => {
member.addRole('759729116931948573');
});
}
else if (emoji.name === '????') {
message.guild.fetchMember(user.id).then(member => {
member.addRole('759768642580906026');
});
}
// Remove the user's reaction
reaction.remove(user);
});
当我执行我的 Discord 机器人并在这种情况下对消息做出反应时,我收到此错误。
TypeError: message.guild.fetchMember is not a function
0|index | at Client.client.on (/home/pi/discordbot/index.js:52:31)
0|index | at Client.emit (events.js:193:13)
0|index | at MessageReactionAdd.handle (/home/pi/node_modules/discord.js/src/client/actions/MessageReactionAdd.js:46:17)
0|index | at Object.module.exports [as MESSAGE_REACTION_ADD] (/home/pi/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js:4:37)
0|index | at WebSocketManager.handlePacket (/home/pi/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
0|index | at WebSocketShard.onPacket (/home/pi/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
0|index | at WebSocketShard.onMessage (/home/pi/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
0|index | at WebSocket.onMessage (/home/pi/node_modules/discord.js/node_modules/ws/lib/event-target.js:125:16)
0|index | at WebSocket.emit (events.js:193:13)
0|index | at Receiver.receiverOnMessage (/home/pi/node_modules/discord.js/node_modules/ws/lib/websocket.js:797:20)
现在我记得:我做了“sudo apt-get update”和“sudo apt-get upgrade”,所以可能它升级了 node.js 的版本到 v12。我不记得我有哪个版本(可能我在 2019 年初/年中安装了 node.js)。我尝试安装 v11,但出现同样的问题。有谁知道这行代码适用于哪个版本?
P.S:message.member.roles.find 也给了我这个错误:message.member.roles.find is not a function,但我用谷歌搜索并找到了解决方案。我把那行改成message.member.roles.cache.some。
提前致谢。
【问题讨论】:
标签: javascript node.js discord discord.js