More comments, typo fixes and changes of "var" to "let"

This commit is contained in:
Entarno54 2025-05-24 05:02:46 +07:00
parent 5d6103a0aa
commit f705fa387f
3 changed files with 59 additions and 41 deletions

View File

@ -1,44 +1,61 @@
const {client, commands} = require("../index") const { commands } = require("../index")
const { EmbedBuilder, Message, Colors } = require("discord.js") const { EmbedBuilder, Colors } = require("discord.js")
module.exports.commands = [ module.exports.commands = [
{ {
name: "ping", name: "ping",
run: (ctx, args) => { run: (ctx) => {
ctx.reply(`Pong! ${args}`) ctx.reply(`Pong!`)
}, },
hide: false, hide: false,
arguments: ["any"],
description: "Check how fast bot will reply!" description: "Check how fast bot will reply!"
}, },
{ {
name: "help", name: "help",
run: (ctx, args) => { run: (ctx) => {
// Constructing the embed
const embed = new EmbedBuilder() 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) .setColor(Colors.White)
// Going over all command lists
commands.forEach(commandList => { commands.forEach(commandList => {
// Going over all commands
commandList.forEach(command => { commandList.forEach(command => {
if (command.hide) { 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() const arguments = command.arguments && command.arguments.slice()
// Changing
if (arguments) { if (arguments) {
arguments.forEach((argument, index) => { arguments.forEach((argument, index) => {
if (typeof argument == "object" || typeof argument == "function") { if (typeof argument == "object" || typeof argument == "function") {
arguments[index] = argument.name arguments[index] = argument.name
} else {
arguments[index] = typeof argument
} }
}) })
} }
const field = {name: command.name, value: `Description: ${command.description || "None"}\nArguments: ${arguments || "None"}`} // Making a field out of command info
embed.addFields(field) 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]}) ctx.reply({embeds: [embed]})
}, },
hide: true, hide: true,

View File

@ -1,5 +1,5 @@
const { GuildMember, Message } = require('discord.js') const { GuildMember } = require('discord.js')
const {client, dir} = require('../index') const { dir } = require('../index')
module.exports.commands = [ module.exports.commands = [
{ {

View File

@ -1,9 +1,6 @@
// Base requires // Base requires
const { Client, GatewayIntentBits, Events, ApplicationCommandPermissionType } = require("discord.js") const { Client, GatewayIntentBits } = require("discord.js")
const fs = require("fs") 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) // TOKEN is stored in the .env file (node --env-file=.env index.js)
const token = process.env.TOKEN const token = process.env.TOKEN
@ -52,10 +49,10 @@ fs.readdir(`${__dirname}/commands`, (err, files) => {
// Function to get the command with that name // Function to get the command with that name
function getCommand(commandName) { function getCommand(commandName) {
var command; let command;
commands.forEach(commandList => { commands.forEach(commandList => {
commandList.forEach(commandArray => { commandList.forEach(commandArray => {
if (commandArray.name == commandName) { if (commandArray.name === commandName) {
command = commandArray command = commandArray
} }
}) })
@ -63,9 +60,9 @@ function getCommand(commandName) {
return command; return command;
} }
// Parsing commands on message create // Parsing commands on message creation
client.on("messageCreate", async (message) => { client.on("messageCreate", async (message) => {
var content = message.content let content = message.content
// Continue only if starts with the prefix // Continue only if starts with the prefix
if (!content.startsWith('!')) { if (!content.startsWith('!')) {
@ -85,22 +82,22 @@ client.on("messageCreate", async (message) => {
const realCommand = getCommand(command) const realCommand = getCommand(command)
// Only continue if command exists // Only continue if the command exists
if (!realCommand) { if (!realCommand) {
return return
} }
if (!realCommand.arguments) { if (!realCommand.arguments) {
// No arguments so no need to parse them // No arguments, so no need to parse them
// Run command with no args // Run command with no args
if (realCommand.run.constructor.name == "AsyncFunction"){ if (realCommand.run.constructor.name === "AsyncFunction"){
await realCommand.run(message) await realCommand.run(message)
} else { } else {
realCommand.run(message) realCommand.run(message)
} }
} else { } else {
// 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})
if (args.length < realCommand.arguments.length) { if (args.length < realCommand.arguments.length) {
const missing = realCommand.arguments.slice(realCommand.arguments.length - args.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}`) return message.reply(`Missing arguments ${missing}`)
} }
var wrongArg = false let wrongArg = false
// Parsing // Parsing
args.forEach((arg, index) => { args.forEach((arg, index) => {
@ -122,7 +119,7 @@ client.on("messageCreate", async (message) => {
// User, lets get the id // User, lets get the id
const id = arg.slice(2, arg.length - 1) 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) { if (member) {
args[index] = member args[index] = member
@ -131,20 +128,20 @@ client.on("messageCreate", async (message) => {
// Channel, lets get the id // Channel, lets get the id
const id = arg.slice(2, arg.length - 1) 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) { if (channel) {
args[index] = channel args[index] = channel
} }
} else if (Number(arg)) { } else if (Number(arg)) {
args[index] = Number(arg) args[index] = Number(arg)
} else if (arg == "true" || arg == "false") { } else if (arg === "true" || arg === "false") {
args[index] = arg == "true" // This is awful man. args[index] = arg === "true" // This is awful, man.
} }
// Checks if the type is wrong // Checks if the type is wrong
if (typeof args[index] != typeof realCommand.arguments[index] && !(args[index] instanceof realCommand.arguments[index])) { if (typeof args[index] !== typeof realCommand.arguments[index] && !(args[index] instanceof realCommand.arguments[index])) {
wrongArg = true // So it cant continue wrongArg = true // So it can't continue
return message.reply(`Argument ${index} supposed to be ${realCommand.arguments[index].name}`) return message.reply(`Argument ${index} supposed to be ${realCommand.arguments[index].name}`)
} }
}) })
@ -154,7 +151,7 @@ client.on("messageCreate", async (message) => {
} }
// Run command // Run command
if (realCommand.run.constructor.name == "AsyncFunction"){ if (realCommand.run.constructor.name === "AsyncFunction"){
await realCommand.run(message, ...args) await realCommand.run(message, ...args)
} else { } else {
realCommand.run(message, ...args) realCommand.run(message, ...args)
@ -168,7 +165,7 @@ client.on("messageCreate", async (message) => {
Command preset: Command preset:
module.exports.commands = [ //module.exports.commands exports ONLY COMMANDLISTS. module.exports.commands = [ //module.exports.commands exports ONLY COMMAND LISTS.
{ {
name: "name", // !name 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 module.exports.commands = commands
// Time to login // Time to log in
client.login(token) client.login(token).then(logged => {
if (!logged) {
return console.error("Couldn't login.")
}
})