Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Is it possible to make a bot in discord.js search for previous messages without a json,or having to store it?

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't sadly. Here's why...

Explanation


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.


Fetching all messages?

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.


Demonstration

// 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>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!