From 06ead4101fb970ca42f3b5c5677c7544683ec7ea Mon Sep 17 00:00:00 2001 From: jaredthomason Date: Sun, 12 May 2024 12:28:58 -0400 Subject: [PATCH] Revert "Rather than make a new resource for each player, the bot uses one resource / connection to ClassicFM for each channel." This reverts commit 80d1baad4e364834a47234a18d0beec243cd30af. --- src/bot.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/bot.js b/src/bot.js index 96adf90..fba24f1 100644 --- a/src/bot.js +++ b/src/bot.js @@ -20,8 +20,6 @@ client.once('ready', () => { console.log('Bot is ready!'); }); -const resource = dVC.createAudioResource('https://icecast.thisisdax.com/ClassicFM', {inlineVolume: true, silencePaddingFrames: 5}); - client.on('messageCreate', async message => { if (!message.content.startsWith(prefix) || message.author.bot) return; @@ -50,14 +48,14 @@ client.on('messageCreate', async message => { const streamURL = lines[0]; console.log(`Playing stream: ${streamURL}`); - JoinChannel(voiceChannel, resource, 2); + JoinChannel(voiceChannel, 'https://icecast.thisisdax.com/ClassicFM', 2); } ) } }); let streamJob = null; -function JoinChannel(channel, resource, volume) { +function JoinChannel(channel, track, volume) { const connection = dVC.joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, @@ -82,6 +80,7 @@ function JoinChannel(channel, resource, volume) { } }); + const resource = dVC.createAudioResource(track, {inlineVolume: true, silencePaddingFrames: 5}); const player = dVC.createAudioPlayer(); resource.volume.setVolume(2); connection.subscribe(player) @@ -119,13 +118,13 @@ function JoinChannel(channel, resource, volume) { player.stop(); player.play(resource); }); - } +} - function LeaveVoiceChannel(channel) { - // Get resource, player, etc, and destroy them - const connection = dVC.getVoiceConnection(channel.guild.id); - if (connection) { - connection.destroy(); - } +function LeaveVoiceChannel(channel) { + // Get resource, player, etc, and destroy them + const connection = dVC.getVoiceConnection(channel.guild.id); + if (connection) { + connection.destroy(); } - client.login(config.token).catch(error => console.error(`Login error: ${error}`)); // Log any login errors \ No newline at end of file +} +client.login(config.token).catch(error => console.error(`Login error: ${error}`)); // Log any login errors \ No newline at end of file