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