繁体   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