类扩展值命令不是构造函数或

类扩展值命令不是构造函数或

本文介绍了TypeError:类扩展值命令不是构造函数或 null - node.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I tried to make a !warn command, so that I can warn people in my server and if you have 2 warns you get a mute etc.

When I was done there was only 1 error left. I tried many things, but I just can't figure it out, every help would be awesome.

Full error:

 TypeError: Class extends value Command is not a constructor or null
   at Object.<anonymous> (/app/server.js:297:12)
   at Module._compile (internal/modules/cjs/loader.js:759:30)
   at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
   at Module.load (internal/modules/cjs/loader.js:628:32)
   at Function.Module._load (internal/modules/cjs/loader.js:555:12)
   at Function.Module.runMain (internal/modules/cjs/loader.js:826:10)
   at internal/main/run_main_module.js:17:11

Code:

const ms = require("ms");

class Warn extends ("Command") {
constructor(client) {
    super(client, {
        name: "warn",
        description: "Command om een gebruiker te waarschuwen",
        usage: "warn",
        category: "System",
        permLevel: "Moderator"
    });
}

async run(message, args) {
try {
    const warnedUser = message.guild.member(
        message.mentions.users.first() || message.guild.members.get(args[0])
    );
    if (!warnedUser) return message.channel.send("Deze gebruiker bestaat niet");

    const warnToAdd = 1;
    const warnToDel = 4;
    const reason = args.join(" ").slice(22);

    this.client.warns.ensure(`${warnedUser.id}`, {
        warnings: 0
    });

    let userWarnings = this.client.warns.get(`${warnedUser.id}`, "warnings");
    userWarnings += warnToAdd;

    this.client.warns.set(`${warnedUser.id}`, userWarnings, "warnings");

    message.delete();

    if (this.client.warns.get(`${warnedUser.id}`, "warnings") == 1) {
        message.channel.send(`${warnedUser}, eerste waarschuwing (reden: ${reason})`);
    } else if (this.client.warns.get(`${warnedUser.id}`, "warnings") == 2) {
        const muteRole = message.guild.roles.find(x => x.name === "muted");
        if (!muteRole) message.guild.createRole("name", "muted");
        message.channel.send(
            `${warnedUser}, tweede waarschuwing (reden: ${reason})`
        );
        const muteTime = "1h";
        await warnedUser.addRole(muteRole.id);
        message.channel.send(
            `${warnedUser} is gemuted voor ${muteTime} (reden: ${reason})`
        );

        setTimeout(function() {
            warnedUser.removeRole(muteRole.id);
            message.channel.send(`De gebruiker ${warnedUser} is niet meer gemuted!`);
        }, ms(muteTime));

        } else if (this.client.warns.get(`${warnedUser.id}`, "warnings") == 3) {
            message.channel.send(`${warnedUser}, derde waarschuwing (reden: ${reason})`);
            message.channel.send(`:warning: Pas op ${warnedUser}, bij 4 waarschuwingen krijg je een kick`);
        } else if (this.client.warns.get(`${warnedUser.id}`, "warnings") == 4) {
            message.channel.send(`${warnedUser}, vierde waarschuwing, veel plezier met je kick (reden: ${reason})`);
            warnedUser.kick(reason);
            userWarnings -= warnToDel;
        }
    } catch (e) {
        console.log(e);
    }
}
}

module.exports = Warn;

If someone could help me with this it would be amazing.One thing that also surprised me is that when I put this code in Visual Studio Code, there are no errors, but when I put it in glitch.com, this error appears.

解决方案

It should be class Warn extends Command, not class Warn extends ("Command"). I think, you try to extend the Command class from Discord.js Commando.

You can only extend classes, not strings.

Also, make sure you import the class in your file:

const { Command } = require('discord.js-commando');
const ms = require("ms");

class Warn extends Command {
  constructor(client) {
    super(client, {
      name: "warn",
      ...

这篇关于TypeError:类扩展值命令不是构造函数或 null - node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 13:27