简体   繁体   English

如何让不和谐机器人在自己的回复中添加反应?

[英]How do I get a discord bot to add a reaction to its own reply?

Expected Result: The user comments 'fruit', the bot responds with 'apple' and leaves an apple emoji 🍎 on its own comment预期结果:用户评论“水果”,机器人回复“苹果”并在自己的评论上留下一个苹果表情符号🍎

Actual Result: The user comments 'fruit', the bot responds with 'apple' and leaves an apple emoji 🍎 on the user's comment instead实际结果:用户评论“水果”,机器人回复“苹果”并在用户评论上留下一个苹果表情符号🍎

bot.on('message', msg => {

  if(msg.content === 'fruit'){

    msg.reply('apple').then();
    msg.react('🍎');

  }

})

I've also tried the following:我还尝试了以下方法:

 bot.on('message', msg => {

  if(msg.content === 'fruit'){

     msg.reply('apple').then(react('🍎'));

  }

})

But it results in an error: 'react is not defined'但这会导致错误:'react is not defined'

Thank you in advance先感谢您

This is super easy to solve.这个超级容易解决。 All you have to do is use an arrow function inside the .then .您所要做的就是在.then使用箭头函数。

msg.reply('apple').then(m => m.react('🍎'));

You need to use the result of the message reply inside the then of of the promise :您需要在 promise 的 then 中使用消息回复的结果:

bot.on('message', msg => {
  if (msg.content === 'fruit') {
    msg.reply('apple').then((botMsg) => botMsg.react('🍎'));
  }
});

(You can have the message created inside the then, it means that the promise successed) (你可以在 then 里面创建消息,这意味着承诺成功)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 discord 机器人在 discord.js 中发送消息后有表情符号反应? - How do I make discord bot have an emoji reaction after it sends its message in discord.js? 如何让 Discord Bot 删除用户命令并将其替换为回复 - How do I get a Discord Bot to delete a user command and replace it with a reply 如何让我的机器人等待提到的用户 discord.js 的回复? - How do I get my bot to wait for reply from a mentioned user discord.js? 如何让我的 discord 机器人通过回复池回复特定消息? - How do I make my discord bot reply to a specific message with reply from a pool of replies? Discord.js 对机器人消息添加反应 - Discord js Add reaction to a bot message 我正在尝试使用我自己的不和谐机器人来制作反应角色,但由于某种原因,即使它添加了反应,它也没有添加角色 - I'm trying to make reaction roles using my own discord bot but for some reason it doesn't add the role even though it adds the reactions 如何使Discord bot DM用户获得特定答复? - How do I make my Discord bot DM users with a specific reply? 如何让我的 Discord Bot 回复类似消息的相同答案? JavaScript - How do I make my Discord Bot reply a same answer for similar messages? JavaScript 如何让 DIscord.js 机器人实际回复消息? - How do I make a DIscord.js bot actually reply to a message? 数据准备好后,如何使Discord机器人编辑自己的最后一条消息 - How can I make my discord bot edit its own last message after data is ready
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM