Merge pull request #6 from radiantly/exit-channel

Exit channel without specifying the channel name
This commit is contained in:
Sravanth C 2020-10-27 00:58:13 +05:30 committed by GitHub
commit 5e17893079
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 16 deletions

View file

@ -31,19 +31,23 @@ exports.enter = function(msg, channelName) {
.catch(err => { throw err; }); .catch(err => { throw err; });
} }
exports.exit = function(msg, channelName) { exports.exit = function (msg) {
const voiceChannel = msg.guild.channels.cache.find(channel => channel.name === channelName); // Use optional chaining when we upgrade to Node 14.
if (
!(
msg &&
msg.guild &&
msg.guild.voice &&
msg.guild.voice.channel &&
msg.guild.voice.connection
)
)
return;
if (!voiceChannel || voiceChannel.type !== 'voice') const { channel: voiceChannel, connection: conn } = msg.guild.voice;
return msg.reply(`The channel #${channelName} doesn't exist or isn't a voice channel.`); const dispatcher = conn.play(__dirname + "/../sounds/badumtss.mp3", { volume: 0.45 });
dispatcher.on("finish", () => {
voiceChannel.join() voiceChannel.leave();
.then(conn => { console.log(`\nSTOPPED RECORDING\n`);
const dispatcher = conn.play(__dirname + '/../sounds/badumtss.mp3', { volume: 0.45 }); });
dispatcher.on('finish', () => { };
voiceChannel.leave();
console.log(`\nSTOPPED RECORDING\n`);
});
});
}

View file

@ -10,7 +10,7 @@ client.on('message', msg => {
const channelName = commandBody[1]; const channelName = commandBody[1];
if (commandBody[0] === ('enter') && commandBody[1]) commands.enter(msg, channelName); if (commandBody[0] === ('enter') && commandBody[1]) commands.enter(msg, channelName);
if (commandBody[0] === ('exit') && commandBody[1]) commands.exit(msg, channelName); if (commandBody[0] === ('exit')) commands.exit(msg);
} }
}); });