From e74fc3fd99b665c6da0518196de0987d00f08993 Mon Sep 17 00:00:00 2001 From: jaredthomason <66704967+jaredthomason1991@users.noreply.github.com> Date: Thu, 9 May 2024 21:54:32 -0400 Subject: [PATCH] Updated bot.js Modified the bot so that it restarts the stream every 15 minutes in the event of an error. --- src/bot.js | 17 ++++++++++++----- src/config.json | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bot.js b/src/bot.js index a5edc68..7d78539 100644 --- a/src/bot.js +++ b/src/bot.js @@ -18,10 +18,6 @@ const prefix = '!'; client.once('ready', () => { console.log('Bot is ready!'); - cron.schedule('0 0 * * *', () => { - console.log('Restarting bot...'); - process.exit(); - }); }); client.on('messageCreate', async message => { @@ -57,6 +53,8 @@ client.on('messageCreate', async message => { ) } }); +let streamJob = null; + function JoinChannel(channel, track, volume) { const connection = dVC.joinVoiceChannel({ channelId: channel.id, @@ -65,7 +63,6 @@ function JoinChannel(channel, track, volume) { selfDeaf: true }); - const resource = dVC.createAudioResource(track, {inlineVolume: true, silencePaddingFrames: 5}); const player = dVC.createAudioPlayer(); resource.volume.setVolume(2); @@ -94,6 +91,16 @@ function JoinChannel(channel, track, volume) { player.on('idle', () => { connection.destroy(); }) + + // Schedule a cron job to restart the stream every 15 minutes + if (streamJob) { + streamJob.stop(); + } + streamJob = cron.schedule('*/15 * * * *', () => { + console.log('Restarting stream...'); + player.stop(); + player.play(resource); + }); } function LeaveVoiceChannel(channel) { diff --git a/src/config.json b/src/config.json index f237fe0..ff3d4ae 100644 --- a/src/config.json +++ b/src/config.json @@ -1,3 +1,3 @@ { - "token": "InsertTokenHere" + "token": "Insert-token-here" } \ No newline at end of file