diff --git a/commands/base.js b/commands/base.js index 3365c9b..33f7c8a 100644 --- a/commands/base.js +++ b/commands/base.js @@ -29,14 +29,11 @@ module.exports = [ if (arguments) { arguments.forEach((argument, index) => { - console.log(typeof argument) if (typeof argument == "object" || typeof argument == "function") { arguments[index] = argument.name } }) } - - console.log(arguments) const field = {name: command.name, value: `Description: ${command.description || "None"}\nArguments: ${arguments || "None"}`} embed.addFields(field) diff --git a/index.js b/index.js index cf87b02..49ed244 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ // Base requires -const { Client, GatewayIntentBits, Events } = require("discord.js") +const { Client, GatewayIntentBits, Events, ApplicationCommandPermissionType } = require("discord.js") const fs = require("fs") +const { type } = require("os") // TOKEN is stored in the .env file (node --env-file=.env index.js) const token = process.env.TOKEN @@ -87,41 +88,67 @@ client.on("messageCreate", (message) => { if (!realCommand) { return } - - // Removing command from the args - const args = parsed.filter(value => {return value != command}) - // Parsing - args.forEach((arg, index) => { - if (arg.startsWith("<@")) { - // User, lets get the id - const id = arg.slice(2, arg.length - 1) + if (!realCommand.arguments) { + // No arguments so no need to parse them + // Run command with no args + realCommand.run(message) + } else { + // Removing command from the args + const args = parsed.filter(value => {return value != command}) - const member = message.guild.members.cache.find(member => member.user.id == id) + if (args.length < realCommand.arguments.length) { + const missing = realCommand.arguments.slice(realCommand.arguments.length - args.length) + missing.forEach((argument, index) => { + if (typeof argument == "object" || typeof argument == "function") { + missing[index] = argument.name + } + }) - if (member) { - args[index] = member + return message.reply(`Missing arguments ${missing}`) + } + + var wrongArg = false + + // Parsing + args.forEach((arg, index) => { + if (arg.startsWith("<@")) { + // User, lets get the id + const id = arg.slice(2, arg.length - 1) + + const member = message.guild.members.cache.find(member => member.user.id == id) + + if (member) { + args[index] = member + } + } else if (arg.startsWith("<#")) { + // Channel, lets get the id + const id = arg.slice(2, arg.length - 1) + + const channel = message.guild.channels.cache.find(channel => channel.id == id) + + if (channel) { + args[index] = channel + } } - } else if (arg.startsWith("<#")) { - // Channel, lets get the id - const id = arg.slice(2, arg.length - 1) - const channel = message.guild.channels.cache.find(channel => channel.id == id) - - if (channel) { - args[index] = channel + // Checks if the type is wrong + if (typeof args[index] != typeof realCommand.arguments[index] && !(args[index] instanceof realCommand.arguments[index])) { + wrongArg = true // So it cant continue + return message.reply(`Argument ${index} supposed to be ${realCommand.arguments[index].name}`) } + }) + + if (wrongArg) { + 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) + //...args passes it as separate args rather than an Array } - }) - - // Run command - realCommand.run(message, ...args) - //...args passes it as separate args rather than an Array -}) + } +) // After getting the command list we can export it module.exports.commands = commands diff --git a/package-lock.json b/package-lock.json index fafa074..b5e1f31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "dependencies": { "discord.js": "^14.19.3" - } + }, + "devDependencies": {} }, "node_modules/@discordjs/builders": { "version": "1.11.2",