Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  90] [ 6]  / answers: 1 / hits: 10939  / 4 Years ago, fri, june 12, 2020, 12:00:00

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.


More From » discord.js

 Answers
3

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.



MessageManager.fetch()


[#3502] Wednesday, June 10, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;