Merge pull request #278 from twlite/patch-1

fix(playerSkip): only log on error
This commit is contained in:
Marius Begby authored and GitHub committed 2023-10-29 10:13:01 +01:00
commit 3f9f73b5c3
1 file changed
+39 -31
+39 -31
View File
@@ -1,5 +1,5 @@
import config from 'config'; import config from 'config';
import { Track } from 'discord-player'; import { Track, TrackSkipReason } from 'discord-player';
import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js'; import { BaseGuildTextChannel, EmbedBuilder } from 'discord.js';
import { randomUUID as uuidv4 } from 'node:crypto'; import { randomUUID as uuidv4 } from 'node:crypto';
import { Logger } from 'pino'; import { Logger } from 'pino';
@@ -10,12 +10,18 @@ import { ExtendedGuildQueuePlayerNode } from '../../types/eventTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
const botOptions: BotOptions = config.get('botOptions'); const botOptions: BotOptions = config.get('botOptions');
const systemOptions: SystemOptions = config.get('systemOptions'); const systemOptions: SystemOptions = config.get('systemOptions');
// Emitted when the audio player fails to load the stream for a track
// Emitted when the audio player skips a track.
module.exports = { module.exports = {
name: 'playerSkip', name: 'playerSkip',
isDebug: false, isDebug: false,
isPlayerEvent: true, isPlayerEvent: true,
execute: async (queue: ExtendedGuildQueuePlayerNode, track: Track) => { execute: async (
queue: ExtendedGuildQueuePlayerNode,
track: Track,
reason: TrackSkipReason,
description: string
) => {
const executionId: string = uuidv4(); const executionId: string = uuidv4();
const logger: Logger = loggerModule.child({ const logger: Logger = loggerModule.child({
module: 'event', module: 'event',
@@ -25,35 +31,37 @@ module.exports = {
guildId: queue.metadata?.channel.guild.id guildId: queue.metadata?.channel.guild.id
}); });
logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.`); logger.debug(`Track [${track.url}] skipped with reason: ${reason}\n${description}`);
await queue.metadata?.channel.send({ if (reason === TrackSkipReason.NoStream) {
embeds: [ logger.error(`player.events.on('playerSkip'): Failed to play '${track.url}'.\n${description}`);
new EmbedBuilder() await queue.metadata?.channel.send({
.setDescription( embeds: [
`**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nIt seems there was an issue while loading stream for the track.\n\nIf you performed a command, you can try again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._` new EmbedBuilder()
) .setDescription(
.setColor(embedOptions.colors.error) `**${embedOptions.icons.error} Uh-oh... _Something_ went wrong!**\nIt seems there was an issue while loading stream for the track.\n\nIf you performed a command, you can try again.\n\n_If this problem persists, please submit a bug report in the **[support server](${botOptions.serverInviteUrl})**._`
.setFooter({ text: `Execution ID: ${executionId}` }) )
] .setColor(embedOptions.colors.error)
}); .setFooter({ text: `Execution ID: ${executionId}` })
]
if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) { });
const channel: BaseGuildTextChannel = (await queue.metadata?.client.channels.cache.get( if (systemOptions.systemMessageChannelId && systemOptions.systemUserId) {
systemOptions.systemMessageChannelId const channel: BaseGuildTextChannel = (await queue.metadata?.client.channels.cache.get(
)) as BaseGuildTextChannel; systemOptions.systemMessageChannelId
if (channel) { )) as BaseGuildTextChannel;
await channel.send({ if (channel) {
embeds: [ await channel.send({
new EmbedBuilder() embeds: [
.setDescription( new EmbedBuilder()
`${embedOptions.icons.error} **player.events.on('playerSkip')**\nExecution id: ${executionId}\n${track.url}` + .setDescription(
`\n\n<@${systemOptions.systemUserId}>` `${embedOptions.icons.error} **player.events.on('playerSkip')**\nExecution id: ${executionId}\n${track.url}` +
) `\n\n<@${systemOptions.systemUserId}>`
.setColor(embedOptions.colors.error) )
.setFooter({ text: `Execution ID: ${executionId}` }) .setColor(embedOptions.colors.error)
] .setFooter({ text: `Execution ID: ${executionId}` })
}); ]
});
}
} }
} }
} }