izy521 / discord.io

A small, single-file library for creating DiscordApp clients from Node.js or the browser
https://discord.gg/0MvHMfHcTKVVmIGP
MIT License
533 stars 156 forks source link

How to check if bot is streaming audio in a channel? #319

Open abdatta opened 4 years ago

abdatta commented 4 years ago

I have a music bot and it streams audio from youtube well. Now I want to detect if it is already streaming something. My current code that simply streams is this:

bot.getAudioContext(user_voice_channel_id, (err, stream) => {
                if(err) return console.log(err);

                youtube.stream(url)
                    .on('error', (err) => handleError(err))
                    .pipe(stream, {end: false});
});

where youtube.stream is just the ytdl-core library.

I know I can keep a flag that is turned true when play starts and add a stream.once('done', () => flag = false), to turn it off, but this doesn't seem to be the most robust solution. The stream object itself should have some property that can tell if it is receiving any audio already.

So..... any help would be appreciated 😄

cloudrac3r commented 4 years ago

just do the flag.

Questions belong in the server, not in GitHub issues. https://discord.gg/0MvHMfHcTKVVmIGP