Guest User

Untitled

a guest
Nov 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. function generateOutputFile(channel, member) {
  2. // use IDs instead of username cause some people have stupid emojis in their name
  3. const fileName = `./recordings/${channel.id}-${member.id}-${Date.now()}.pcm`;
  4. return fs.createWriteStream(fileName);
  5. }
  6.  
  7. client.on('message', message => {
  8. // Voice only works in guilds, if the message does not come from a guild,
  9. // we ignore it
  10. if (!message.guild) return;
  11.  
  12. if (message.content === '/stream') {
  13. // Only try to join the sender's voice channel if they are in one themselves
  14.  
  15. const voiceChannel = message.member.voiceChannel;
  16.  
  17. if (message.member.voiceChannel) {
  18. message.member.voiceChannel.join()
  19. .then(connection => { // Connection is an instance of VoiceConnection
  20. const receiver = connection.createReceiver();
  21.  
  22. connection.on('speaking', (user, speaking) => {
  23. if (speaking) {
  24. // this creates a 16-bit signed PCM, stereo 48KHz PCM stream.
  25. const audioStream = receiver.createPCMStream(user);
  26. // create an output stream so we can dump our data in a file
  27. const outputStream = generateOutputFile(voiceChannel, user);
  28. // pipe our audio data into the file stream
  29. audioStream.pipe(outputStream);
  30. outputStream.on("data", console.log);
  31. // when the stream ends (the user stopped talking) tell the user
  32. audioStream.on('end', () => {});
  33. }
  34. })
  35.  
  36. message.reply('Я тут, напишите /start, когда будете готовы начать!');
  37. })
  38. .catch(console.log);
  39. } else {
  40. message.reply('Сначала вы должны присоединиться к каналу!');
  41. }
  42. }
  43. })
  44.  
  45. client.login(token);
Add Comment
Please, Sign In to add comment