为什么我的 kick 命令只给出错误?

Why is my kick command only giving errors?

Wassup 人。我正在处理一些管理命令。此时将是踢球命令。但它只是给出错误。如果您删除一行或更改任何内容,它将感染另一个地方的代码。

这就是我正在努力解决的问题。

这是我的代码:

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: [embed] }).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);
            });
    },
};

据我所知,很可能 reason 字段为空。

您可以将其更改为此以确保有后备!

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