Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- client.on('message', message => {
- // Voice only works in guilds, if the message does not come from a guild,
- // we ignore it
- if (!message.guild) return;
- if (message.content === '/stream') {
- // Only try to join the sender's voice channel if they are in one themselves
- const voiceChannel = message.member.voiceChannel;
- if (message.member.voiceChannel) {
- message.member.voiceChannel.join()
- .then(connection => { // Connection is an instance of VoiceConnection
- const receiver = connection.createReceiver();
- connection.on('speaking', (user, speaking) => {
- if (speaking) {
- // 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.reply('Я тут, напишите /start, когда будете готовы начать!');
- })
- .catch(console.log);
- } else {
- message.reply('Сначала вы должны присоединиться к каналу!');
- }
- }
- })
- client.login(token);
Add Comment
Please, Sign In to add comment