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

194
Vistas
How make a bot delete Discord channel messages that start with or are from a bot

I have a bot in my Discord server for playing music. As it works with commands, and it answers if there is something like a playlist the channel is spammed with songs or messages that later on are meaningless. So I want the bot that each time it leaves a voice channel, it clears the command messages that were sent to it and the answer messages that it sent.

So I have looked around a bit and came to this code but it doesnt work. I added some console logs to see up where it goes in, and it reaches FLAG 1 but not FLAG 2. So what is wrong in that condition? PREFIX is the "!" that commands start with, and 0123456789 is the bot ID

else if (msg.content.trim().toLowerCase() == _CMD_LEAVE) {
        const channel = msg.channel;
        const messageManager = channel.messages;
        messageManager.fetch({ limit: 100 }).then((messages) => {
             messages.forEach((message) => {
                 console.log("FLAG 1: "+ util.inspect(message))
                 if ( (message.content.startWith(PREFIX)) || (message.author.id == 0123456789)) {
                     console.log("FLAG 2: "+ util.inspect(message))   
                     message.delete();
                 }  
             });
        });
            
}

Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Two things here: startWith should actually be startsWith since you didn't mention any errors I'll assume this is just a typo from the example code.

Second, message.author.id == 0123456789 won't work since IDs should be strings, not numbers.

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