Javascript Discord js 添加对机器人消息的反应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44284666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Discord js Add reaction to a bot message
提问by ZaraaKai
I've been created my own discord bot but i have this error for this code:
我已经创建了自己的不和谐机器人,但此代码出现此错误:
message.channel.send(":apple:***SONDAGE :apple:\n "+choix1+" ou "+""+choix2+"***")
.then(function (message) {
message.react("")
message.react("")
message.pin()
message.delete()
});
It's send a message to the channel and add reaction, and in my console i have this error:
它向频道发送消息并添加反应,在我的控制台中我有这个错误:
(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
回答by Nevosis
Those aren't error, those are warning. As it is said, you don't check when your promise is rejected. You should use .catch() after .then() in case it get rejected.
那些不是错误,那些是警告。如前所述,当您的承诺被拒绝时,您不会检查。你应该在 .then() 之后使用 .catch() 以防它被拒绝。
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise/catch
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise/catch
Try :
尝试 :
message.channel.send(":apple:***SONDAGE :apple:\n "+choix1+" ou "+""+choix2+"***")
.then(function (message) {
message.react("")
message.react("")
message.pin()
message.delete()
}).catch(function() {
//Something
});
回答by Cecemel_PvP
I had the same error, you do message.delete(), but you want to add reactions. When a message is deleted the bot can't add reactions. Just remove the message.delete()and no error will come.
我有同样的错误,你有message.delete(),但你想添加反应。删除消息后,机器人无法添加反应。只需删除message.delete(),就不会出现错误。

