From c4b5d59033977c2fe6a471b5049498f6b666309e Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Wed, 30 Aug 2023 10:34:22 +1000 Subject: [PATCH] Add dedicated class for music module --- src/helpers/MessageTool.ts | 6 ++++++ src/index.ts | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/helpers/MessageTool.ts b/src/helpers/MessageTool.ts index 6c1400b..18c0fff 100644 --- a/src/helpers/MessageTool.ts +++ b/src/helpers/MessageTool.ts @@ -1,6 +1,12 @@ import Discord from 'discord.js'; export default class MessageTool { + static embedMusic(color:Discord.ColorResolvable, title:string, thumbnail?:string, footer?:string){ + const embed = new Discord.EmbedBuilder().setColor(color).setTitle(title); + if (thumbnail) embed.setThumbnail(thumbnail); + if (footer) embed.setFooter({text: footer}); + return embed + } static embedStruct(color:Discord.ColorResolvable, title:string, description?:string|null, image?:string|null){ const embed = new Discord.EmbedBuilder().setColor(color).setTitle(title); if (description) embed.setDescription(description); diff --git a/src/index.ts b/src/index.ts index 3a073f8..b0b96ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,13 +25,13 @@ client.on('error', (error: Error)=>DZ(error, 'clientError')); // Audio Player event handling if (client.config.botSwitches.music){ - player.events.on('playerStart', (queue,track)=>queue.channel.send({embeds:[MessageTool.embedStruct(client.config.embedColor, `Next up: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]})); - player.events.on('audioTrackAdd', (queue,track)=>queue.channel.send({embeds:[MessageTool.embedStruct(client.config.embedColorGreen, `Added: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]})); - player.events.on('audioTrackRemove', (queue, track)=>queue.channel.send({embeds:[MessageTool.embedStruct(client.config.embedColor, `Removed: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]})); + player.events.on('playerStart', (queue,track)=>queue.channel.send({embeds:[MessageTool.embedMusic(client.config.embedColor, `Next up: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]})); + player.events.on('audioTrackAdd', (queue,track)=>queue.channel.send({embeds:[MessageTool.embedMusic(client.config.embedColorGreen, `Added: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]})); + player.events.on('audioTrackRemove', (queue, track)=>queue.channel.send({embeds:[MessageTool.embedMusic(client.config.embedColor, `Removed: ${track.raw.title} - ${track.raw.author}`,track.raw.thumbnail)]})); player.events.on('emptyQueue', queue=>{ if (queue.tracks.size < 1) return queue.channel.send('There\'s no songs left in the queue, leaving voice channel in 15 seconds.').then(()=>setTimeout(()=>queue.connection.disconnect(), 15000)) }); - player.events.on('playerPause', queue=>queue.channel.send({embeds:[MessageTool.embedStruct(client.config.embedColor, 'Player has been paused.\nRun the command to unpause it')]})); + player.events.on('playerPause', queue=>queue.channel.send({embeds:[MessageTool.embedMusic(client.config.embedColor, 'Player has been paused.\nRun the command to unpause it')]})); player.events.on('playerError', (queue, error)=>DZ(error, 'playerError')); // I don't know if both of these actually works, because most player.events.on('error', (queue, error)=>DZ(error, 'playerInternalError')); // errors from the player is coming from unhandledRejection }