[英]How do I make discord bot have an emoji reaction after it sends its message in discord.js?
[英]How do I get a discord bot to add a reaction to its own reply?
預期結果:用戶評論“水果”,機器人回復“蘋果”並在自己的評論上留下一個蘋果表情符號🍎
實際結果:用戶評論“水果”,機器人回復“蘋果”並在用戶評論上留下一個蘋果表情符號🍎
bot.on('message', msg => {
if(msg.content === 'fruit'){
msg.reply('apple').then();
msg.react('🍎');
}
})
我還嘗試了以下方法:
bot.on('message', msg => {
if(msg.content === 'fruit'){
msg.reply('apple').then(react('🍎'));
}
})
但這會導致錯誤:'react is not defined'
先感謝您
這個超級容易解決。 您所要做的就是在.then
使用箭頭函數。
msg.reply('apple').then(m => m.react('🍎'));
您需要在 promise 的 then 中使用消息回復的結果:
bot.on('message', msg => {
if (msg.content === 'fruit') {
msg.reply('apple').then((botMsg) => botMsg.react('🍎'));
}
});
(你可以在 then 里面創建消息,這意味着承諾成功)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.