检查最后一条之前的消息

Check for the message before the last

我正在尝试让我的机器人删除特定数量的消息,我认为 if 最适合这种情况,但我不知道该怎么做...

它应该是这样工作的:频道中有一条来自我的机器人的消息,它始终是聊天中的最后一条。我的机器人会检查消息是否确实存在,如果存在,它将删除消息和命令,然后发送一条新消息。如果消息不存在,它只会删除命令并发送新消息。

这是我的参考代码:

if(/* message is there */) const fetched = await message.channel.fetchMessages({limit: 2});
else const fetched = await message.channel.fetchMessages({limit: 1});

// Deletes stuff
message.channel.bulkDelete(fetched)
  .catch(error => message.reply(`There was an error: ${error}`));
message.channel.send("```Open```");

我如何检查之前的消息是否存在?

我会检查最后一条消息的作者是否是您的机器人:

let lastTwo = await message.channel.fetchMessages({limit: 2}), // Get the last 2 messages
  last = lastTwo.last(); // The last in the collection will be the last message
if (last.author.id == client.user.id) await message.channel.bulkDelete(lastTwo);
else await last.delete();
message.channel.send("```Open```");