Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my kick command only giving errors?

Wassup people. I am working on some admin commands. At this moment it’s going to be a kick command. But it’s only giving errors. If you remove a line or change anything, it will infect the code in another place.

That’s what I am struggling with.

Here’s my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const { Client, Intents } = require("discord.js");
const discord = require("discord.js");
const { MessageEmbed, Collection, Permissions } = require("discord.js");

module.exports = {
    name: "kick",
    description: "Kicks a specific member",
    admin: true,
    usage: "[Target] [Reason] [Messages]",
    options: [
        {
            name: "Target",
            description: "Provide A User To Kick.",
            type: "USER",
            required: true,
        },
        {
            name: "Reason",
            description: "Provide A Reason For The Kick.",
            type: "STRING",
            required: true,
        },
    ],

    async execute(message, args, client) {
        const target = message.mentions.members.first();
        const reason = args.slice(1, args.length - 1).join(" ");

        console.log("Target: ");

        const embed = new MessageEmbed().setTitle("There seems to be a error to execute this command").setColor("RED").setDescription("Are you sure you got the right permission? And are you providing a reason?");

        if (!message.member.permissions.has(Permissions.FLAGS.KICK_MEMBERS))
            return message.reply({ embeds:  }).catch((err) => {
                console.log(err);
            });

        if (target.id === message.member.id)
            return message.reply({
                embeds: [new MessageEmbed().setTitle("There seems to be a error to execute this command").setColor("RED").setDescription("Why would you kick yourself?")],
                ephemeral: true,
            });

        if (target.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) {
            return message.reply({
                embeds: [new MessageEmbed().setColor("RED").setDescription("You can't kick this person.")],
            });
        }

        const DMEmbed = new MessageEmbed().setTitle(`You've Been Kicked From ${message.guild.name}`).setColor("RED").setTimestamp().addFields(
            {
                name: "Reason:",
                value: reason,
            },
            {
                name: "Kicked By:",
                value: message.member.user.toString(),
            }
        );

        await target
            .send({
                embeds: [DMEmbed],
            })
            .catch((err) => {
                console.log(err);
            });
    },
};

>Solution :

From what I can see, it is most likely the reason field being empty.

You can change it to this to ensure there is a fallback!

            {
                name: "Reason:",
                value: reason.replace(/\s/g, '') == "" ? "Not Provided" : reason,
            },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading