Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda