如何从频道获取消息? discord.js

How can I fetch a message from a channel? discord.js

我重复使用了 snipe 命令代码来制作这个获取命令,但这不是我的问题。

我正在尝试从频道获取消息并 post 在指定频道中获取消息,例如: 抓住 X 中的消息,然后 post 它在 Y 中。如果这有意义,我目前所拥有的是:

const Discord = require('discord.js');

module.exports = class FetchCommand extends BaseCommand {
  constructor() {
    super('fetch', 'fun', []);
  }

  async run(client, message, args) {
    const msg = client.snipes.get(message.channel.id);
    if (!msg) return message.channel.send('There are no messages to fetch.');
    
    const fetchEmbed = new Discord.MessageEmbed()
      .setAuthor(msg.author.tag, msg.author.displayAvatarURL())
      .setDescription(msg.content)
      .setTimestamp()

    message.channel.send(fetchEmbed);
  }
}

非常感谢帮助!

PS:截至目前,它从正在运行正在执行命令的频道获取消息。如果我在 X 通道中发送消息,并且 运行 在 X 通道中发送命令,它将在 X 通道中获取消息。 我的目标是尝试从一个频道获取一条消息,然后 post 在另一个频道中获取它。

如果您有频道 ID 和消息 ID:await message.guild.channels.cache.get('channel-id').messages.fetch('message-id')(仅限异步函数)

如果您只有频道 ID 并且想要不是命令的最后一条消息:(await message.guild.channels.cache.get('channel-id').messages.fetch({ count: 2 })).first()