【问题标题】:How do I make my discord bot delete my message and react to the message above?如何让我的不和谐机器人删除我的消息并对上面的消息做出反应?
【发布时间】:2020-12-06 05:20:41
【问题描述】:
bot.on('message', message => {
    if (message.content === 'react') {
            message.delete({ timeout: 1 })
                .then(() => message.react('????'))
                .then(() => message.react('????'))
                .then(() => message.react('????'));   
        }
});

这是我用来尝试删除我的消息的代码,然后对我上面的消息做出反应。我试过使用msg.channel.send('+:apple:'),但它只是发布+????,而不是对上面的消息做出反应。所以我猜问题是meesage.react 试图对我的消息做出反应,但它被删除了,所以它什么也没做。还有其他方法吗?

【问题讨论】:

标签: javascript node.js discord discord.js


【解决方案1】:

好吧,该代码意味着对已删除的消息做出反应。这是不可能的。

但是有一种方法可以获取最新消息。

message.channel.messages.fetch({limit: 1}).then(msg => {
//...
});

那么msg是消息的集合,所以msg.first()是最新消息。所以你可以使用msg.first().react()。 完整代码:

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('?');
      });
    });
  }
});

【讨论】:

    猜你喜欢
    • 2020-09-03
    • 2021-05-19
    • 2020-11-20
    • 2020-09-12
    • 2020-12-14
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 2018-12-15
    相关资源
    最近更新 更多