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

186
Visualizações
DJS - Subtracting from quick.db on message delete in specific channel if victim is a bot

I'm trying to achieve a counter for the amount of messages in my channel for suggestions. The code for counting upwards works flawlessly. But I'm struggling to subtract from triggering on message deletion and only to do so if the author of the message is a bot. Hence the (target.id === '953904462701948938').

I'm using quick.db as my database.

I'm new to Discord JS and coding overall - two week in the game, so any suggestions to improve my code is appreciated as well.

var dbSuggestionMinus = new db.table('counterM');
dbSuggestionMinus.set('minus', 0);
let dbSuggestionSubtract = parseInt();

client.on('messageDelete', async message => {
  let logs = await message.guild.fetchAuditLogs({
    type: 72
  });
  let entry = logs.entries.first();
  const {executor, target} = entry;
  if (target.id === '953904462701948938') {
      db.subtract('counterM.minus', 1);
      dbSuggestionSubtract = await db.fetch('counterM.minus');
    } 
  })

I have a channel for suggestions that embeds message sent from user and deletes the users message. This seem to trigger the event, which I think is the problem. If I log target.id I get the id of the bot when the bot makes the deletion. I only want to subtract if the victim is the bot.

Something I haven't gotten to is making this event specific to a channel, which I do request in the title. But that's the next step.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I guess I was making things too complicated. This worked fine.

var dbSuggestionMinus = new db.table('counterM');
dbSuggestionMinus.set('minus', 0);
let dbSuggestionSubtract = parseInt();

client.on('messageDelete', async message => {
  if (message.channel.id === '918462969975812166' && message.author.bot) {
      db.subtract('counterM.minus', 1)
    } 
  })

There's some obvious drawbacks with what I wanted to achieve. But hopefully this can be used for other things.

about 4 years ago · Juan Pablo Isaza Relatório

0

target.id
// gives you message id

target.author.id

// this is what you need
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