Reputation: 28
message.channel.messages.fetch
does fine at fetching from the channel the command is run in, but I need to be able to fetch messages from ANY channel in the server. For reference, I'm making a command to quote a message via message ID, but as of right now it can only quote messages from the same channel that the command is run in.
Upvotes: 0
Views: 13171
Reputation:
let found;
message.guild.channels.cache.each(channel => {
if(found) return;
found = await channel.messages.fetch("ID_HERE").catch(() => undefined);
});
Upvotes: 1
Reputation: 471
Loop 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.
Upvotes: 1