Attempting to react to messages older than bot does not work

I'm trying to make my bot react with an emoji to all messages that are in a server. However, the reactions do go back by one day, but don't go farther than that.
Here's the code:
const { Client, Events, GatewayIntentBits, Partials, TextChannel } = require("discord.js")
const env = require("dotenv")
env.config()

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
partials: [ Partials.Channel, Partials.Message ] });
client.once(Events.ClientReady, async (readyClient) => {
    console.log(`Ready! Logged in as ${readyClient.user.tag}`);
    let server = await client.guilds.fetch("1155619424020213801");
    let channels = await server.channels.fetch(); // Get ALL channels
    for (let channel of channels){
        if (channel[1].type == 4){continue}
        let messages = await fetchAllMessages(channel[1],server)
        //const filteredMessages = messages.filter(m => m.reactions.cache.me == false);
        let i = 0;
        messages.forEach(function(e){
            e.react("šŸ‰");
            i++;
        })
        console.log("Finished with channel " + channel[1].name+" and count "+i)
    }
    console.log("Finished reacting.")
});

// Log in to Discord with your client's token
client.login(process.env.token);

async function fetchAllMessages(id,server) {
  const channel = id
  if (channel.size == 38){
    console.log("Defaulted?")
    return []
  }
  let messages = [];
  let message = channel.messages.fetch({ limit: 1 })
    .then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null));
  while (message) {
    await channel.messages
      .fetch({ limit: 100, before: message.id })
      .then(messagePage => {
        messagePage.forEach(msg => messages.push(msg));
        message = 0 < messagePage.size ? messagePage.at(messagePage.size - 1) : null;
      });
  }

  return messages // Print all messages
}
Was this page helpful?