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:
parent
b4f20935ae
commit
e74fc3fd99
17
src/bot.js
17
src/bot.js
|
@ -18,10 +18,6 @@ const prefix = '!';
|
||||||
|
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
console.log('Bot is ready!');
|
console.log('Bot is ready!');
|
||||||
cron.schedule('0 0 * * *', () => {
|
|
||||||
console.log('Restarting bot...');
|
|
||||||
process.exit();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('messageCreate', async message => {
|
client.on('messageCreate', async message => {
|
||||||
|
@ -57,6 +53,8 @@ client.on('messageCreate', async message => {
|
||||||
) }
|
) }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let streamJob = null;
|
||||||
|
|
||||||
function JoinChannel(channel, track, volume) {
|
function JoinChannel(channel, track, volume) {
|
||||||
const connection = dVC.joinVoiceChannel({
|
const connection = dVC.joinVoiceChannel({
|
||||||
channelId: channel.id,
|
channelId: channel.id,
|
||||||
|
@ -65,7 +63,6 @@ function JoinChannel(channel, track, volume) {
|
||||||
selfDeaf: true
|
selfDeaf: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const resource = dVC.createAudioResource(track, {inlineVolume: true, silencePaddingFrames: 5});
|
const resource = dVC.createAudioResource(track, {inlineVolume: true, silencePaddingFrames: 5});
|
||||||
const player = dVC.createAudioPlayer();
|
const player = dVC.createAudioPlayer();
|
||||||
resource.volume.setVolume(2);
|
resource.volume.setVolume(2);
|
||||||
|
@ -94,6 +91,16 @@ function JoinChannel(channel, track, volume) {
|
||||||
player.on('idle', () => {
|
player.on('idle', () => {
|
||||||
connection.destroy();
|
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) {
|
function LeaveVoiceChannel(channel) {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"token": "InsertTokenHere"
|
"token": "Insert-token-here"
|
||||||
}
|
}
|
Loading…
Reference in a new issue