Skip to content

Commit d234e85

Browse files
committed
Added Chalk and reload command
1 parent a4b4963 commit d234e85

File tree

7 files changed

+98
-36
lines changed

7 files changed

+98
-36
lines changed

package-lock.json

Lines changed: 36 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"eslint": "^8.27.0"
2222
},
2323
"dependencies": {
24+
"chalk": "^5.1.2",
2425
"discord.js": "^14.6.0",
2526
"fs": "^0.0.1-security"
2627
}

src/commands/reload.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import commandHandler from '../handlers/commands.js';
2+
3+
export default {
4+
name: 'reload',
5+
description: 'Reloads all commands',
6+
aliases: [],
7+
8+
async execute(message, args, client) {
9+
try {
10+
let cmd = await commandHandler.reloadCommands(client);
11+
message.reply(`${cmd} commands have been reloaded!`);
12+
} catch (error) {
13+
console.log(error);
14+
}
15+
}
16+
};

src/events/ready.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import chalk from 'chalk';
2+
import { readFileSync } from 'fs';
3+
let version = JSON.parse(readFileSync('./package.json', 'utf8')).version;
4+
15
export default {
26
event: 'ready',
37
async execute(client) {
48
try {
5-
console.log(`Logged in as ${client.user.tag}`);
9+
console.log(chalk.yellow(`[LOGIN] logged in as ${client.user.tag} -> Version ${version}`));
610
} catch (error) {
711
return console.log(error);
812
}

src/handlers/commands.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
11
import { readdirSync } from 'fs';
2+
import chalk from 'chalk';
23

34
async function loadCommands(client) {
4-
const commandFiles = readdirSync('./src/commands').filter(file => file.endsWith('.js'));
5-
for (let i = 0; i < commandFiles.length; i++) {
6-
const cmd = await import(`../commands/${commandFiles[i]}`);
7-
client.commands.set(cmd.default.name, cmd.default);
5+
const commandFiles = readdirSync('./src/commands').filter(file => file.endsWith('.js'));
6+
for (let i = 0; i < commandFiles.length; i++) {
7+
const cmd = await import(`../commands/${commandFiles[i]}`);
8+
client.commands.set(cmd.default.name, cmd.default);
9+
console.log(chalk.greenBright(`[COMMAND] Loaded ${(chalk.yellow(commandFiles[i]))} with command ${(chalk.yellow(cmd.default.name))} ${(chalk.yellow(`[${cmd.default.aliases}]`))}`));
810

9-
if (cmd.default.aliases) {
10-
cmd.default.aliases.forEach(alias => {
11-
client.aliases.set(alias, cmd.default);
12-
});
13-
};
14-
}
11+
if (cmd.default.aliases) {
12+
cmd.default.aliases.forEach(alias => {
13+
client.aliases.set(alias, cmd.default);
14+
});
15+
}
16+
}
1517
}
1618

17-
export default { loadCommands };
19+
async function reloadCommands(client) {
20+
client.commands.clear();
21+
client.aliases.clear();
22+
const commandFiles = readdirSync('./src/commands').filter(file => file.endsWith('.js'));
23+
for (let i = 0; i < commandFiles.length; i++) {
24+
const cmd = await import(`../commands/${commandFiles[i]}`);
25+
client.commands.set(cmd.default.name, cmd.default);
26+
console.log(chalk.greenBright(`[COMMAND] Reloaded ${(chalk.yellow(commandFiles[i]))} with command ${(chalk.yellow(cmd.default.name))} ${(chalk.yellow(`[${cmd.default.aliases}]`))}`));
27+
28+
if (cmd.default.aliases) {
29+
cmd.default.aliases.forEach(alias => {
30+
client.aliases.set(alias, cmd.default);
31+
});
32+
}
33+
}
34+
return commandFiles.length;
35+
}
36+
37+
export default { loadCommands, reloadCommands };

src/handlers/events.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { readdirSync } from 'fs';
2+
import chalk from 'chalk';
23

34
async function loadEvents(client) {
4-
const eventFiles = readdirSync('./src/events').filter(file => file.endsWith('.js'));
5-
for (let i = 0; i < eventFiles.length; i++) {
6-
const event = await import(`../events/${eventFiles[i]}`);
7-
client.on(event.default.event, event.default.execute.bind(null, client));
8-
}
5+
const eventFiles = readdirSync('./src/events').filter(file => file.endsWith('.js'));
6+
for (let i = 0; i < eventFiles.length; i++) {
7+
const event = await import(`../events/${eventFiles[i]}`);
8+
client.on(event.default.event, event.default.execute.bind(null, client));
9+
console.log(chalk.greenBright(`[EVENT] Loaded ${(chalk.yellow(eventFiles[i]))} with event ${(chalk.yellow(event.default.event))}`));
10+
}
911
}
1012

1113
export default { loadEvents };

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Discord from 'discord.js';
22
import config from './data/config.js';
33

4-
import commandHanderler from './handlers/commands.js';
4+
import commandHandler from './handlers/commands.js';
55
import eventHandler from './handlers/events.js';
66

77
console.clear();
@@ -16,7 +16,7 @@ const client = new Discord.Client({
1616
client.commands = new Discord.Collection();
1717
client.aliases = new Discord.Collection();
1818

19-
await commandHanderler.loadCommands(client);
19+
await commandHandler.loadCommands(client);
2020
await eventHandler.loadEvents(client);
2121

2222
process.on('uncaughtException', function (err) {

0 commit comments

Comments
 (0)