Reputation: 127
Djs (v12)
Maybe someone is already familiar with this problem in their code and knows the solution. After a few hours of listening, the bot just randomly stops playing music from the web by URL and leaves the voice channel.
Here's a bit of my code where the problem is hiding, thanks for any answers or solutions :-)
const commands = {
"play-join": {
process: function(message) {
if (message.content.toLowerCase() == "?play-join") {
if (message.channel.type == "dm") return;
const role = message.guild.roles.cache.find((r) => r.name === 'DJ')
if (!role) return message.reply(`**DJ** role is not created`)
if (!message.member.roles.cache.has(role.id)) return message.reply(`You need to have ${role} role.`);
var shuffle1 = Math.floor(Math.random() * connect_log.length);
const voiceChannel = message.member.voice.channel
if (voiceChannel) {
if (!client.voice.connections.some(conn => conn.channel.id == voiceChannel.id)) {
var EventEmitter = require('events');
const emitter = new EventEmitter()
emitter.setMaxListeners(0)
message.member.voice.channel.join().then(connection => {
require('http').get("http://STREM_URL", (res) => {
connection.play(res);
message.channel.send(connect_log[shuffle1]);
connection.voice.setSelfDeaf(true);
});
});
}
} else {
message.reply("Be in a Voice Channel!");
}}
}
}
}
Upvotes: 2
Views: 707
Reputation: 127
After some time, I had figured it out. If someone is having problems as I did, use stateChange and Idle event, then reconnect if the state changes from playing to Idle. Thanks for your answers guys it really helped!
Upvotes: 1
Reputation: 1880
If you're hosting your bot on Heroku you can try this:
Procfile
to your root directoryworker: node index.js
and save itworker: node index.js
, edit it so you can activate itBefore hosting my bot on a VPS I hosted it on Heroku too and following this steps made my bot never fall asleep. Hope it helps for you too :)
Upvotes: 0