Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda