Updated bot.js

Modified the bot so that it restarts the stream every 15 minutes in the event of an error.
This commit is contained in:
jaredthomason 2024-05-09 21:54:32 -04:00
parent b4f20935ae
commit e74fc3fd99
2 changed files with 13 additions and 6 deletions

View file

@ -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) {

View file

@ -1,3 +1,3 @@
{
"token": "InsertTokenHere"
"token": "Insert-token-here"
}