Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. const Discord = require("discord.js")
  2. const fs = require('fs');
  3. const botconfig = require("./botconfig.json");
  4.  
  5. module.exports.run = async (bot, message, args) => {
  6. // make a new stream for each time someone starts to talk
  7. function generateOutputFile(channel, member) {
  8. // use IDs instead of username cause some people have stupid emojis in their name
  9. const fileName = `./recordings/${channel.id}-${member.id}-${Date.now()}.pcm`;
  10. return fs.createWriteStream(fileName);
  11. }
  12.  
  13. if botconfig.prefix+'join' {
  14. let [command, ...channelName] = msg.content.split(" ");
  15. if (!message.guild) {;
  16. return message.reply('no private service is available in your area at the moment. Please contact a service representative for more details.');
  17. }
  18. const voiceChannel = message.guild.channels.find("name", channelName.join(" "));
  19. //console.log(voiceChannel.id);
  20. if (!voiceChannel || voiceChannel.type !== 'voice') {
  21. return message.reply(`I couldn't find the channel ${channelName}. Can you spell?`);
  22. }
  23. voiceChannel.join()
  24. .then(conn => {
  25. message.reply('ready!');
  26. // create our voice receiver
  27. const receiver = conn.createReceiver();
  28.  
  29. conn.on('speaking', (user, speaking) => {
  30. if (speaking) {
  31. message.channel.sendMessage(`I'm listening to ${user}`);
  32. // this creates a 16-bit signed PCM, stereo 48KHz PCM stream.
  33. const audioStream = receiver.createPCMStream(user);
  34. // create an output stream so we can dump our data in a file
  35. const outputStream = generateOutputFile(voiceChannel, user);
  36. // pipe our audio data into the file stream
  37. audioStream.pipe(outputStream);
  38. outputStream.on("data", console.log);
  39. // when the stream ends (the user stopped talking) tell the user
  40. audioStream.on('end', () => {
  41. message.channel.sendMessage(`I'm no longer listening to ${user}`);
  42. });
  43. }
  44. });
  45. })
  46. .catch(console.log);
  47. }
  48. if(message.content.startsWith(botconfig.prefix+'leave')) {
  49. let [command, ...channelName] = msg.content.split(" ");
  50. let voiceChannel = msg.guild.channels.find("name", channelName.join(" "));
  51. voiceChannel.leave();
  52. }
  53. }
  54.  
  55.  
  56. module.exports.help = {
  57. name: "join"
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement