簡體   English   中英

如何讓不和諧機器人在自己的回復中添加反應?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM