Discord bot不会运行看似正确的代码

时间:2020-09-27 08:50:40

标签: javascript node.js discord discord.js

因此,我正在为我的不和谐机器人编写unban脚本-仅使用此命令时,它会不断抛出错误-对我和我的伴侣看来正确,有什么我在忽略的东西吗?

const discord = require("discord.js");
module.exports = {
    name: 'unban',
    category: 'moderation',
    description: 'unban a members',
    aliases: [''],
    run: async (message, client, args) => {



        let unbanned = message.mentions.users.first() || client.users.resolve(args[0]);
        let reason = args.slice(1).join(" ");

        let member = await client.users.fetch(unbanned);
        let ban = await message.guild.fetchBans();

        // MESSAGES

        if (!unbanned) {
            let unbaninfoembed = new Discord.MessageEmbed()
                .setTitle("Command: unban")
                .setDescription(
                    `**Description:** Unban a user. \n` +
                    "**Sub Commands:**\n" +
                    "" +
                    "**Usage:**\n" +
                    "-unban [user] (limit) (reason) \n" +
                    "**Examples:** \n" +
                    "-unban <@759175803409530932> good guy \n" +
                    "-unban 759175803409530932 good guy "
                )
                .setColor("#2C2F33");
            message.channel.send(unbaninfoembed);

            return;
        }

        if (!ban.get(member.id)) {
            let notbannedembed = new Discord.MessageEmbed()
                .setDescription("This user is not banned")
                .setColor("#2C2F33");
            message.channel.send(notbannedembed);

            return;
        }

        if (!message.guild.me.permissions.has("BAN_MEMBERS")) {
            let botnoperms = new Discord.MessageEmbed()
                .setDescription(
                    "I do not have permissions, please contact an administrator"
                )
                .setColor("#2C2F33");
            message.channel.send(botnoperms);

            return;
        }

        if (!message.member.permission.has("BAN_MEMBERS")) {
            let nopermsembed = new Discord.MessageEmbed()
                .setDescription(
                    "You do not have permission `BAN MEMBERS` contact an administrator"
                )
                .setColor("#2C2F33");
            message.channel.send(nopermsembed);

            return;
        }

        var user = ban.get(member.id);
        message.guild.members.unban(member);
        let successfullyembed = new Discord.MessageEmbed()
            .setTitle(`Successfully Unbaned!`)
            .setDescription(`${member.tag} has been successfully unbanned`)
            .addField(`Reason: ${reason}`)
            .setColor("#2C2F33");

        message.channel.send(successfullyembed);
    },
};

给出错误:

UnhandledPromiseRejectionWarning: DiscordAPIError: 404: Not Found
        at RequestHandler.execute (E:\Lyckas\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)
    (Use `node --trace-warnings ...` to show where the warning was created)
    (node:17316) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
    (node:17316) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

1 个答案:

答案 0 :(得分:0)

最近Discord已将主网站从“ discordapp.com”更改为“ discord.com”,尝试重新安装discord.js模块,看看是否有帮助。