简体   繁体   English

我的 discord 机器人不响应踢命令

[英]My discord bot doesn't respond for kick command

I want to make the gif reactions sent randomly when I use command kick but my bot doesn't respond, also there are no errors in the terminal.我想在使用命令踢时随机发送gif 反应,但我的机器人没有响应,终端中也没有错误。

This is a picture of the path:这是路径的图片:
小路

kick.js file: kick.js 文件:

const Discord = require('discord.js');
const fs = require('fs');

module.exports = {
    name: 'kick',
    description: 'Kicks A User.',
    execute(message, args) {
        const { Permissions } = require('discord.js');
        let randomNumber = (Math.floor(Math.random() * 12) + 1);
        const member = message.mentions.members.first();
        fs.readdir('./kickgifs', (err, files) => {
            if(err) return console.log(err);
        let embed = new Discord.MessageEmbed()
            .setColor(000000)
            .setImage(`${randomNumber}.gif`)
            if (!member) return message.channel.send("Invalid Member Given!");
            if (member.roles.highest.position > message.member.roles.highest.positon) return message.channel.send("This user is a higher role than you!");
            let reason = args.slice(1).join(" ");
            if (!reason) reason = "No Reason Provided!";
        member.kick()
            .catch(console.log)
        message.channel.send({ embeds: [embed.setDescription(`<@${member.user.id}> Has Been **Kicked** By **${message.author.username}**`)] })
        });
    }
}

index.js file: index.js 文件:

const { Intents, Client, MessageEmbed, Attachment, DiscordAPIError, Collection } = require('discord.js'); // require other classes as per your bot needs
const intents = [Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]; // Add other related intents
const client = new Client({ intents: intents });

const prefix = '!';

var version = '1.0.1';

const targetChannelId = '799206261978693634' // Channel for rules

const welcomeChannelId = '798928691988004897' // Channel for welcome message

const fs = require('fs');

client.commands = new 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('Baji is online.');
    setInterval(() => {
        const statuses = [
            `!help | ♡`,
            `Your Home`,
        ]

        const status = statuses[Math.floor(Math.random() * statuses.length)]
        client.user.setActivity(status, { type: "WATCHING" }) // Can Be WATCHING, STREAMING, LISTENING
    }, 2000) // Second You Want to Change Status, This Cahnges Every 2 Seconds    
});


client.on('guildMemberAdd', (member) => {
    console.log(member)
    const channel = member.guild.channels.cache.get(welcomeChannelId)
    const embed = new MessageEmbed()
        .setColor('#000000')
        .setTitle(`Welcome To ${member.guild.name}`)
        .setDescription(`Hello <@${member.user.id}> Make sure to check out the ${member.guild.channels.cache.get(targetChannelId).toString()} in order to keep this server nice and safe! We hope you enjoy your stay!`)
        .setThumbnail(member.user.displayAvatarURL({ dynamic: true, size: 512 }))
        .setFooter(`From the love of ${member.guild.name}`)
    channel.send({ embeds: [embed] });
});

client.on('message', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

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

    if (command === 'ping') {
        client.commands.get('ping').execute(message, args);
    } else if (command == 'website') {
        client.commands.get('website').execute(message, args);
    } else if (command == 'clear') {
        client.commands.get('clear').execute(message, args);
    } else if (command == 'kick') {
        client.commands.get('kick').execute(message, args);
    } else if (command == 'ban') {
        client.commands.get('ban').execute(message, args);
    }

    switch (args[0]) {
        case 'profile':
            const embed = new MessageEmbed()
                .setTitle('User Information')
                .addField('User Name', message.author.username)
                .addField('Version ', version)
                .addField('Current Server', message.guild.name)
                .setColor(000000)
                .setFooter('jajaja')
                .setThumbnail(message.author.displayAvatarURL())
            message.channel.send({ embeds: [embed] });
            break;
        case 'hello':
            const embed1 = new MessageEmbed()
            .setDescription(`<@${member.user.id}> is greeting Everone!`)
            .setColor(000000)
            message.channel.send({ embeds: [embed1] });
            break;

        case 'info':
            if (args[1] === 'version') {
                message.channel.send('Version ' + version);
            } else {
                message.channel.send('Invalid Args')
            }
            break;
    }
})

client.login('TOKEN');

Additionally, the profile, info, and hello commands don't work either.此外,profile、info 和 hello 命令也不起作用。

I assume your commands are not working because of your handler, you can try changing it to mine.我假设你的命令因为你的处理程序而不起作用,你可以尝试将它更改为我的。 (Please note you will need to download ascii-table module: npm i ascii-table ) (请注意,您需要下载 ascii-table 模块: npm i ascii-table

index.js索引.js

client.commands = new Collection();
client.name = new Collection();

["command"].forEach(handler => {
    require(`./handler/${handler}`)(client);
})

client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if (cmd.length === 0) return;

let command = client.commands.get(client.name.get(cmd));

if (command) command.run(message, args);
})

./handler/command.js ./handler/command.js

const { readdirSync } = require("fs");

const ascii = require("ascii-table");

// Create a new Ascii table
let table = new ascii("Commands");
table.setHeading("Command", "Load status");

module.exports = (client) => {
    readdirSync("./commands/").forEach(dir => {
        // Filter so we only have .js command files
        const commands = readdirSync(`./commands/`).filter(file => file.endsWith(".js"));
    
        // Loop over the commands, and add all of them to a collection
        // If there's no name found, prevent it from returning an error
        for (let file of commands) {
            let pull = require(`../commands/${file}`);
    
            if (pull.name) {
                client.commands.set(pull.name, pull);
                table.addRow(file, '✅');
            } else {
                table.addRow(file, `❌  -> missing a help.name, or help.name is not a string.`);
                continue;
            }
    
            // If there's an aliases key, read the aliases.
            if (pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach(alias => robot.aliases.set(alias, pull.name));
        }
    });
    // Log the table
    console.log(table.toString());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM