I got this function from another stackoverflow question. I fixed it to work with Discord.js v12 by changing channel.fetchMessages to channel.messages.fetch
channel.fetchMessages
channel.messages.fetch