我尝试发出 !warn
命令,以便我可以警告我服务器中的人,如果您有 2 个警告,您将被静音等。
当我完成时,只剩下 1 个错误。我尝试了很多东西,但我就是想不通,每一个帮助都会很棒。
完全错误:
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
代码:
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;
如果有人能帮我解决这个问题,那就太棒了。 同样让我吃惊的一件事是,当我把这段代码放到 Visual Studio Code 中时,没有任何错误,但是当我把它放到 glitch.com 中时,却出现了这个错误。
答案 0 :(得分:0)
应该是class Warn extends Command
,而不是class Warn extends ("Command")
。我认为,您尝试从 Discord.js Commando 扩展 Command
类。
你只能扩展类,不能扩展字符串。
此外,请确保在文件中导入类:
const { Command } = require('discord.js-commando');
const ms = require("ms");
class Warn extends Command {
constructor(client) {
super(client, {
name: "warn",
...