mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 14:38:49 +00:00
fix: more changes to logging
This commit is contained in:
1 parent
7ef666f03d
commit
9d9087d4c3
39 files changed
+403
-260
No files matched your search
Generated
+10
-1
@@ -21,7 +21,8 @@
|
||||
"mediaplex": "^0.0.6",
|
||||
"node-os-utils": "^1.3.7",
|
||||
"pino": "^8.15.0",
|
||||
"pino-loki": "^2.1.3"
|
||||
"pino-loki": "^2.1.3",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.47.0",
|
||||
@@ -3643,6 +3644,14 @@
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/vue-eslint-parser": {
|
||||
"version": "8.3.0",
|
||||
"resolved": "https://registry.npmjs.org/vue-eslint-parser/-/vue-eslint-parser-8.3.0.tgz",
|
||||
|
||||
+4
-3
@@ -20,10 +20,10 @@
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node ./src/index.js",
|
||||
"start-pretty": "node ./src/index.js | pino-pretty --ignore environment,source,module,action,name,context,err,error",
|
||||
"start-pretty": "node ./src/index.js | pino-pretty --ignore environment,source,module,action,name,context,err,error,executionId,shardId,guildId",
|
||||
"start-pretty-no-ignore": "node ./src/index.js | pino-pretty",
|
||||
"deploy": "node ./src/utils/deploySlashCommands.js",
|
||||
"deploy-pretty": "node ./src/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,err,error",
|
||||
"deploy-pretty": "node ./src/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,err,error,executionId,shardId,guildId",
|
||||
"eslint": "eslint ./"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -39,7 +39,8 @@
|
||||
"mediaplex": "^0.0.6",
|
||||
"node-os-utils": "^1.3.7",
|
||||
"pino": "^8.15.0",
|
||||
"pino-loki": "^2.1.3"
|
||||
"pino-loki": "^2.1.3",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.47.0",
|
||||
|
||||
+15
-5
@@ -1,18 +1,28 @@
|
||||
require('dotenv').config();
|
||||
const logger = require('./services/logger');
|
||||
const { registerEventListeners } = require('./utils/registerEventListeners.js');
|
||||
const { registerClientCommands } = require('./utils/registerClientCommands.js');
|
||||
const { createClient } = require('./utils/factory/createClient.js');
|
||||
const { createPlayer } = require('./utils/factory/createPlayer.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('./services/logger').child({
|
||||
source: 'bot.js',
|
||||
module: 'shardingClient',
|
||||
name: 'shardingClient',
|
||||
executionId: executionId,
|
||||
shardId: 'client'
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const client = await createClient();
|
||||
const player = await createPlayer(client);
|
||||
const client = await createClient({ executionId });
|
||||
const player = await createPlayer({ client, executionId });
|
||||
|
||||
client.on('allShardsReady', async () => {
|
||||
client.registerClientCommands = registerClientCommands;
|
||||
registerEventListeners(client, player);
|
||||
registerClientCommands(client);
|
||||
registerEventListeners({ client, player, executionId });
|
||||
registerClientCommands({ client, executionId });
|
||||
client.emit('ready', client);
|
||||
});
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ module.exports = {
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
||||
logger.error(error, 'Failed to fetch client values from shards.');
|
||||
});
|
||||
|
||||
const botStatusString =
|
||||
|
||||
@@ -88,7 +88,7 @@ module.exports = {
|
||||
components: [filterActionRow, disableFiltersActionRow]
|
||||
});
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Sent embed for command ${interaction.commandName}, awaiting interaction response.`
|
||||
`Sent embed for command ${interaction.commandName}, awaiting interaction response.`
|
||||
);
|
||||
|
||||
const collectorFilter = (i) => i.user.id === interaction.user.id;
|
||||
@@ -99,7 +99,7 @@ module.exports = {
|
||||
});
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Received interaction response for command ${interaction.commandName}.`
|
||||
`Received interaction response for command ${interaction.commandName}.`
|
||||
);
|
||||
|
||||
confirmation.deferUpdate();
|
||||
@@ -150,7 +150,7 @@ module.exports = {
|
||||
queue.filters.ffmpeg.toggle(confirmation.values);
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Enabled filters ${confirmation.values.join(', ')} for command ${
|
||||
`Enabled filters ${confirmation.values.join(', ')} for command ${
|
||||
interaction.commandName
|
||||
}.`
|
||||
);
|
||||
@@ -182,14 +182,14 @@ module.exports = {
|
||||
} catch (error) {
|
||||
if (error.code === 'InteractionCollectorError') {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Interaction response timed out for command ${interaction.commandName}.`
|
||||
`Interaction response timed out for command ${interaction.commandName}.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
error,
|
||||
`[Shard ${interaction.guild.shardId}] Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.`
|
||||
`Unhandled error while awaiting interaction response for command ${interaction.commandName}, throwing error.`
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = {
|
||||
|
||||
if (!queue) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
||||
`User used command ${interaction.commandName} but there was no queue.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -42,7 +42,7 @@ module.exports = {
|
||||
if (!queue.deleted) {
|
||||
queue.delete();
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and deleted the queue.`
|
||||
`User used command ${interaction.commandName} and deleted the queue.`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ module.exports = {
|
||||
|
||||
if (!mode && mode !== 0) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but no mode was provided.`
|
||||
`User used command ${interaction.commandName} but no mode was provided.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -74,7 +74,7 @@ module.exports = {
|
||||
|
||||
if (mode === currentMode) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.`
|
||||
`User used command ${interaction.commandName} but loop mode was already set to ${modeUserString}.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -92,7 +92,7 @@ module.exports = {
|
||||
|
||||
if (!queue.repeatMode === mode) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but failed to change loop mode.`
|
||||
`User used command ${interaction.commandName} but failed to change loop mode.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -108,7 +108,7 @@ module.exports = {
|
||||
|
||||
if (queue.repeatMode === 0) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and disabled loop mode.`
|
||||
`User used command ${interaction.commandName} and disabled loop mode.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -128,7 +128,7 @@ module.exports = {
|
||||
|
||||
if (queue.repeatMode === 3) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and enabled autoplay.`
|
||||
`User used command ${interaction.commandName} and enabled autoplay.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -147,7 +147,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and enabled loop mode.`
|
||||
`User used command ${interaction.commandName} and enabled loop mode.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
|
||||
@@ -34,7 +34,7 @@ module.exports = {
|
||||
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
||||
logger.debug(
|
||||
{ action: 'autocomplete_responded' },
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with results from lastQuery for query: '${query}'`
|
||||
`Autocomplete search responded with results from lastQuery for query: '${query}'`
|
||||
);
|
||||
return interaction.respond(result);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ module.exports = {
|
||||
if (query.length < 3) {
|
||||
logger.debug(
|
||||
{ action: 'autocomplete_responded' },
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with empty results due to < 3 length for query '${query}'`
|
||||
`Autocomplete search responded with empty results due to < 3 length for query '${query}'`
|
||||
);
|
||||
return interaction.respond([]);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ module.exports = {
|
||||
|
||||
logger.debug(
|
||||
{ action: 'autocomplete_responded' },
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded for query: '${query}'`
|
||||
`Autocomplete search responded for query: '${query}'`
|
||||
);
|
||||
return interaction.respond(response);
|
||||
},
|
||||
@@ -119,7 +119,7 @@ module.exports = {
|
||||
|
||||
if (searchResults.tracks.length === 0) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no search results found.`
|
||||
`User used command ${interaction.commandName} but there was no search results found.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -173,7 +173,7 @@ module.exports = {
|
||||
|
||||
if (!lyricsResult || !lyricsResult.lyrics) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no lyrics found.`
|
||||
`User used command ${interaction.commandName} but there was no lyrics found.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -188,11 +188,11 @@ module.exports = {
|
||||
|
||||
// If message length is too long, split into multiple messages
|
||||
if (lyricsResult.lyrics.length > 3800) {
|
||||
logger.debug(`[Shard ${interaction.guild.shardId}] Lyrics too long, splitting into multiple messages.`);
|
||||
logger.debug('Lyrics too long, splitting into multiple messages.');
|
||||
const messageCount = Math.ceil(lyricsResult.lyrics.length / 3800);
|
||||
for (let i = 0; i < messageCount; i++) {
|
||||
logger.debuf(
|
||||
`[Shard ${interaction.guild.shardId}] Lyrics, sending message ${i + 1} of ${messageCount}.`
|
||||
`Lyrics, sending message ${i + 1} of ${messageCount}.`
|
||||
);
|
||||
const message = lyricsResult.lyrics.slice(i * 3800, (i + 1) * 3800);
|
||||
if (i === 0) {
|
||||
@@ -224,7 +224,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and retrieved lyrics.`
|
||||
`User used command ${interaction.commandName} and retrieved lyrics.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
|
||||
@@ -107,7 +107,7 @@ module.exports = {
|
||||
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, finished intializing data.`
|
||||
`User used command ${interaction.commandName}, finished intializing data.`
|
||||
);
|
||||
|
||||
const response = await interaction.editReply({
|
||||
@@ -159,7 +159,7 @@ module.exports = {
|
||||
});
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, finished sending response.`
|
||||
`User used command ${interaction.commandName}, finished sending response.`
|
||||
);
|
||||
|
||||
const collectorFilter = (i) => i.user.id === interaction.user.id;
|
||||
@@ -173,11 +173,11 @@ module.exports = {
|
||||
|
||||
if (confirmation.customId === 'nowplaying-skip') {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName}, received skip confirmation.`
|
||||
`User used command ${interaction.commandName}, received skip confirmation.`
|
||||
);
|
||||
if (!queue || (queue.tracks.data.length === 0 && !queue.currentTrack)) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and tried skipping but there was no queue.`
|
||||
`User used command ${interaction.commandName} and tried skipping but there was no queue.`
|
||||
);
|
||||
return await interaction.followUp({
|
||||
embeds: [
|
||||
@@ -193,7 +193,7 @@ module.exports = {
|
||||
|
||||
if (queue.currentTrack !== currentTrack) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and tried skipping but the track was already removed.`
|
||||
`User used command ${interaction.commandName} and tried skipping but the track was already removed.`
|
||||
);
|
||||
return await interaction.followUp({
|
||||
embeds: [
|
||||
@@ -221,7 +221,7 @@ module.exports = {
|
||||
const repeatModeUserString = loopModesFormatted.get(queue.repeatMode);
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped the track.`
|
||||
`User used command ${interaction.commandName} and skipped the track.`
|
||||
);
|
||||
return await interaction.followUp({
|
||||
embeds: [
|
||||
@@ -251,14 +251,14 @@ module.exports = {
|
||||
} catch (error) {
|
||||
if (error.code === 'InteractionCollectorError') {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but did not respond to the skip prompt.`
|
||||
`User used command ${interaction.commandName} but did not respond to the skip prompt.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
error,
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was an unhandled error.`
|
||||
`User used command ${interaction.commandName} but there was an unhandled error.`
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ module.exports = {
|
||||
// change paused state to opposite of current state
|
||||
queue.node.setPaused(!queue.node.isPaused());
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${
|
||||
`User used command ${
|
||||
interaction.commandName
|
||||
} and set paused state to ${queue.node.isPaused()}.`
|
||||
);
|
||||
|
||||
+49
-56
@@ -9,12 +9,6 @@ const { transformQuery } = require('../../utils/validation/searchQueryValidator'
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
const { useMainPlayer, useQueue } = require('discord-player');
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'play.js',
|
||||
module: 'command',
|
||||
name: '/play'
|
||||
});
|
||||
|
||||
const recentQueries = new Map();
|
||||
|
||||
module.exports = {
|
||||
@@ -34,25 +28,28 @@ module.exports = {
|
||||
.setMaxLength(500)
|
||||
.setAutocomplete(true)
|
||||
),
|
||||
autocomplete: async ({ interaction }) => {
|
||||
autocomplete: async ({ interaction, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'play.js',
|
||||
module: 'slashCommand',
|
||||
name: '/play',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
const player = useMainPlayer();
|
||||
const query = interaction.options.getString('query', true);
|
||||
|
||||
const { lastQuery, results, timestamp } = recentQueries.get(interaction.user.id) || {};
|
||||
|
||||
if (lastQuery && (query.startsWith(lastQuery) || lastQuery.startsWith(query)) && Date.now() - timestamp < 500) {
|
||||
logger.debug(
|
||||
{ action: 'autocomplete_responded' },
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with results from lastQuery for query: '${query}'`
|
||||
);
|
||||
logger.debug(`Autocomplete search responded with results from lastQuery for query: '${query}'`);
|
||||
return interaction.respond(results);
|
||||
}
|
||||
|
||||
if (query.length < 3) {
|
||||
logger.debug(
|
||||
{ action: 'autocomplete_responded' },
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded with empty results due to < 3 length for query '${query}'`
|
||||
);
|
||||
logger.debug(`Autocomplete search responded with empty results due to < 3 length for query '${query}'`);
|
||||
return interaction.respond([]);
|
||||
}
|
||||
const searchResults = await player.search(query);
|
||||
@@ -82,14 +79,18 @@ module.exports = {
|
||||
return interaction.respond([]);
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
{ action: 'autocomplete_responded' },
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete search responded for query: '${query}'`
|
||||
);
|
||||
logger.debug(`Autocomplete search responded for query: '${query}'`);
|
||||
|
||||
return interaction.respond(response);
|
||||
},
|
||||
execute: async ({ interaction, client }) => {
|
||||
execute: async ({ interaction, client, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'play.js',
|
||||
module: 'slashCommand',
|
||||
name: '/play',
|
||||
executionId: executionId
|
||||
});
|
||||
|
||||
if (await notInVoiceChannel(interaction, client)) {
|
||||
return;
|
||||
}
|
||||
@@ -123,12 +124,12 @@ module.exports = {
|
||||
stack: error.stack
|
||||
}
|
||||
},
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Failed to search for track with player.search() with query: ${transformedQuery}.`
|
||||
`Failed to search for track with player.search() with query: ${transformedQuery}.`
|
||||
);
|
||||
}
|
||||
|
||||
if (!searchResult || searchResult.tracks.length === 0) {
|
||||
logger.debug(`[Shard ${interaction.guild.shardId}] No results found for query: ${query}`);
|
||||
logger.debug(`No results found for query: ${query}`);
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -145,9 +146,7 @@ module.exports = {
|
||||
let queueSize = queue?.size ?? 0;
|
||||
|
||||
if ((searchResult.playlist && searchResult.tracks.length) > playerOptions.maxQueueSize - queueSize) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Playlist found but too many tracks. Query: ${query}.`
|
||||
);
|
||||
logger.debug(`Playlist found but too many tracks. Query: ${query}.`);
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -186,12 +185,10 @@ module.exports = {
|
||||
}
|
||||
}));
|
||||
|
||||
logger.debug(`[Shard ${interaction.guild.shardId}] player.play() successful. Query: ${query}.`);
|
||||
logger.debug(`player.play() successful. Query: ${query}.`);
|
||||
} catch (error) {
|
||||
if (error.message.includes('Sign in to confirm your age')) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Found track but failed to retrieve audio due to age confirmation warning.`
|
||||
);
|
||||
logger.debug('Found track but failed to retrieve audio due to age confirmation warning.');
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
@@ -204,9 +201,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (error.message.includes('The following content may contain')) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Found track but failed to retrieve audio due to graphic/mature/sensitive topic warning.`
|
||||
);
|
||||
logger.debug('Found track but failed to retrieve audio due to graphic/mature/sensitive topic warning.');
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
@@ -224,10 +219,7 @@ module.exports = {
|
||||
error.message.includes('Failed to fetch resources for ytdl streaming'))) ||
|
||||
error.message.includes('Could not extract stream for this track')
|
||||
) {
|
||||
logger.debug(
|
||||
error,
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Found track but failed to retrieve audio. Query: ${query}.`
|
||||
);
|
||||
logger.debug(error, `Found track but failed to retrieve audio. Query: ${query}.`);
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -241,10 +233,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (error.message === 'Cancelled') {
|
||||
logger.debug(
|
||||
error,
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Operation cancelled. Query: ${query}.`
|
||||
);
|
||||
logger.debug(error, `Operation cancelled. Query: ${query}.`);
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -257,18 +246,28 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
logger.error(
|
||||
error,
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Failed to play track with player.play(), unhandled error.`
|
||||
);
|
||||
if (error.message === 'Cannot read properties of null (reading \'createStream\')') {
|
||||
// Can happen if /play then /leave before track starts playing
|
||||
logger.warn(error, 'Found track but failed to play back audio. Voice connection might be unavailable.');
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.error} Uh-oh... Failed to add track!**\nSomething unexpected happened and it was not possible to start playing the track. This could happen if the voice connection is lost or queue is destroyed while adding the track.\n\nYou can try to perform the command again.\n\n_If you think this message is incorrect, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
//logger.error(error, 'Failed to play track with player.play(), unhandled error.');
|
||||
}
|
||||
|
||||
queue = useQueue(interaction.guild.id);
|
||||
|
||||
if (!queue) {
|
||||
logger.warn(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> After player.play(), queue is undefined. Query: ${query}.`
|
||||
);
|
||||
logger.warn(`After player.play(), queue is undefined. Query: ${query}.`);
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -299,9 +298,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (searchResult.playlist && searchResult.tracks.length > 1) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Playlist found and added with player.play(). Query: '${query}'`
|
||||
);
|
||||
logger.debug(`Playlist found and added with player.play(). Query: '${query}'`);
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -324,9 +321,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (queue.currentTrack === track && queue.tracks.data.length === 0) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Track found and added with player.play(), started playing. Query: ${query}.`
|
||||
);
|
||||
logger.debug(`Track found and added with player.play(), started playing. Query: ${query}.`);
|
||||
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -345,9 +340,7 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Track found and added with player.play(), added to queue. Query: ${query}.`
|
||||
);
|
||||
logger.debug(`Track found and added with player.play(), added to queue. Query: ${query}.`);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
|
||||
@@ -32,7 +32,7 @@ module.exports = {
|
||||
if (!queue) {
|
||||
if (pageIndex >= 1) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
||||
`User used command ${interaction.commandName} but there was no queue.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -48,7 +48,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
||||
`User used command ${interaction.commandName} but there was no queue.`
|
||||
);
|
||||
queueString = 'The queue is empty, add some tracks with **`/play`**!';
|
||||
return await interaction.editReply({
|
||||
@@ -72,7 +72,7 @@ module.exports = {
|
||||
|
||||
if (pageIndex > totalPages - 1) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but page was higher than total pages.`
|
||||
`User used command ${interaction.commandName} but page was higher than total pages.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -127,7 +127,7 @@ module.exports = {
|
||||
|
||||
if (!currentTrack) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no current track.`
|
||||
`User used command ${interaction.commandName} but there was no current track.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -166,7 +166,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and got queue in reply with current track.`
|
||||
`User used command ${interaction.commandName} and got queue in reply with current track.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
@@ -40,7 +40,7 @@ module.exports = {
|
||||
|
||||
if (removeTrackNumber > queue.tracks.data.length) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but track number was higher than total tracks.`
|
||||
`User used command ${interaction.commandName} but track number was higher than total tracks.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -64,7 +64,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and removed track.`
|
||||
`User used command ${interaction.commandName} and removed track.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
@@ -55,7 +55,7 @@ module.exports = {
|
||||
|
||||
if (durationArray.length === 0 || durationArray.length > 3) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration.`
|
||||
`User used command ${interaction.commandName} but entered an invalid duration.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -84,7 +84,7 @@ module.exports = {
|
||||
|
||||
if (!validElements) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration after parsing duration.`
|
||||
`User used command ${interaction.commandName} but entered an invalid duration after parsing duration.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -107,7 +107,7 @@ module.exports = {
|
||||
|
||||
if (!isValidDuration) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered an invalid duration after regex checks.`
|
||||
`User used command ${interaction.commandName} but entered an invalid duration after regex checks.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
@@ -129,7 +129,7 @@ module.exports = {
|
||||
|
||||
if (durationInMilliseconds > currentTrackMaxDurationInMs - 1000) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but entered a duration longer than the track.`
|
||||
`User used command ${interaction.commandName} but entered a duration longer than the track.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -145,7 +145,7 @@ module.exports = {
|
||||
queue.node.seek(durationInMilliseconds);
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and seeked to duration.`
|
||||
`User used command ${interaction.commandName} and seeked to duration.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
@@ -36,7 +36,7 @@ module.exports = {
|
||||
queue.tracks.shuffle();
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and shuffled the queue.`
|
||||
`User used command ${interaction.commandName} and shuffled the queue.`
|
||||
);
|
||||
|
||||
return await interaction.editReply({
|
||||
|
||||
@@ -41,7 +41,7 @@ module.exports = {
|
||||
if (skipToTrack) {
|
||||
if (skipToTrack > queue.tracks.data.length) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but track number was higher than total tracks.`
|
||||
`User used command ${interaction.commandName} but track number was higher than total tracks.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -66,7 +66,7 @@ module.exports = {
|
||||
queue.node.skipTo(skipToTrack - 1);
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped to track.`
|
||||
`User used command ${interaction.commandName} and skipped to track.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -86,7 +86,7 @@ module.exports = {
|
||||
} else {
|
||||
if (queue.tracks.data.length === 0 && !queue.currentTrack) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no tracks in queue or current track.`
|
||||
`User used command ${interaction.commandName} but there was no tracks in queue or current track.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -120,7 +120,7 @@ module.exports = {
|
||||
const loopModeUserString = loopModesFormatted.get(queue.repeatMode);
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and skipped track.`
|
||||
`User used command ${interaction.commandName} and skipped track.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = {
|
||||
|
||||
if (!queue) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but there was no queue.`
|
||||
`User used command ${interaction.commandName} but there was no queue.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -44,7 +44,7 @@ module.exports = {
|
||||
queue.clear();
|
||||
queue.node.stop();
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and cleared the queue.`
|
||||
`User used command ${interaction.commandName} and cleared the queue.`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ module.exports = {
|
||||
const currentVolume = queue.node.volume;
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but no volume was provided, providing info of current volume.`
|
||||
`User used command ${interaction.commandName} but no volume was provided, providing info of current volume.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -57,7 +57,7 @@ module.exports = {
|
||||
});
|
||||
} else if (volume > 100 || volume < 0) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} but volume was higher than 100% or lower than 0%.`
|
||||
`User used command ${interaction.commandName} but volume was higher than 100% or lower than 0%.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -73,7 +73,7 @@ module.exports = {
|
||||
|
||||
if (volume === 0) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and muted volume.`
|
||||
`User used command ${interaction.commandName} and muted volume.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -91,7 +91,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] User used command ${interaction.commandName} and changed volume.`
|
||||
`User used command ${interaction.commandName} and changed volume.`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = {
|
||||
.setNSFW(false),
|
||||
execute: async ({ interaction, client }) => {
|
||||
if (await notValidGuildId(interaction)) {
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Not a valid guild id.`);
|
||||
logger.debug('Not a valid guild id.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = {
|
||||
.setNSFW(false),
|
||||
execute: async ({ interaction, client }) => {
|
||||
if (await notValidGuildId(interaction)) {
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Not a valid guild id.`);
|
||||
logger.debug('Not a valid guild id.');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ module.exports = {
|
||||
shardClient.registerClientCommands(shardClient);
|
||||
})
|
||||
.then(() => {
|
||||
logger.info(`[Shard ${client.shard.ids[0]}] Reloaded commands across all shards.`);
|
||||
logger.info('Reloaded commands across all shards.');
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to reload commands.`);
|
||||
logger.error(error, 'Failed to reload commands.');
|
||||
}
|
||||
|
||||
const commands = client.commands.map((command) => {
|
||||
|
||||
@@ -90,10 +90,10 @@ module.exports = {
|
||||
break;
|
||||
}
|
||||
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Fetched shardInfo from each shard.`);
|
||||
logger.debug('Fetched shardInfo from each shard.');
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
||||
logger.error(error, 'Failed to fetch client values from shards.');
|
||||
});
|
||||
|
||||
const shardCount = shardInfoList.length;
|
||||
|
||||
@@ -80,7 +80,7 @@ module.exports = {
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
||||
logger.error(error, 'Failed to fetch client values from shards.');
|
||||
});
|
||||
|
||||
const botStatusString =
|
||||
|
||||
@@ -9,7 +9,7 @@ module.exports = {
|
||||
isDebug: false,
|
||||
once: false,
|
||||
execute: async (client) => {
|
||||
logger.warn(`[Shard ${client.shard.ids[0]}] ${client.user.tag} lost connection to Discord APIs. Disconnected.`);
|
||||
logger.warn(`${client.user.tag} lost connection to Discord APIs. Disconnected.`);
|
||||
|
||||
// send message to system message channel for event
|
||||
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { Events } = require('discord.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildCreate,
|
||||
isDebug: false,
|
||||
once: false,
|
||||
execute: async (guild) => {
|
||||
logger.info(`[Shard ${guild.shardId}] Added to guild '${guild.name}' with ${guild.memberCount} members.`);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'guildCreate.js',
|
||||
module: 'event',
|
||||
name: 'guildCreate',
|
||||
executionId: executionId,
|
||||
shardId: guild.shardId,
|
||||
guildId: guild.id
|
||||
});
|
||||
|
||||
logger.info(`Added to guild '${guild.id}' with ${guild.memberCount} members.`);
|
||||
}
|
||||
};
|
||||
@@ -1,13 +1,22 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { Events } = require('discord.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
module.exports = {
|
||||
name: Events.GuildDelete,
|
||||
isDebug: false,
|
||||
once: false,
|
||||
execute: async (guild) => {
|
||||
logger.info(
|
||||
`[Shard ${guild.shardId}] Removed from guild '${guild.name}' with ${guild.memberCount} members.`
|
||||
);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'guildDelete.js',
|
||||
module: 'event',
|
||||
name: 'guildDelete',
|
||||
executionId: executionId,
|
||||
shardId: guild.shardId,
|
||||
guildId: guild.id
|
||||
});
|
||||
|
||||
logger.info(`Removed from guild '${guild.id}' with ${guild.memberCount} members.`);
|
||||
}
|
||||
};
|
||||
+16
-10
@@ -1,4 +1,3 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const embedOptions = config.get('embedOptions');
|
||||
const systemOptions = config.get('systemOptions');
|
||||
@@ -7,29 +6,36 @@ const loadTestOptions = config.get('loadTestOptions');
|
||||
const { postBotStats } = require('../../utils/other/postBotStats.js');
|
||||
const { startLoadTest } = require('../../utils/other/startLoadTest');
|
||||
const { Events, EmbedBuilder } = require('discord.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
module.exports = {
|
||||
name: Events.ClientReady,
|
||||
isDebug: false,
|
||||
once: false,
|
||||
execute: async (client) => {
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Client 'ready' event emitted after 'allShardsReady'.`);
|
||||
await client.user.setPresence(presenceStatusOptions);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'ready.js',
|
||||
module: 'event',
|
||||
name: 'clientReady',
|
||||
executionId: executionId,
|
||||
shardId: client.shard.ids[0]
|
||||
});
|
||||
|
||||
logger.debug('Client \'ready\' event received after \'allShardsReady\' event.');
|
||||
await client.user.setPresence(presenceStatusOptions);
|
||||
|
||||
if (loadTestOptions.enabled) {
|
||||
logger.info(`[Shard ${client.shard.ids[0]}] STARTING LOAD TEST.`);
|
||||
await startLoadTest(client);
|
||||
logger.info('Initiating load test for bot client.');
|
||||
await startLoadTest({ client, executionId });
|
||||
}
|
||||
|
||||
const channel = await client.channels.cache.get(systemOptions.systemMessageChannelId);
|
||||
logger.info(`[Shard ${client.shard.ids[0]}] ALL SHARDS READY`);
|
||||
|
||||
// Check if the channel exists in curent shard and send a message
|
||||
if (channel) {
|
||||
logger.info(
|
||||
`[Shard ${client.shard.ids[0]}] Sending system message for 'allShardsReady' to channel id ${channel.id}.`
|
||||
);
|
||||
logger.debug(`Sending system message for 'allShardsReady' to channel id ${channel.id}.`);
|
||||
channel.send({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
@@ -41,6 +47,6 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
process.env.NODE_ENV === 'production' ? await postBotStats(client) : null;
|
||||
process.env.NODE_ENV === 'production' ? await postBotStats({ client, executionId }) : null;
|
||||
}
|
||||
};
|
||||
@@ -9,7 +9,7 @@ module.exports = {
|
||||
isDebug: false,
|
||||
once: false,
|
||||
execute: async (client) => {
|
||||
logger.warn(`[Shard ${client.shard.ids[0]}] ${client.user.tag} is reconnecting to Discord APIs.`);
|
||||
logger.warn(`${client.user.tag} is reconnecting to Discord APIs.`);
|
||||
|
||||
// send message to system message channel for event
|
||||
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const embedOptions = config.get('embedOptions');
|
||||
const botOptions = config.get('botOptions');
|
||||
const { cannotSendMessageInChannel } = require('../../utils/validation/permissionValidator');
|
||||
const { Events, EmbedBuilder } = require('discord.js');
|
||||
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
isDebug: false,
|
||||
execute: async (interaction, { client }) => {
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'interactionCreate.js',
|
||||
module: 'event',
|
||||
name: 'interactionCreate',
|
||||
executionId: executionId,
|
||||
shardId: interaction.guild.shardId,
|
||||
guildId: interaction.guild.id
|
||||
});
|
||||
|
||||
if (interaction.isMessageComponent()) {
|
||||
logger.info(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${
|
||||
interaction.guild.id
|
||||
}> Message component interaction created for id ${interaction.customId}${
|
||||
logger.debug(
|
||||
`Message component interaction created for id ${interaction.customId}${
|
||||
interaction.values ? ' and values ' + interaction.values : ''
|
||||
}.`
|
||||
);
|
||||
@@ -22,32 +32,30 @@ module.exports = {
|
||||
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
if (!command) {
|
||||
logger.warn(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction created but command '${interaction.commandName}' was not found.`
|
||||
);
|
||||
logger.warn(`Interaction created but command '${interaction.commandName}' was not found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (interaction.isAutocomplete()) {
|
||||
logger.debug(`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete created.`);
|
||||
logger.debug('Autocomplete interaction created.');
|
||||
try {
|
||||
await command.autocomplete({ interaction, client });
|
||||
await command.autocomplete({ interaction, executionId });
|
||||
} catch (error) {
|
||||
if (
|
||||
error.message === 'Unknown interaction' ||
|
||||
error.message === 'Interaction has already been acknowledged.'
|
||||
) {
|
||||
logger.debug(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Autocomplete failed to be responded to, unknown interaction or already acknowledged.`
|
||||
'Autocomplete failed to be responded to, unknown interaction or already acknowledged.'
|
||||
);
|
||||
return;
|
||||
} else {
|
||||
logger.warn(error, `[Shard ${interaction.guild.shardId}] Autocomplete failed to execute.`);
|
||||
logger.warn(error, 'Autocomplete failed to execute.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else if (interaction.isChatInputCommand()) {
|
||||
logger.debug(`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction created.`);
|
||||
logger.debug(`Chat input command interaction created for ${interaction.commandName}.`);
|
||||
try {
|
||||
await interaction.deferReply();
|
||||
|
||||
@@ -56,62 +64,70 @@ module.exports = {
|
||||
}
|
||||
|
||||
const inputTime = new Date();
|
||||
await command.execute({ interaction, client });
|
||||
await command.execute({ interaction, client, executionId });
|
||||
|
||||
const outputTime = new Date();
|
||||
const executionTime = outputTime - inputTime;
|
||||
|
||||
logger.info(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Command '${interaction}' executed in ${executionTime} ms.`
|
||||
`Command '${interaction}' executed in ${executionTime} ms.`
|
||||
);
|
||||
} catch (error) {
|
||||
logger.warn(
|
||||
error,
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Command '${interaction}' throwed an unhandled error and might have failed to execute properly.`
|
||||
`Command '${interaction}' throwed an unhandled error and might have failed to execute properly.`
|
||||
);
|
||||
|
||||
if (!interaction.deferred || !interaction.replied) {
|
||||
logger.warn(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction was not deferred or replied to, and an error was thrown.`
|
||||
);
|
||||
if (
|
||||
error.message === 'Unknown interaction' ||
|
||||
error.message === 'Interaction has already been acknowledged.'
|
||||
) {
|
||||
logger.debug('Command failed to be responded to, unknown interaction or already acknowledged.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (interaction.replied) {
|
||||
// If the interaction has already been replied to, most likely command executed successfully or error is already handled.
|
||||
return;
|
||||
} else if (interaction.deferred) {
|
||||
logger.info(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction was deferred, editing reply and sending Uh-oh message.`
|
||||
);
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
]
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction was not deferred or replied, sending new reply with Uh-oh message.`
|
||||
);
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
]
|
||||
});
|
||||
if (!interaction.deferred || !interaction.replied) {
|
||||
logger.warn(
|
||||
'Interaction was not deferred or replied to, and an error was thrown.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (interaction.replied) {
|
||||
// If the interaction has already been replied to, most likely command executed successfully or error is already handled.
|
||||
return;
|
||||
} else if (interaction.deferred) {
|
||||
logger.info(
|
||||
'Interaction was deferred, editing reply and sending Uh-oh message.'
|
||||
);
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
]
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
'Interaction was not deferred or replied, sending new reply with Uh-oh message.'
|
||||
);
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nThere was an unexpected error while trying to execute this command.\n\nYou can try to perform the command again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn(
|
||||
interaction,
|
||||
`[Shard ${interaction.guild.shardId}] Guild ${interaction.guild.id}> Interaction created but was not a chat input or autocomplete interaction.`
|
||||
'Interaction created but was not a chat input or autocomplete interaction.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const embedOptions = config.get('embedOptions');
|
||||
const botOptions = config.get('botOptions');
|
||||
const systemOptions = config.get('systemOptions');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
// Emitted when the player queue encounters error (general error with queue)
|
||||
module.exports = {
|
||||
@@ -11,10 +11,18 @@ module.exports = {
|
||||
isDebug: false,
|
||||
isPlayerEvent: true,
|
||||
execute: async (queue, error) => {
|
||||
logger.error(
|
||||
error,
|
||||
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('error'): Player queue encountered error event`
|
||||
);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'generalError.js',
|
||||
module: 'event',
|
||||
name: 'generalError',
|
||||
executionId: executionId,
|
||||
shardId: queue.metadata.client.shard.ids[0],
|
||||
guildId: queue.metadata.channel.guild.id
|
||||
});
|
||||
|
||||
logger.error(error, 'player.events.on(\'error\'): Player queue encountered error event');
|
||||
|
||||
await queue.metadata.channel.send({
|
||||
embeds: [
|
||||
@@ -33,7 +41,7 @@ module.exports = {
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`${embedOptions.icons.error} **player.events.on('error')**\n${error.message}` +
|
||||
`${embedOptions.icons.error} **player.events.on('error')**\nExecution id: ${executionId}\n${error.message}` +
|
||||
`\n\n<@${systemOptions.systemUserId}>`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
@@ -41,7 +49,5 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
process.env.NODE_ENV === 'development' ? logger.trace(queue, 'Queue object') : null;
|
||||
}
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const embedOptions = config.get('embedOptions');
|
||||
const botOptions = config.get('botOptions');
|
||||
const systemOptions = config.get('systemOptions');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
// Emitted when the player encounters an error while streaming audio track
|
||||
module.exports = {
|
||||
@@ -11,10 +11,18 @@ module.exports = {
|
||||
isDebug: false,
|
||||
isPlayerEvent: true,
|
||||
execute: async (queue, error) => {
|
||||
logger.error(
|
||||
error,
|
||||
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('playerError'): Player error while streaming track`
|
||||
);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'playerError.js',
|
||||
module: 'event',
|
||||
name: 'playerError',
|
||||
executionId: executionId,
|
||||
shardId: queue.metadata.client.shard.ids[0],
|
||||
guildId: queue.metadata.channel.guild.id
|
||||
});
|
||||
|
||||
logger.error(error, 'player.events.on(\'playerError\'): Player error while streaming track');
|
||||
|
||||
await queue.metadata.channel.send({
|
||||
embeds: [
|
||||
@@ -33,7 +41,7 @@ module.exports = {
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`${embedOptions.icons.error} **player.events.on('playerError')**\n${error.message}` +
|
||||
`${embedOptions.icons.error} **player.events.on('playerError')**\nExecution id: ${executionId}\n${error.message}` +
|
||||
`\n\n<@${systemOptions.systemUserId}>`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const embedOptions = config.get('embedOptions');
|
||||
const botOptions = config.get('botOptions');
|
||||
const systemOptions = config.get('systemOptions');
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
// Emitted when the audio player fails to load the stream for a track
|
||||
module.exports = {
|
||||
@@ -11,9 +11,18 @@ module.exports = {
|
||||
isDebug: false,
|
||||
isPlayerEvent: true,
|
||||
execute: async (queue, track) => {
|
||||
logger.error(
|
||||
`[Shard ${queue.metadata.client.shard.ids[0]}] player.events.on('playerSkip'): Failed to play '${track.url}'.`
|
||||
);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'playerSkip.js',
|
||||
module: 'event',
|
||||
name: 'playerSkip',
|
||||
executionId: executionId,
|
||||
shardId: queue.metadata.client.shard.ids[0],
|
||||
guildId: queue.metadata.channel.guild.id
|
||||
});
|
||||
|
||||
logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.`);
|
||||
|
||||
await queue.metadata.channel.send({
|
||||
embeds: [
|
||||
@@ -32,7 +41,7 @@ module.exports = {
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setDescription(
|
||||
`${embedOptions.icons.error} **player.events.on('playerSkip')**\n${track.url}` +
|
||||
`${embedOptions.icons.error} **player.events.on('playerSkip')**\nExecution id: ${executionId}\n${track.url}` +
|
||||
`\n\n<@${systemOptions.systemUserId}>`
|
||||
)
|
||||
.setColor(embedOptions.colors.error)
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
module.exports = {
|
||||
name: 'playerStart',
|
||||
isDebug: false,
|
||||
isPlayerEvent: true,
|
||||
execute: async (queue, track) => {
|
||||
logger.debug(
|
||||
`[Shard ${queue.metadata.client.shard.ids[0]}] playerStart event: Started playing '${track.raw.url}'.`
|
||||
);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'playerStart.js',
|
||||
module: 'event',
|
||||
name: 'playerStart',
|
||||
executionId: executionId,
|
||||
shardId: queue.metadata.client.shard.ids[0],
|
||||
guildId: queue.metadata.channel.guild.id
|
||||
});
|
||||
|
||||
logger.debug(`playerStart event: Started playing '${track.url}'.`);
|
||||
process.env.NODE_ENV === 'development' ? logger.trace(queue) : null;
|
||||
}
|
||||
};
|
||||
+14
-2
@@ -1,7 +1,7 @@
|
||||
require('dotenv').config();
|
||||
const shardingOptions = require('config').get('shardingOptions');
|
||||
const logger = require('./services/logger');
|
||||
const { ShardingManager, ShardEvents } = require('discord.js');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
const manager = new ShardingManager('./src/bot.js', {
|
||||
token: process.env.DISCORD_BOT_TOKEN,
|
||||
@@ -9,14 +9,26 @@ const manager = new ShardingManager('./src/bot.js', {
|
||||
});
|
||||
|
||||
const readyShards = new Set();
|
||||
|
||||
manager.on('shardCreate', (shard) => {
|
||||
logger.info(`[Shard ${shard.id}] Launched shard with id ${shard.id}.`);
|
||||
const executionId = uuidv4();
|
||||
|
||||
const logger = require('./services/logger').child({
|
||||
source: 'index.js',
|
||||
module: 'shardingManager',
|
||||
name: 'shardingManager',
|
||||
executionId: executionId,
|
||||
shardId: 'manager'
|
||||
});
|
||||
|
||||
logger.info(`Launched shard with id ${shard.id}.`);
|
||||
|
||||
// When all shards are ready, emit event 'allShardsReady' to all shards
|
||||
shard.on(ShardEvents.Ready, () => {
|
||||
readyShards.add(shard.id);
|
||||
if (readyShards.size === manager.totalShards) {
|
||||
manager.broadcastEval((client) => client.emit('allShardsReady'));
|
||||
logger.info('All shards ready, bot is now online.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
const logger = require('../../services/logger');
|
||||
const Discord = require('discord.js');
|
||||
|
||||
exports.createClient = async () => {
|
||||
exports.createClient = async ({ executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'createPlayer.js',
|
||||
module: 'utilFactory',
|
||||
name: 'createPlayer',
|
||||
executionId: executionId,
|
||||
shardId: 'client'
|
||||
});
|
||||
|
||||
try {
|
||||
logger.debug('Creating Discord.js client...');
|
||||
logger.debug('Creating discord.js client...');
|
||||
|
||||
const client = new Discord.Client({
|
||||
intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildVoiceStates],
|
||||
@@ -33,7 +40,7 @@ exports.createClient = async () => {
|
||||
|
||||
return client;
|
||||
} catch (error) {
|
||||
logger.error('Failed to create Discord.js client', error);
|
||||
logger.error(error, 'Failed to create discord.js client');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -1,9 +1,16 @@
|
||||
const logger = require('../../services/logger');
|
||||
const { Player } = require('discord-player');
|
||||
|
||||
exports.createPlayer = async (client) => {
|
||||
exports.createPlayer = async ({ client, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'createPlayer.js',
|
||||
module: 'utilFactory',
|
||||
name: 'createPlayer',
|
||||
executionId: executionId,
|
||||
shardId: client.shard.ids[0]
|
||||
});
|
||||
|
||||
try {
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Creating discord-player player...`);
|
||||
logger.debug('Creating discord-player player...');
|
||||
|
||||
const player = new Player(client, {
|
||||
useLegacyFFmpeg: false,
|
||||
@@ -23,11 +30,11 @@ exports.createPlayer = async (client) => {
|
||||
global.player = player;
|
||||
|
||||
await player.extractors.loadDefault();
|
||||
logger.trace(`[Shard ${client.shard.ids[0]}] discord-player loaded dependencies:\n${player.scanDeps()}`);
|
||||
logger.trace(`discord-player loaded dependencies:\n${player.scanDeps()}`);
|
||||
|
||||
return player;
|
||||
} catch (error) {
|
||||
logger.error(`[Shard ${client.shard.ids[0]}] Failed to create discord-player player`, error);
|
||||
logger.error(error, 'Failed to create discord-player player');
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -1,22 +1,25 @@
|
||||
const logger = require('../../services/logger');
|
||||
const https = require('node:https');
|
||||
|
||||
exports.postBotStats = async (client) => {
|
||||
exports.postBotStats = async ({ client, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'postBotStats.js',
|
||||
module: 'utilOther',
|
||||
name: 'postBotStats',
|
||||
executionId: executionId,
|
||||
shardId: client.shard.ids[0]
|
||||
});
|
||||
|
||||
try {
|
||||
if (client.shard.ids[0] !== 0) {
|
||||
return logger.debug(`[Shard ${client.shard.ids[0]}] Shard is not the first shard, not posting stats.`);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug(
|
||||
client.shard.ids,
|
||||
`[Shard ${client.shard.ids[0]}] Posting stats to bot lists from client with shard id 0.`
|
||||
);
|
||||
|
||||
let guildCount = 0;
|
||||
let memberCount = 0;
|
||||
let shardCount = client.shard.count;
|
||||
let shardId = client.shard.ids[0];
|
||||
|
||||
logger.debug('Gathering data about guild and member count from shards...');
|
||||
await client.shard
|
||||
.fetchClientValues('guilds.cache')
|
||||
.then((results) => {
|
||||
@@ -26,9 +29,11 @@ exports.postBotStats = async (client) => {
|
||||
memberCount += guildCache.reduce((acc, guildCache) => acc + guildCache.memberCount, 0);
|
||||
}
|
||||
});
|
||||
|
||||
logger.debug('Successfully fetched client values from shards');
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to fetch client values from shards.`);
|
||||
logger.error(error, 'Failed to fetch client values from shards.');
|
||||
});
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
@@ -112,7 +117,10 @@ exports.postBotStats = async (client) => {
|
||||
}
|
||||
];
|
||||
|
||||
logger.info(`[Shard ${client.shard.ids[0]}] Posting stats to bot lists with guildCount ${guildCount}...`);
|
||||
logger.info(`Starting to post bot stats with guild count ${guildCount} and member count ${memberCount}...`);
|
||||
|
||||
let statusCodes = [];
|
||||
|
||||
sites.map((site) => {
|
||||
if (site.disabled) {
|
||||
return;
|
||||
@@ -132,14 +140,18 @@ exports.postBotStats = async (client) => {
|
||||
|
||||
let request = https.request(options, (res) => {
|
||||
res.statusCode === 200
|
||||
? logger.info(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
||||
? logger.debug(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
||||
: logger.warn(`Request to ${site.hostname}: statusCode: ${res.statusCode}`);
|
||||
|
||||
statusCodes.push(res.statusCode);
|
||||
});
|
||||
|
||||
request.write(JSON.stringify(site.body));
|
||||
request.end();
|
||||
});
|
||||
|
||||
logger.info(`Successfully posted bot stats with status codes ${statusCodes.join(', ')}.`);
|
||||
} catch (error) {
|
||||
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to post stats to bot lists.`);
|
||||
logger.error(error, 'Failed to post bot stats to sites.');
|
||||
}
|
||||
};
|
||||
@@ -1,15 +1,23 @@
|
||||
const logger = require('../../services/logger');
|
||||
const config = require('config');
|
||||
const loadTestOptions = config.get('loadTestOptions');
|
||||
|
||||
exports.startLoadTest = async (client) => {
|
||||
exports.startLoadTest = async ({ client, executionId }) => {
|
||||
const logger = require('../../services/logger').child({
|
||||
source: 'startLoadTest.js',
|
||||
module: 'utilOther',
|
||||
name: 'loadTest',
|
||||
executionId: executionId,
|
||||
shardId: client.shard.ids[0]
|
||||
});
|
||||
|
||||
if (!loadTestOptions.enabled) {
|
||||
logger.debug('Load test is disabled in options, cancelling.');
|
||||
return;
|
||||
}
|
||||
|
||||
const channelIds = loadTestOptions.channelIdsToJoin;
|
||||
const track = loadTestOptions.trackUrl;
|
||||
logger.info(`Starting load test in ${channelIds.length} channels.`);
|
||||
logger.info(`Starting load test in ${channelIds.length} specified channels.`);
|
||||
|
||||
channelIds.forEach((each) => {
|
||||
client.shard.broadcastEval(
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
const logger = require('../services/logger');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { Collection } = require('discord.js');
|
||||
|
||||
exports.registerClientCommands = (client) => {
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering client commands...`);
|
||||
exports.registerClientCommands = ({ client, executionId }) => {
|
||||
const logger = require('../services/logger').child({
|
||||
source: 'registerClientCommands.js',
|
||||
module: 'register',
|
||||
name: 'registerClientCommands',
|
||||
executionId: executionId,
|
||||
shardId: client.shard.ids[0]
|
||||
});
|
||||
|
||||
logger.debug('Registering client commands...');
|
||||
client.commands = new Collection();
|
||||
|
||||
const commandFolders = fs.readdirSync(path.resolve('./src/commands'));
|
||||
for (const folder of commandFolders) {
|
||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering client commands for folder '${folder}'...`);
|
||||
logger.trace(`Registering client commands for folder '${folder}'...`);
|
||||
const commandFiles = fs
|
||||
.readdirSync(path.resolve(`./src/commands/${folder}`))
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
@@ -24,12 +31,10 @@ exports.registerClientCommands = (client) => {
|
||||
client.commands.delete(command.data.name);
|
||||
client.commands.set(command.data.name, command);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`[Shard ${client.shard.ids[0]}] Error registering command ${folder}/${file}: ${error.message}`
|
||||
);
|
||||
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering client commands complete.`);
|
||||
logger.trace('Registering client commands complete.');
|
||||
};
|
||||
@@ -1,16 +1,23 @@
|
||||
const logger = require('../services/logger');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const config = require('config');
|
||||
|
||||
const loggerOptions = config.get('loggerOptions');
|
||||
|
||||
exports.registerEventListeners = (client, player) => {
|
||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering event listeners...`);
|
||||
exports.registerEventListeners = ({ client, player, executionId }) => {
|
||||
const logger = require('../services/logger').child({
|
||||
source: 'registerEventListeners.js',
|
||||
module: 'register',
|
||||
name: 'registerEventListeners',
|
||||
executionId: executionId,
|
||||
shardId: client.shard.ids[0]
|
||||
});
|
||||
|
||||
logger.debug('Registering event listeners...');
|
||||
|
||||
const eventFolders = fs.readdirSync(path.resolve('./src/events'));
|
||||
for (const folder of eventFolders) {
|
||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering event listener for folder '${folder}'...`);
|
||||
logger.trace(`Registering event listener for folder '${folder}'...`);
|
||||
|
||||
const eventFiles = fs
|
||||
.readdirSync(path.resolve(`./src/events/${folder}`))
|
||||
@@ -52,12 +59,10 @@ exports.registerEventListeners = (client, player) => {
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.error(
|
||||
`[Shard ${client.shard.ids[0]}] Unknown event folder '${folder}' while trying to register events.`
|
||||
);
|
||||
logger.error(`Unknown event folder '${folder}' while trying to register events.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.trace(`[Shard ${client.shard.ids[0]}] Registering event listeners complete.`);
|
||||
logger.trace('Registering event listeners complete.');
|
||||
};
|
||||
Reference in new issue
Block a user