idk what can i do

This commit is contained in:
Loic Bersier 2018-12-09 02:13:16 +01:00
parent 9a4c84b506
commit 346874ce31
2 changed files with 11 additions and 8 deletions

1
.gitignore vendored
View file

@ -10,3 +10,4 @@ json/blacklist.json
json/customresponse.json json/customresponse.json
tag/* tag/*
tts.mp3 tts.mp3
ttsvc.mp3

View file

@ -44,13 +44,13 @@ module.exports = class ttsvcCommand extends Command {
} }
// Write the binary audio content to a local file // Write the binary audio content to a local file
fs.writeFile('tts.mp3', response.audioContent, 'binary', err => { fs.writeFile('ttsvc.mp3', response.audioContent, 'binary', err => {
if (err) { if (err) {
console.error('ERROR:', err); console.error('ERROR:', err);
message.say('An error has occured, the message is probably too long') message.say('An error has occured, the message is probably too long')
return; return;
} }
console.log('Audio content written to file: tts.mp3'); console.log('Audio content written to file: ttsvc.mp3');
const { voiceChannel } = message.member; const { voiceChannel } = message.member;
// If not in voice channel ask user to join // If not in voice channel ask user to join
@ -63,11 +63,13 @@ module.exports = class ttsvcCommand extends Command {
voiceChannel.leave() voiceChannel.leave()
message.say('I leaved the channel'); message.say('I leaved the channel');
} else } else
const dispatcher = voiceChannel.join() voiceChannel.join().then(connection => {
.then(connection => dispatcher = connection.play('./tts.mp3')) const dispatcher = connection.playStream('./ttsvc.mp3');
dispatcher.on('finish', () => { // End at then end of the audio stream
voiceChannel.leave() dispatcher.on('end', () => setTimeout(function(){
voiceChannel.leave();
}, 2000));
}); });
}); });
})}} });
}}