Skip to content

Commit

Permalink
Make bot check if it's the only member in the channel and leave if so
Browse files Browse the repository at this point in the history
  • Loading branch information
rosetintedcheeks committed Dec 14, 2022
1 parent d5473f6 commit 4fdd0e5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ client.once('ready', () => {
const pool = mysql.createPool(database);
const player = createAudioPlayer();

/*
let last_played = Date.now(); // should hold when a sound was last played
const leave_after = ; // how long since a sound has been played should we stay
// TODO: move to config? and finish this
*/


var guild_config = [];
const query = pool.query('SELECT guild, announce_channel FROM guild_config', function (error, results, fields) {
Expand Down Expand Up @@ -158,6 +164,17 @@ scheduleJob('*/5 * * * *', function() {
//});
});

scheduleJob('*/1 * * * *', function() {
// if the bot is the only member, it should leave
const voiceConnection = getVoiceConnection(guild_config[0].guild);
if(!voiceConnection) return;
const channel = client.channels.cache.get(voiceConnection.joinConfig.channelId);
if(!channel) return;
if(channel.members.size === 1) {
voiceConnection.disconnect();
}
});

process.on('beforeExit', () => {
pool.end(function (err) {
console.log(err);
Expand Down

0 comments on commit 4fdd0e5

Please sign in to comment.