Ad

Discord Delete Message Filter

- 1 answer

I made a code that states that when offline users were chatting, they were deleted and a message was sent to the console that offline chat was detected.

const Discord = require('discord.js');
const bot = new Discord.Client();

bot.on('message', message => {

  let member = message.member;
  let status = member.user.presence.status;
  let args = message.content.trim().split(' ');

  if(args[0]){
      if(status === "offline") {
        message.delete();
      }
   }

bot.on('messageDelete', (msg, status) => {

  if(status === "offline"){
    console.log('Offline user chat detected.')
  }
}

However, the messageDelete section did not work and I knew status was a problem.

How can I get the other handler variables and apply them?

Ad

Answer

Client.messageDelete only allows 1 paramter, being the Message. Therefore, you may use the Message object to access the author property which is a User object. From the User object, you can access the status by getting the User.presence.status.

As a result, your messageDelete event should look like this:

bot.on('messageDelete', msg => {

  if(msg.author.presence.status === "offline") {
    console.log('Offline user chat detected.');
  }
}
Ad
source: stackoverflow.com
Ad