Discord.js check warnings command bug

Viewed 244
const Mongodb = require('../../models/modSchema');
const Discord = require('discord.js');

module.exports = {
    name: 'warnings',
    category: "moderation",
    description: 'Finds and displays the warnings of the mentioned user.',
    run : async(client, message, args, db) => {
        const mentionedMember = message.mentions.members.first() || message.guild.members.cache.get(args[0]);

        if(!mentionedMember) return message.channel.send("bruh mention a member u nub");

        Mongodb.find({ guildId : message.guild.id, userId : mentionedMember.user.id}, async(err, data) => {
            if(err) throw err;
            if(data) {
                message.channel.send(new Discord.MessageEmbed()
                    .setTitle(`${mentionedMember.user.tag}'s punishments.`)
                    .addFields(
                        data.map((warn)=> {
                            if (!warn || warn === undefined) return { name: 'Punishments', value: 'This user has no punishments' };
                            if (warn) return { name: `Case #${warn.case} - ${warn.punishType}`, value: warn.reason};
                        })
                    )
                    .setColor("GREEN")
                )
            } 
        });
    }
}

This is my code. Whenever I type -warnings user and the user has no warns then it replies with user's warn when it's supposed to reply with This user has no warnings. Another question I have is how to make the bot show the user's warnings when the user says -warnings it shows the current user's warnings meaning that the user that said -warnings.

0 Answers
Related