This commit is contained in:
Supositware 2019-01-18 22:44:16 +01:00
parent 066be8915e
commit 2bd536aa85

View file

@ -25,7 +25,6 @@ class TtsvcCommand extends Command {
}
async exec(message, args) {
try {
let text = args.text;
// Construct the request
@ -54,21 +53,20 @@ class TtsvcCommand extends Command {
}
console.log('Audio content written to file: ttsvc.mp3');
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
const dispatcher = connection.playFile('../../ttsvc.mp3');
dispatcher.on('finish', () => {
dispatcher.destroy();
});
} else {
message.reply('You need to join a voice channel first!');
}
});
});
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.say('Please enter a voice channel first.');
try {
const connection = await voiceChannel.join();
const dispatcher = connection.play('../../ttsvc.mp3');
dispatcher.once('finish', () => voiceChannel.leave());
dispatcher.once('error', () => voiceChannel.leave());
return null;
} catch (err) {
console.error(err);
voiceChannel.leave();
return message.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
});
});
}
}
module.exports = TtsvcCommand;