Example #1
0
 private static void Client_OnJoinedVoiceChannel(DiscordSocketClient client, VoiceConnectEventArgs args)
 {
     if (TrackLists.TryGetValue(args.Client.Guild.Id, out var list) && !list.Running)
     {
         list.Start();
     }
 }
Example #2
0
        private static void Client_OnJoinedVoiceChannel(DiscordSocketClient client, VoiceConnectEventArgs args)
        {
            Console.WriteLine(client.User.ToString() + " has joined " + args.Client.Channel.Id);

            // exploit that lets you speak while muted (https://www.youtube.com/watch?v=PWzPa_BIv9s)
            args.Client.Microphone.Bitrate = ((VoiceChannel)client.GetChannel(args.Client.Channel.Id)).Bitrate;
            args.Client.Microphone.SetSpeakingState(DiscordSpeakingFlags.Soundshare);

            CancellationTokenSource source = new CancellationTokenSource();

            Task.Run(() =>
            {
                while (true)
                {
                    if (GetParticipantCount(client, args.Client.Channel.Id) == 0)
                    {
                        source.Cancel();
                        if (Connect(client))
                        {
                            Console.WriteLine(client.User.ToString() + " is switching channel, due to there being noone in the current one");
                        }
                        else
                        {
                            args.Client.Disconnect();
                        }

                        return;
                    }

                    Thread.Sleep(100);
                }
            });

            while (args.Client.State == MediaConnectionState.Ready && !source.IsCancellationRequested)
            {
                args.Client.Microphone.CopyFrom(DiscordVoiceUtils.GetAudioStream(AudioPath), source.Token);
            }
        }