Skip to content

Commit cecfec8

Browse files
committed
add: Added error handling across files
1 parent 38d4712 commit cecfec8

File tree

6 files changed

+61
-17
lines changed

6 files changed

+61
-17
lines changed

src/events/interactionCreate.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,36 @@ module.exports = {
77

88
const command = client.commands.get(interaction.commandName);
99

10+
const color = {
11+
red: '\x1b[31m',
12+
orange: '\x1b[38;5;202m',
13+
yellow: '\x1b[33m',
14+
green: '\x1b[32m',
15+
blue: '\x1b[34m',
16+
reset: '\x1b[0m'
17+
}
18+
19+
function getTimestamp() {
20+
const date = new Date();
21+
const year = date.getFullYear();
22+
const month = date.getMonth() + 1;
23+
const day = date.getDate();
24+
const hours = date.getHours();
25+
const minutes = date.getMinutes();
26+
const seconds = date.getSeconds();
27+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
28+
}
29+
1030
if (!command) return
1131

1232
try{
1333
await command.execute(interaction, client);
1434
} catch (error) {
1535

16-
client.logs.error(error);
36+
console.error(`${color.red}[${getTimestamp()}] [INTERACTION_CREATE] Error while executing command. \n${color.red}[${getTimestamp()}] [INTERACTION_CREATE] Please check you are using the correct execute method: "async execute(interaction, client)":`, error);
1737

1838
const channelID = `${client.config.commandErrorChannel}`;
1939
const channel = client.channels.cache.get(channelID);
20-
2140

2241
const embed = new EmbedBuilder()
2342
.setColor("Blue")

src/events/messageCreate.js

+30-6
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,44 @@ module.exports = {
1111
if (!message.content.startsWith(client.config.prefix)) return;
1212
const args = message.content.slice(client.config.prefix.length).trim().split(/ +/);
1313

14+
const color = {
15+
red: '\x1b[31m',
16+
orange: '\x1b[38;5;202m',
17+
yellow: '\x1b[33m',
18+
green: '\x1b[32m',
19+
blue: '\x1b[34m',
20+
reset: '\x1b[0m'
21+
}
22+
23+
function getTimestamp() {
24+
const date = new Date();
25+
const year = date.getFullYear();
26+
const month = date.getMonth() + 1;
27+
const day = date.getDate();
28+
const hours = date.getHours();
29+
const minutes = date.getMinutes();
30+
const seconds = date.getSeconds();
31+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
32+
}
33+
1434
let cmd = args.shift().toLowerCase();
1535
if (cmd.length === 0) return;
1636

1737
let command = client.pcommands.get(cmd);
1838
if (!command) command = client.pcommands.get(client.aliases.get(cmd));
1939

2040
if (!command) {
41+
try{
2142

22-
const embed = new EmbedBuilder()
23-
.setColor("Red")
24-
.setTitle(`${client.user.username} prefix system ${client.config.arrowEmoji}`)
25-
.setDescription(`> The command you tried **does not exist**. \n> To see **all** commands, use \`\`${client.config.prefix}help\`\``)
43+
const embed = new EmbedBuilder()
44+
.setColor("Red")
45+
.setTitle(`${client.user.username} prefix system ${client.config.arrowEmoji}`)
46+
.setDescription(`> The command you tried **does not exist**. \n> To see **all** commands, use \`\`${client.config.prefix}help\`\``)
2647

27-
return message.reply({ embeds: [embed], ephemeral: true});
48+
return message.reply({ embeds: [embed], ephemeral: true});
49+
} catch (error) {
50+
client.logs.error(`[PREFIX_ERROR] Error sending 'cannot find prefix' embed.`, error);
51+
};
2852
};
2953

3054
if (!command) return;
@@ -36,7 +60,7 @@ module.exports = {
3660
try {
3761
command.execute(message, client, args);
3862
} catch (error) {
39-
client.logs.error(error)
63+
console.error(`${color.red}[${getTimestamp()}] [MESSAGE_CREATE] Error while executing command. \n${color.red}[${getTimestamp()}] [MESSAGE_CREATE] Please check you are using the correct execute method: "async execute(message, client, args)":`, error);
4064

4165
const embed = new EmbedBuilder()
4266
.setColor("Red")

src/functions/handelCommands.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ module.exports = (client) => {
6767
Routes.applicationCommands(clientId), {
6868
body: client.commandArray
6969
},
70-
);
70+
).catch((error) => {
71+
console.error(`${color.red}[${getTimestamp()}] [SLASH_COMMANDS] Error while refreshing application (/) commands. \n${color.red}[${getTimestamp()}] [SLASH_COMMANDS] Check if your clientID is correct and matches your bots token:`, error);
72+
});
7173

7274
client.logs.success(`[SLASH_COMMANDS] Successfully reloaded application (/) commands.`);
7375
} catch (error) {

src/functions/handlePrefix.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ module.exports = (client) => {
5555

5656
(async () => {
5757
try {
58-
5958
client.logs.success(`[PREFIX_COMMANDS] Successfully reloaded prefix (?) commands.`);
60-
6159
} catch (error) {
6260
console.error(error);
6361
}
6462
})();
65-
}
66-
}
63+
};
64+
};

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const fs = require('fs');
55

66
// Version Control //
77

8-
const currentVersion = "v2.0";
8+
const currentVersion = "beta";
99

1010
const client = new Client({ intents: [
1111
GatewayIntentBits.Guilds,

src/lib/version.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ function getTimestamp() {
2424

2525
async function getLatestVersion() {
2626
try {
27-
const response = await axios.get('https://api.github.com/repos/Kkkermit/DiscordBotV14-template/releases/latest');
27+
const response = await axios.get('https://api.github.com/repos/Kkkermit/Testify/releases/latest');
2828
const latestVersion = response.data.tag_name;
2929
return latestVersion;
3030
} catch (error) {
31-
console.error(`${color.torquise}[${getTimestamp()}] [LATEST_VERSION] Error while retrieving the latest version, ${color.reset}`, error);
31+
// Release has not yet come out yet causing this error to be thrown, just ignore it for it now.
32+
console.error(`${color.torquise}[${getTimestamp()}] [LATEST_VERSION] Error while retrieving the latest version. No release found. ${color.reset}`);
3233
}
3334
}
3435

3536
function checkVersion(currentVersion) {
3637
getLatestVersion().then((latestVersion) => {
3738
if (currentVersion < latestVersion) {
38-
console.log(`${color.torquise}[${getTimestamp()}] [LATEST_VERSION] Attention, a new update is available, please install it - https://github.com/Kkkermit/DiscordBotV14-template`);
39+
console.log(`${color.torquise}[${getTimestamp()}] [LATEST_VERSION] Attention, a new update is available, please install it - https://github.com/Kkkermit/Testify`);
3940
} else {
4041
console.log(`${color.torquise}[${getTimestamp()}] [LATEST_VERSION] You have the latest version of the code.`);
4142
}

0 commit comments

Comments
 (0)