0
votes

I reused a snipe command code to make this fetch command but that's not really my issue here.

I'm trying to fetch a message from a channel and post it in a designated channel, for example: Grab the message in X, and post it in Y. If that makes sense, all I have so far are:

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);
  }
}

Help is very appreciated!

PS: As of right now, it fetches the messages from the channel it is running the command it. If I sent a message in X channel, and run the command in X channel it would fetch the message in the X channel. My goal is trying to fetch a message from a channel and post it in another channel.

1
Did you take a look at this question already? stackoverflow.com/questions/64854513/discord-js-snipe-command - Gilles Heinesch
This is doing the opposite of what my fetch command is doing, that snipe command is fetching deleted messages, my command is fetching messages sent (not like it matters, I can reuse if I was going for that). However, that is not what I am looking for, with that snipe code it alerts whenever a message was deleted. In my case, I want to specifically fetch a message from a channel not multiple or all. - ignshifts

1 Answers

1
votes

If you have the channel ID and message ID: await message.guild.channels.cache.get('channel-id').messages.fetch('message-id') (async functions only)

If you just have the channel ID and want the last message that wasn't the command: (await message.guild.channels.cache.get('channel-id').messages.fetch({ count: 2 })).first()