Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js")
- const fs = require('fs');
- const botconfig = require("./botconfig.json");
- module.exports.run = async (bot, message, args) => {
- // make a new stream for each time someone starts to talk
- function generateOutputFile(channel, member) {
- // use IDs instead of username cause some people have stupid emojis in their name
- const fileName = `./recordings/${channel.id}-${member.id}-${Date.now()}.pcm`;
- return fs.createWriteStream(fileName);
- }
- if botconfig.prefix+'join' {
- let [command, ...channelName] = msg.content.split(" ");
- if (!message.guild) {;
- return message.reply('no private service is available in your area at the moment. Please contact a service representative for more details.');
- }
- const voiceChannel = message.guild.channels.find("name", channelName.join(" "));
- //console.log(voiceChannel.id);
- if (!voiceChannel || voiceChannel.type !== 'voice') {
- return message.reply(`I couldn't find the channel ${channelName}. Can you spell?`);
- }
- voiceChannel.join()
- .then(conn => {
- message.reply('ready!');
- // create our voice receiver
- const receiver = conn.createReceiver();
- conn.on('speaking', (user, speaking) => {
- if (speaking) {
- message.channel.sendMessage(`I'm listening to ${user}`);
- // this creates a 16-bit signed PCM, stereo 48KHz PCM stream.
- const audioStream = receiver.createPCMStream(user);
- // create an output stream so we can dump our data in a file
- const outputStream = generateOutputFile(voiceChannel, user);
- // pipe our audio data into the file stream
- audioStream.pipe(outputStream);
- outputStream.on("data", console.log);
- // when the stream ends (the user stopped talking) tell the user
- audioStream.on('end', () => {
- message.channel.sendMessage(`I'm no longer listening to ${user}`);
- });
- }
- });
- })
- .catch(console.log);
- }
- if(message.content.startsWith(botconfig.prefix+'leave')) {
- let [command, ...channelName] = msg.content.split(" ");
- let voiceChannel = msg.guild.channels.find("name", channelName.join(" "));
- voiceChannel.leave();
- }
- }
- module.exports.help = {
- name: "join"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement