Better argument type handing

This commit is contained in:
entar 2025-05-21 12:21:04 +07:00
parent fba3f26f57
commit dbc45d4a42
3 changed files with 24 additions and 10 deletions

View File

@ -24,6 +24,15 @@ module.exports = [
if (command.hide) { if (command.hide) {
return // Go to next command if this one shouldnt show up return // Go to next command if this one shouldnt show up
} }
const arguments = command.arguments.slice()
arguments.forEach((argument, index) => {
if (typeof argument == "object") {
arguments[index] = argument.prototype.name
}
})
const field = {name: command.name, value: `Description: ${command.description || "None"}\nArguments: ${command.arguments || "None"}`} const field = {name: command.name, value: `Description: ${command.description || "None"}\nArguments: ${command.arguments || "None"}`}
embed.addFields(field) embed.addFields(field)
}) })

View File

@ -5,7 +5,7 @@ module.exports = [
{ {
name: "helptest", name: "helptest",
description: "Kill every1", description: "Kill every1",
arguments: [GuildMember.name, GuildChannel.name], arguments: [GuildMember, GuildChannel],
run: (ctx, member, channel) => { run: (ctx, member, channel) => {
if (!member || !(member instanceof GuildMember) ) { if (!member || !(member instanceof GuildMember) ) {
return ctx.reply("Member invalid.") return ctx.reply("Member invalid.")

View File

@ -79,6 +79,15 @@ client.on("messageCreate", (message) => {
// Getting command name // Getting command name
const command = parsed[0] const command = parsed[0]
// Actual command
const realCommand = getCommand(command)
// Only continue if command exists
if (!realCommand) {
return
}
// Removing command from the args // Removing command from the args
const args = parsed.filter(value => {return value != command}) const args = parsed.filter(value => {return value != command})
@ -103,16 +112,12 @@ client.on("messageCreate", (message) => {
args[index] = channel args[index] = channel
} }
} }
if (typeof args[index] != typeof realCommand.arguments[index] || !(args[index] instanceof realCommand.arguments[index])) {
return message.reply(`Argument ${index} of wrong type`)
}
}) })
// Actual command
const realCommand = getCommand(command)
// Only continue if command exists
if (!realCommand) {
return
}
// Run command // Run command
realCommand.run(message, ...args) realCommand.run(message, ...args)
//...args passes it as separate args rather than an Array //...args passes it as separate args rather than an Array