diff --git a/commands/base.js b/commands/base.js index 0319a3f..1133ca0 100644 --- a/commands/base.js +++ b/commands/base.js @@ -1,44 +1,61 @@ -const {client, commands} = require("../index") -const { EmbedBuilder, Message, Colors } = require("discord.js") +const { commands } = require("../index") +const { EmbedBuilder, Colors } = require("discord.js") module.exports.commands = [ { name: "ping", - run: (ctx, args) => { - ctx.reply(`Pong! ${args}`) + run: (ctx) => { + ctx.reply(`Pong!`) }, hide: false, - arguments: ["any"], description: "Check how fast bot will reply!" }, - { name: "help", - run: (ctx, args) => { + run: (ctx) => { + // Constructing the embed const embed = new EmbedBuilder() - .setAuthor({name: ctx.author.username, iconURL: ctx.author.avatarURL(), url: "https://git.squog.ru/entar/SquogAdmin"}) + // Setting author to the user + .setAuthor({ + name: ctx.author.username, + iconURL: ctx.author.avatarURL(), + url: "https://git.squog.ru/entar/SquogAdmin" + }) + // Setting color to white, obviously. .setColor(Colors.White) - + + // Going over all command lists commands.forEach(commandList => { + // Going over all commands commandList.forEach(command => { if (command.hide) { - return // Go to next command if this one shouldnt show up + return // Go to the next command if this one shouldn't show up } const arguments = command.arguments && command.arguments.slice() - + + // Changing if (arguments) { arguments.forEach((argument, index) => { if (typeof argument == "object" || typeof argument == "function") { arguments[index] = argument.name + } else { + arguments[index] = typeof argument } }) } - - const field = {name: command.name, value: `Description: ${command.description || "None"}\nArguments: ${arguments || "None"}`} - embed.addFields(field) + + // Making a field out of command info + const field = { + name: command.name, + value: `Description: ${command.description || "None"}\nArguments: ${arguments || "None"}` + } + + embed.addFields(field) // Jetbrains doesn't like this because it's not "any" for some reason? }) }) + + // Sending the constructed message ctx.reply({embeds: [embed]}) }, hide: true, diff --git a/commands/fun.js b/commands/fun.js index 5a3d05c..3ebd9ce 100644 --- a/commands/fun.js +++ b/commands/fun.js @@ -1,5 +1,5 @@ -const { GuildMember, Message } = require('discord.js') -const {client, dir} = require('../index') +const { GuildMember } = require('discord.js') +const { dir } = require('../index') module.exports.commands = [ { diff --git a/index.js b/index.js index c007561..023f313 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,6 @@ // Base requires -const { Client, GatewayIntentBits, Events, ApplicationCommandPermissionType } = require("discord.js") +const { Client, GatewayIntentBits } = require("discord.js") const fs = require("fs") -const { type } = require("os") -const { parse } = require("path") -const types = require("util/types") // TOKEN is stored in the .env file (node --env-file=.env index.js) const token = process.env.TOKEN @@ -52,10 +49,10 @@ fs.readdir(`${__dirname}/commands`, (err, files) => { // Function to get the command with that name function getCommand(commandName) { - var command; + let command; commands.forEach(commandList => { commandList.forEach(commandArray => { - if (commandArray.name == commandName) { + if (commandArray.name === commandName) { command = commandArray } }) @@ -63,9 +60,9 @@ function getCommand(commandName) { return command; } -// Parsing commands on message create +// Parsing commands on message creation client.on("messageCreate", async (message) => { - var content = message.content + let content = message.content // Continue only if starts with the prefix if (!content.startsWith('!')) { @@ -85,22 +82,22 @@ client.on("messageCreate", async (message) => { const realCommand = getCommand(command) - // Only continue if command exists + // Only continue if the command exists if (!realCommand) { return } if (!realCommand.arguments) { - // No arguments so no need to parse them + // No arguments, so no need to parse them // Run command with no args - if (realCommand.run.constructor.name == "AsyncFunction"){ + if (realCommand.run.constructor.name === "AsyncFunction"){ await realCommand.run(message) } else { realCommand.run(message) } } else { // Removing command from the args - const args = parsed.filter(value => {return value != command}) + const args = parsed.filter(value => {return value !== command}) if (args.length < realCommand.arguments.length) { const missing = realCommand.arguments.slice(realCommand.arguments.length - args.length) @@ -112,8 +109,8 @@ client.on("messageCreate", async (message) => { return message.reply(`Missing arguments ${missing}`) } - - var wrongArg = false + + let wrongArg = false // Parsing args.forEach((arg, index) => { @@ -122,7 +119,7 @@ client.on("messageCreate", async (message) => { // 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) + const member = message.guild.members.cache.find(member => member.user.id === id) if (member) { args[index] = member @@ -131,20 +128,20 @@ client.on("messageCreate", async (message) => { // Channel, lets get the id const id = arg.slice(2, arg.length - 1) - const channel = message.guild.channels.cache.find(channel => channel.id == id) + const channel = message.guild.channels.cache.find(channel => channel.id === id) if (channel) { args[index] = channel } } else if (Number(arg)) { args[index] = Number(arg) - } else if (arg == "true" || arg == "false") { - args[index] = arg == "true" // This is awful man. + } else if (arg === "true" || arg === "false") { + args[index] = arg === "true" // This is awful, man. } // 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 + if (typeof args[index] !== typeof realCommand.arguments[index] && !(args[index] instanceof realCommand.arguments[index])) { + wrongArg = true // So it can't continue return message.reply(`Argument ${index} supposed to be ${realCommand.arguments[index].name}`) } }) @@ -154,7 +151,7 @@ client.on("messageCreate", async (message) => { } // Run command - if (realCommand.run.constructor.name == "AsyncFunction"){ + if (realCommand.run.constructor.name === "AsyncFunction"){ await realCommand.run(message, ...args) } else { realCommand.run(message, ...args) @@ -168,7 +165,7 @@ client.on("messageCreate", async (message) => { Command preset: -module.exports.commands = [ //module.exports.commands exports ONLY COMMANDLISTS. +module.exports.commands = [ //module.exports.commands exports ONLY COMMAND LISTS. { name: "name", // !name @@ -184,8 +181,12 @@ module.exports.commands = [ //module.exports.commands exports ONLY COMMANDLISTS. */ -// After getting the command list we can export it +// After getting the command list, we can export it module.exports.commands = commands -// Time to login -client.login(token) \ No newline at end of file +// Time to log in +client.login(token).then(logged => { + if (!logged) { + return console.error("Couldn't login.") + } +}) \ No newline at end of file