I'm currently trying to fetch all messages in a guild, yet the .fetchMessages method only works on specific channels.
I've already tried using the .forEach function but have received multiple errors whilst doing so.
async function intervalFunc() {
  var mainGuild = client.guilds.get("562324876330008576");
  var messagesArray = [];
  await mainGuild.channels.forEach(channel => {
    if (channel.type == "text") {
      channel.fetchMessages({ limit: 20 }).then(msg => {
        messagesArray.push(msg);
      });
    }
  });
  console.log(messagesArray.length)
  //....
}
The expected output is at least a few hundred but instead, it outputs 0.
 
     
    