Exit channel without specifying it
This commit is contained in:
parent
210496a9fb
commit
6f122f5060
|
@ -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`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
2
index.js
2
index.js
|
@ -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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue