如何解决JavaScript参考错误(命令未定义)?

时间:2020-08-21 15:35:01

标签: javascript discord.js

我试图解决此问题,但没有成功... 有人可以帮我吗?

这将是我得到的错误

(if(Command === ${prefix}kick); { ^ ReferenceError:未定义命令)

这是我的代码:

if(Command === `${prefix}kick`); {
    
    var args = message.content.slice(prefix.length).split("/ +/");
    
    if (!message.member.hasPermissions("KICK_MEMBERS")) return message.reply("You do not have permissions to use this command!");

    if (!message.guild.me.hasPermissions("KICK_MEMBERS")) return message.reply("You do not have permissions to use this command!");

    if (!args[1]) return message.reply("You have to specify a person!");

    if (!args[2]) return message.reply("You need to inculde a reason!");

    var kickUser = message.guild.member(message.mentions.user.first() || message.guild.members.get(args[1]));

    var reason = args.slice(2).join(" ");

    if(!kickUser) return message.reply("Player not found!");

    var embedPrompt = new discord.MessageEmbed()
    .setColor("BLACK")
    .setTitle("Please answer within 30 seconds!")
    .setDescription(`Are you sure you wan\'t to kick ${kickUser}?`);

    var embed = new discord.MessageEmbed()
    .setColor("#ff0000")
    .setFooter(message.member.displayName)
    .setTimestamp()
    .setDescription(`**Kicked member:** ${kickUser} (${kickUser.id})
    ****Kicked by:** ${message.author}
    **reason:** ${reason}`);

    message.channel.send(embedPrompt).then(async msg =>{
        
        var emoji =await promptMessage(msg, message.author, 30, ["✅", "❌"]);

        if(emoji === "✅"){

            msg.delete();

            kickUser.kick(reason).catch(err =>{
                if(err) return message.reply("Oops! Something went wrong.");
            });

            message.channel.send(embed);
        }else if(emoji === "❌"){

            msg.delete();

            message.reply("Kick has been canceled!").then(m => m.delete(5000));
        }

    });

}

async function promptMessage(message, author, time, reactions){

    time *= 1000;

    for(const reaction of reactions){
        await message.react(reaction);
    };

    var filter = (reaction, user) => reactions.includes(reaction.emoji.name) && user.id === author.id;

    return message.awaitReactions(filter, {max:1, time: time}).then(collected => collected.first() && collected.first().emoji.name);

};

1 个答案:

答案 0 :(得分:0)

您首先需要定义command variabele。 const command = args.shift().toLowerCase();下面的简单var args = message.content.slice(prefix.length).split("/ +/");应该可以解决问题!