【问题标题】:When I try to kick someone on Discord using bot I get an error当我尝试使用机器人在 Discord 上踢某人时,出现错误
【发布时间】:2022-01-12 01:33:55
【问题描述】:

当我尝试使用机器人踢某人时,我让它不断出错。我按照 CodeLyons 关于禁止和踢球的教程进行操作。这是他的 2020 年不和谐机器人播放列表。这是不断出现的错误:

(node:5108) DeprecationWarning:消息事件已被弃用。改用 messageCreate (使用node --trace-deprecation ... 显示警告的创建位置) /home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/rest/RequestHandler.js:350 抛出新的 DiscordAPIError(data, res.status, request); ^

DiscordAPIError:缺少权限 在 RequestHandler.execute (/home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/rest/RequestHandler.js:350:13) 在 processTicksAndRejections (节点:internal/process/task_queues:96:5) 在异步 RequestHandler.push (/home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/rest/RequestHandler.js:51:14) 在异步 GuildMemberManager.kick (/home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/managers/GuildMemberManager.js:363:5) { 方法:'删除', 路径:'/guilds/927169002294345758/members/895937895456735233', 代码:50013, http状态:403, requestData:{ json:未定义,文件:[] } }

我的代码:

main.js:

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

const prefix = '!';

const client = new Discord.Client({
  intents: [ Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES ]
});

const fs = require('fs');

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('Chilly is online!');
});

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 === 'kick') {
        client.commands.get('kick').execute(message, args);
    } else if (command === 'ban') {
        client.commands.get('ban').execute(message, args);
    }
});

client.login('***********************************');

kick.js:

module.exports = {
    name: "kick",
    description: "This command kicks a member!",
    execute(message, args) {
        const member = message.mentions.users.first();
        //if (message.member.roles.cache.has('927171204371079208')) {
            if (member) {
                const memberTarget = message.guild.members.cache.get(member.id);
                memberTarget.kick();
                message.channel.send("User has been kicked");
            } else {
                message.channel.send("You couldn't kick that member");
            }
        //} else {
            //message.channel.send("Sorry you don't have the right permissions to send this message");
        //}
    }
}

额外信息: 库:discord.js nodejs版本:16.13

【问题讨论】:

标签: javascript node.js api discord.js bots


【解决方案1】:

您的代码看起来不错。

该错误表示该机器人没有KICK_MEMBERS 权限,您可以通过授予机器人管理员或KICK_MEMBERS 权限来解决此问题。这也可能意味着机器人无法踢出成员,因为他们是所有者和/或高于机器人角色

【讨论】:

  • 龟爪感谢您的回答。 “这也可能意味着机器人无法踢出成员,因为他们是所有者和/或高于机器人角色”,我注意到我的 alt 帐户具有员工权限(高于机器人)所以当我删除员工时我能够访问我的 alt 帐户!
猜你喜欢
  • 2021-02-24
  • 2021-05-18
  • 2017-07-22
  • 2021-08-10
  • 2019-12-23
  • 2022-01-18
  • 2020-09-22
  • 2022-12-07
  • 2017-10-11
相关资源
最近更新 更多