clean up: fs.promises api and reformat
This commit is contained in:
parent
fdedb50bc5
commit
46e938946c
21
index.js
21
index.js
@ -1,13 +1,11 @@
|
|||||||
import { Client, Collection, GatewayIntentBits } from 'discord.js';
|
import { Client, Collection, GatewayIntentBits } from 'discord.js';
|
||||||
|
import { readdir, stat } from 'fs/promises';
|
||||||
|
import { Partials } from 'discord.js';
|
||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { promisify } from 'util';
|
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
import { readdir } from 'fs';
|
|
||||||
import { Partials } from 'discord.js';
|
|
||||||
|
|
||||||
config();
|
config();
|
||||||
const readdirAsync = promisify(readdir);
|
|
||||||
|
|
||||||
const required = ['data', 'execute'];
|
const required = ['data', 'execute'];
|
||||||
const optional = ['autocomplete', 'modalSubmit'];
|
const optional = ['autocomplete', 'modalSubmit'];
|
||||||
@ -39,14 +37,13 @@ const runClient = (commands, events) => {
|
|||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
const cmdPath = join(__dirname, 'commands');
|
const cmdPath = join(__dirname, 'commands');
|
||||||
const evtPath = join(__dirname, 'events');
|
const evtPath = join(__dirname, 'events');
|
||||||
readdirAsync(cmdPath)
|
readdir(cmdPath)
|
||||||
.then(
|
.then(async (categories) =>
|
||||||
async (categories) =>
|
|
||||||
// For each category directory
|
// For each category directory
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
categories.map(async (category) => {
|
categories.map(async (category) => {
|
||||||
const catPath = join(cmdPath, category);
|
const catPath = join(cmdPath, category);
|
||||||
const content = await readdirAsync(catPath);
|
const content = await readdir(catPath);
|
||||||
const files = content.filter((file) => file.endsWith('.js') && !file.endsWith('.example.js'));
|
const files = content.filter((file) => file.endsWith('.js') && !file.endsWith('.example.js'));
|
||||||
// For each command file
|
// For each command file
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
@ -73,10 +70,10 @@ readdirAsync(cmdPath)
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
)
|
).then((commands) =>
|
||||||
.then((commands) => commands.reduce((a, i) => a.concat(i), []).filter((e) => e !== 0))
|
commands.reduce((a, i) => a.concat(i), []).filter((e) => e !== 0)
|
||||||
.then(async (commands) => {
|
).then(async (commands) => {
|
||||||
const content = await readdirAsync(evtPath);
|
const content = await readdir(evtPath);
|
||||||
const files = content.filter((file) => file.endsWith('.js'));
|
const files = content.filter((file) => file.endsWith('.js'));
|
||||||
const events = await Promise.all(
|
const events = await Promise.all(
|
||||||
files.map(async (current) => {
|
files.map(async (current) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user