简体   繁体   中英

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.

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.

target.id
// gives you message id

target.author.id

// this is what you need

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM