Moved commends to category folders
This commit is contained in:
parent
a4eab091c7
commit
52de74494d
6 changed files with 40 additions and 46 deletions
|
@ -3,7 +3,7 @@ import { MessageEmbed, MessageActionRow, MessageSelectMenu } from 'discord.js';
|
||||||
import { exec } from 'node:child_process';
|
import { exec } from 'node:child_process';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import utils from '../utils/videos.js';
|
import utils from '../../utils/videos.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
|
@ -5,6 +5,6 @@ export default {
|
||||||
.setName('ping')
|
.setName('ping')
|
||||||
.setDescription('Replies with Pong!'),
|
.setDescription('Replies with Pong!'),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
await interaction.reply('Pong!');
|
await interaction.reply(`Pong! \`${Math.round(interaction.client.ws.ping)} ms\``);
|
||||||
},
|
},
|
||||||
};
|
};
|
|
@ -1,5 +1,5 @@
|
||||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
import utils from '../utils/videos.js';
|
import utils from '../../utils/videos.js';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
@ -55,7 +55,7 @@ export default {
|
||||||
|
|
||||||
async function gifski(output, input) {
|
async function gifski(output, input) {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
exec(`gifski -o ${output} ${input}`, (err, stdout, stderr) => {
|
exec(`gifski --quality 70 -o ${output} ${input}`, (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(stderr);
|
reject(stderr);
|
||||||
}
|
}
|
46
index.js
46
index.js
|
@ -11,9 +11,19 @@ const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||||
|
|
||||||
// Load commands from the commands folder
|
// Load commands
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
const commandsPath = path.join(__dirname, 'commands');
|
await loadCommandFromDir('fun');
|
||||||
|
await loadCommandFromDir('utility');
|
||||||
|
|
||||||
|
// Load events
|
||||||
|
loadEventFromDir('client', client);
|
||||||
|
loadEventFromDir('process', process);
|
||||||
|
|
||||||
|
client.login(token);
|
||||||
|
|
||||||
|
async function loadCommandFromDir(dir) {
|
||||||
|
const commandsPath = path.join(`${__dirname}/commands`, dir);
|
||||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
|
@ -23,37 +33,21 @@ for (const file of commandFiles) {
|
||||||
|
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load client events from the events folder
|
async function loadEventFromDir(dir, listener) {
|
||||||
const clientEventsPath = path.join(__dirname, 'events/client');
|
const eventsPath = path.join(`${__dirname}/events`, dir);
|
||||||
const clientEventFiles = fs.readdirSync(clientEventsPath).filter(file => file.endsWith('.js'));
|
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
for (const file of clientEventFiles) {
|
for (const file of eventFiles) {
|
||||||
const filePath = path.join(clientEventsPath, file);
|
const filePath = path.join(eventsPath, file);
|
||||||
let event = await import(filePath);
|
let event = await import(filePath);
|
||||||
event = event.default;
|
event = event.default;
|
||||||
if (event.once) {
|
if (event.once) {
|
||||||
client.once(event.name, (...args) => event.execute(...args));
|
listener.once(event.name, (...args) => event.execute(...args));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
client.on(event.name, (...args) => event.execute(...args));
|
listener.on(event.name, (...args) => event.execute(...args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load process events from the events folder
|
|
||||||
const processEventsPath = path.join(__dirname, 'events/process');
|
|
||||||
const processEventFiles = fs.readdirSync(processEventsPath).filter(file => file.endsWith('.js'));
|
|
||||||
|
|
||||||
for (const file of processEventFiles) {
|
|
||||||
const filePath = path.join(processEventsPath, file);
|
|
||||||
let event = await import(filePath);
|
|
||||||
event = event.default;
|
|
||||||
if (event.once) {
|
|
||||||
process.once(event.name, (...args) => event.execute(...args));
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
process.on(event.name, (...args) => event.execute(...args));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
client.login(token);
|
|
||||||
|
|
Loading…
Reference in a new issue