首页 > 解决方案 > 未使用“messageReactionAdd”事件定义消息以执行操作

问题描述

我希望我的机器人对“message.member”执行操作,因为该成员对来自我的机器人的消息使用某个表情符号做出反应。但是,我有一个错误“未定义消息”,我对此无能为力。

我想我需要使用“messageReactionAdd”,因为我需要知道服务器上的每个反应,检查它们是否应用于我的机器人消息,然后将操作返回给执行它们的用户。这必须涉及来自我的机器人的所有消息,甚至是旧消息。我想使用的所有方法都是 GuildMember 的方法:https ://discord.js.org/#/docs/main/stable/class/GuildMember 。

client.on('messageReactionAdd', (reaction, user) => {
  console.log(`mess id : ${reaction.message.id} emoji user = ${reaction.message.member.id}`);
    if ((reaction.message.author.id == client.user.id) && (user.id != client.user.id)) {
      if (reaction.emoji.name == '') {
        message.member.send('You picked   '); 
      }
    }
  });
UnhandledPromiseRejectionWarning: ReferenceError: message is not defined
    at Client.client.on (/home/me/botdiscord/index.js:84:7)
    at Client.emit (events.js:193:13)
    at MessageReactionAdd.handle (/home/me/botdiscord/node_modules/discord.js/src/client/actions/MessageReactionAdd.js:46:17)
    at Object.module.exports [as MESSAGE_REACTION_ADD] (/home/me/botdiscord/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js:4:37)
    at WebSocketManager.handlePacket (/home/me/botdiscord/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/home/me/botdiscord/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/home/me/botdiscord/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/me/botdiscord/node_modules/ws/lib/event-target.js:125:16)
    at WebSocket.emit (events.js:193:13)
    at Receiver.receiverOnMessage (/home/me/botdiscord/node_modules/ws/lib/websocket.js:797:20)
(node:7306) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7306) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

标签: javascriptdiscord.jsmember

解决方案


我确实添加了“reaction.message [...]”,但看不到该消息。所以我把“.nickname”方法放上来看看是否有效。但是我将昵称更改为他自己,而不是做出表情反应的用户。请问有什么帮助吗?

client.on('messageReactionAdd', (reaction, user) => {
  console.log(`mess id : ${reaction.message.id} emoji user = ${reaction.message.member.id}`);
    if ((reaction.message.author.id == client.user.id) && (user.id != client.user.id)) {
      if (reaction.emoji.name == '') {
        reaction.message.member.setNickname('')
        .then(console.log)
        .catch(console.error);
      }
    }
  });

推荐阅读