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

@ -11,7 +11,7 @@ module.exports = [
arguments: ["any"],
description: "Check how fast bot will reply!"
},
{
name: "help",
run: (ctx, args) => {
@ -24,6 +24,15 @@ module.exports = [
if (command.hide) {
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"}`}
embed.addFields(field)
})

View File

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

View File

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