message.channel.messages.fetch
does fine at fetching from the channel the mand is run in, but I need to be able to fetch messages from ANY channel in the server. For reference, I'm making a mand to quote a message via message ID, but as of right now it can only quote messages from the same channel that the mand is run in.
message.channel.messages.fetch
does fine at fetching from the channel the mand is run in, but I need to be able to fetch messages from ANY channel in the server. For reference, I'm making a mand to quote a message via message ID, but as of right now it can only quote messages from the same channel that the mand is run in.
2 Answers
Reset to default 1Loop through every channel and fetch messages in them.
message.guild.channels.cache.forEach(channel => {
channel.messages.fetch().then(messages => {
messages.forEach(msg => console.log(msg.content));
});
});
This example fetches as many messages as possible from every channel in the server and logs the content of each one. You could use an if statement to check if the message content is the specified quote to look for.
MessageManager.fetch()
let found;
message.guild.channels.cache.each(channel => {
if(found) return;
found = await channel.messages.fetch("ID_HERE").catch(() => undefined);
});