Basically like the search function in discord.
For example if I want to make a
!search [user] [query]
and make it respond
"50 messages fit the query"
a word counter bot without the db or local storage basically.The bot would return 87 on this query
You can't sadly. Here's why...
Message query is limited to user accounts.
There's a lot of ways to do the workaround but the best way and most used is to fetch a large amount of messages in the specific channel.
All endpoints that are related to fetching always have a limit of 100 things per request.
Fetching messages? 100 messages per request. etc. etc.
There's no way to bypass this, and the only solution is to fetch and re-fetch and re-fetch until you reached certain amount.
// Fetch a 100 messages from a Channel
// You can always fetch more and concat() the collections together
// <Channel> is a placeholder for guild's text-based channels
const messages = await <Channel>.messages.fetch({ limit: 100 });
// Make a filter
// In this case, we're finding messages with "hello". Case insensitive
const query = (msg) => msg.content.toLowerCase().includes("hello");
// Filter out non-matching messages
const matching = messages.filter(query);
console.log(matching);
// `matching` is Collection<Snowflake, Message>