提问者:小点点

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


我重用了一个snipe命令代码来执行这个fetch命令,但这并不是我的问题。

我正试图从一个频道获取一条消息,并将其发布到指定的频道中,例如:在X中抓取消息,并将其发布到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通道中获取消息。我的目标是尝试从一个频道获取一条消息并将其发布到另一个频道。


共1个答案

匿名用户

如果您有通道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()