Better argument type handing
This commit is contained in:
parent
fba3f26f57
commit
dbc45d4a42
@ -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)
|
||||
})
|
||||
|
@ -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.")
|
||||
|
21
index.js
21
index.js
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user