TypeError: Class extends value Command is not a constructor or null - node.js(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TypeError:类扩展值命令不是构造函数或 null - node
基础教程推荐
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01