[英]How do I make my discord bot delete my message and react to the message above?
bot.on('message', message => {
if (message.content === 'react') {
message.delete({ timeout: 1 })
.then(() => message.react('🍎'))
.then(() => message.react('🍊'))
.then(() => message.react('🍇'));
}
});
This is the code I'm using to try and delete my message, then react to the message above mine.这是我用来尝试删除我的消息的代码,然后对我上面的消息做出反应。 I've tried using msg.channel.send('+:apple:')
but it just posts +
instead of reacting with it to the message above.我试过使用msg.channel.send('+:apple:')
但它只是发布+
而不是对上面的消息做出反应。 So I'm guessing the problem is meesage.react
trying to react to my message but it getting deleted so it just doesnt do anything.所以我猜问题是meesage.react
试图对我的消息做出反应,但它被删除了,所以它什么也没做。 Any other way to do this?还有其他方法可以做到这一点吗?
Well, that code means to react to the deleted message.好吧,该代码意味着对已删除的消息做出反应。 It's impossible.不可能。
But there's a way to fetch the latest message.但是有一种方法可以获取最新消息。
message.channel.messages.fetch({limit: 1}).then(msg => {
//...
});
Then the msg
is a collection of messages, so msg.first()
is the latest message.那么msg
就是消息的集合,所以msg.first()
就是最新的消息。 So you can use msg.first().react()
.所以你可以使用msg.first().react()
。 Full code:完整代码:
bot.on('message', (message) => {
if (message.content === 'react') {
message.delete({ timeout: 1 }).then(() => {
message.channel.messages.fetch({ limit: 1 }).then(async (msg) => {
await msg.first().react('🍎');
await msg.first().react('🍊');
await msg.first().react('🍇');
});
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.