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

131
Views
DiscordAPIError: Unknown Message when trying to automatically delete messages

I am trying to create a system that automatically deletes messages in a specific channel if the message does not start with the command prefix AND the user does not have a specific role.

Everything works, but as soon as it deletes one message, it throws the error DiscordAPIError: Unknown Message

The following is the code snippet where this error is coming from:

client.on("messageCreate", (message) => {
    function deleteTalk(delay) {
        setInterval(() => {
            if (message.channel.id === "786356926216536102") {
                if (
                    !message.content.startsWith(prefix) &&
                    !message.member.roles.cache.has("791024545091420190")
                ) {
                    if (!message) return;
                    const user = message.author;
                    message.delete();
                    user.send("Please don't talk in report channels.");
                    return;
                }
            }
        }, delay);
    }

    deleteTalk(100);

//Other Code...
});

I've looked through questions where people have gotten the same error, but the solutions to those instances haven't worked for me. I've tried to add in code snippets that should prevent the function from firing again if there is no message to delete, but I assume what I had written was incorrect as I am still getting the error.

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

0

You put a setInterval so for the first execution your message is deleted but then you try again to delete it 100ms later but the message no longer exists. For your situation I don't see what the setInterval is for

client.on('messageCreate', (message) => {
    if (
        message.channel.id === '786356926216536102' &&
        !message.content.startsWith(prefix) &&
        !message.member.roles.cache.has('791024545091420190')
    ) {
        const user = message.author;
        message.delete();
        user.send("Please don't talk in report channels.");
        return;
    }
});

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!