Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 踢| Discord.js时的层次结构问题_Javascript_Json_Discord.js - Fatal编程技术网

Javascript 踢| Discord.js时的层次结构问题

Javascript 踢| Discord.js时的层次结构问题,javascript,json,discord.js,Javascript,Json,Discord.js,我不知道如何解决这个问题 使用此代码时,我得到错误: 由于角色层次关系,我不能踢那个人 我的机器人甚至比我想踢的人还硬。这个问题的原因是什么 module.exports = { name: 'kick', description: 'Kick someone!', alias: '', access: 'Moderators', command: '!kick', execute(Discord, client, msg, args) {

我不知道如何解决这个问题 使用此代码时,我得到错误:

由于角色层次关系,我不能踢那个人

我的机器人甚至比我想踢的人还硬。这个问题的原因是什么


module.exports = {
    name: 'kick',
    description: 'Kick someone!',
    alias: '',
    access: 'Moderators',
    command: '!kick',
    execute(Discord, client, msg, args) {
        msg.delete(5000);

        if (!args[0]) {
            return msg.reply("Please provide a person to kick.")
                .then(m => m.delete(5000));
        }
        if (!args[1]) {
            return msg.reply("Please provide a reason to kick.")
                .then(m => m.delete(5000));
        }
        if (!msg.member.hasPermission("KICK_MEMBERS")) {
            return msg.reply("❌ You need to be an **admin** or **moderator** to use this command.")
                .then(m => m.delete(5000));
        }
        if (!msg.guild.me.hasPermission("KICK_MEMBERS")) {
            return msg.reply("❌ I do not have permissions to kick members. Please contact a staff member")
                .then(m => m.delete(5000));
        }

        var kUser = msg.mentions.users.first() || msg.guild.members.get(args[0]);

        if (!kUser) {
            return msg.reply("Couldn't find that member, try again")
                .then(m => m.delete(5000));
        }
        if (kUser.id === msg.author.id) {
            return msg.reply("You can't kick yourself...")
                .then(m => m.delete(5000));
        }
        if (!kUser.kickable) {
            return msg.reply("I can't kick that person due to role hierarchy.")
                .then(m => m.delete(5000));
        }

        const embed = new RichEmbed()
        .setColor("#ff0000")
        .setThumbnail(kUser.user.displayAvatarURL)
        .setFooter(msg.member.displayName, msg.author.displayAvatarURL)
        .setTimestamp()
        .setDescription(stripIndents`**> Kicked member:** ${kUser} (${kUser.id})
        **> Kicked by:** ${msg.member} (${msg.member.id})
        **> Reason:** ${args.slice(1).join(" ")}`);

    const promptEmbed = new RichEmbed()
        .setColor("GREEN")
        .setAuthor(`This verification becomes invalid after 30s.`)
        .setDescription(`Do you want to kick ${kUser}?`)

    // Send the msg
    msg.channel.send(promptEmbed).then(async msg => {
        // Await the reactions and the reaction collector
        const emoji = await promptmsg(msg, msg.author, 30, ["✅", "❌"]);

        // The verification stuffs
        if (emoji === "✅") {
            msg.delete();

            kUser.kick(args.slice(1).join(" "))
                .catch(err => {
                    if (err) return msg.channel.send(`Well.... the kick didn't work out. Here's the error ${err}`)
                });

        } else if (emoji === "❌") {
            msg.delete();

            msg.reply(`Kick canceled.`)
                .then(m => m.delete(10000));
        }
    });
}
};


问题可能在KICK.JS文件中,我在该文件中检查此人是否可以被踢,但我无法找出原因

谢谢

我可以在这里看到:

var kUser=msg.indications.users.first()| | msg.guild.members.get(args[0]);
您有时会使用用户定义
kUser
变量

var kUser=msg.indications.users.first()//返回一个用户对象
有时与成员一起

var kUser=msg.guild.members.get(args[0])//返回一个成员对象
但是,kickable属性仅在成员对象上可用。您可以通过编辑以下行轻松修复它:

var kUser=msg.indications.members.first()| | msg.guild.members.get(args[0]);

在所有情况下,它都将返回一个成员对象。(您还应该使用
kMember
重命名变量)

即使bot在上面,也可能是由bot权限引起的。您确定bot是admin吗?bot被设置为admin。

const fs = require('fs');
const Discord = require("discord.js");
const client = new Discord.Client();

const {prefix, token} = require("./config/dependencies.json");

client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

client.once('ready', () => {
    console.log(`${client.user.username} is ready!`);
    client.user.setActivity("m!", { type: 'LISTENING' })
});

client.on('message', msg => {

    if (!msg.content.startsWith(prefix) || msg.author.bot) return;

    const args = msg.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if (!client.commands.has(command)) return;

    try {
        client.commands.get(command).execute(Discord, client, msg, args);
    } catch (error) {
        console.error(error);
        msg.reply(`That command does not exist ErrorID : &${Math.ceil(Math.random() * 10)}SE`);
}

});


client.login(token);