简体   繁体   English

如何让我的 discord 机器人删除我的消息并对上面的消息作出反应?

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

相关问题 如何让我的不和谐机器人自动回复消息? - How do I make my discord bot auto respond to a message? 如何让我的 Discord.JS 机器人对其自己的直接消息做出反应? - How do I make my Discord.JS bot react to it's own Direct Message? 如何让我的不和谐机器人复制并发送每个用户写的消息? - How do I make my discord bot copy and message every user written message? 如何让我的 Discord 机器人发送欢迎消息? - How do I get my Discord bot to send a welcome message? 当特定用户玩特定游戏时,如何让我的不和谐机器人发送消息? - How do I make my discord bot send a message when a specific user plays a specific game? 如何让我的 discord 机器人通过回复池回复特定消息? - How do I make my discord bot reply to a specific message with reply from a pool of replies? 如何让我的 discord 机器人在特定时间或日期发送消息 - How do I make my discord bot to send a message on a certain time or date 如何让我的机器人在特定频道中发送消息,然后在一段时间后将其删除 - How do I make my bot send a message in a specific channel then delete it after a period of time 如果我的不和谐机器人对发送的每条消息都做出反应,我怎么能让它只对 png、jpg 和 gif 做出反应 - How could I make my discord bot react to only png, jpg and gifs if it's reacting to every message sent 如何在一段时间后删除 discord 机器人消息? - How do I delete discord bot message after time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM