javascript - Discord js 添加对机器人消息的 react

标签 javascript bots discord

我已经创建了我自己的 discord 机器人,但我有此代码的错误:

  		message.channel.send(":apple:***SONDAGE :apple:\n "+choix1+" ou "+""+choix2+"***")
    		.then(function (message) {
          message.react("👍")
          message.react("👎")
       		message.pin()
          message.delete()
    			});

它向 channel 发送消息并添加 react ,在我的控制台中出现此错误:

(node:11728) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): DiscordAPIError: Unknown Message
(node:11728) 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.
(node:11728) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): DiscordAPIError: Unknown Message

最佳答案

那些不是错误,那些是警告。正如所说,当您的 promise 被拒绝时,您不会检查。 你应该在 .then() 之后使用 .catch() 以防它被拒绝。

https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise/catch

尝试:

message.channel.send(":apple:***SONDAGE :apple:\n "+choix1+" ou "+""+choix2+"***")
            .then(function (message) {
              message.react("👍")
              message.react("👎")
              message.pin()
              message.delete()
            }).catch(function() {
              //Something
             });

关于javascript - Discord js 添加对机器人消息的 react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44284666/

相关文章:

javascript - 更改页面后卸载事件

javascript 枚举自动递增?

python - 使用python在网络浏览器中自动单击按钮

node.js - 仅在一台服务器上测试不和谐机器人discordjs

javascript - 减小 Javascript 和 CSS 文件大小的最佳方法是什么?

azure - 无法与 Azure 或 Teams 中的 QnAMaker 机器人通信,但可以在本地使用模拟器

javascript - 如何检查字符串是否可能由机器人生成?

python - 如何创建一个新的私有(private)文本 channel 并向其中添加 2 个人?

python - 尝试获取公会角色时出现 Discord API 401 未经授权错误

javascript - Angular JS 范围变量不起作用