title: Discord Bot (C#) Problems Joining Voice Channel
body: <p>I have a problem with my bot joining voice channel.</p>
  
  <p>Code:</p>
  
  <pre><code>    using Discord;
      using Discord.Commands;
      using Discord.Audio;
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
  
      namespace DodoBot
      {
          class MyBot
          {
              DiscordClient discord;
              CommandService commands;
              Random rand;
              string[] cats = new string[]
              {
                  "cate.jpg",
                  "gut.jpg",
                  "meh.jpg",
                  "ugly.jpg",
                  "wow.jpg",
              };
  
              public MyBot()
              {
                  rand = new Random();
                  discord = new DiscordClient(x =&gt;
                  {
                      x.LogLevel = LogSeverity.Info;
                      x.LogHandler = Log;
                  });
  
                  discord.UsingCommands(x =&gt;
                  {
                      x.PrefixChar = '!';
                      x.AllowMentionPrefix = true;
                  });
  
                  commands = discord.GetService&lt;CommandService&gt;();
  
                  RegisterHiCommand();
                  RegisterCatdCommand();
                  RegisterCatCommand();
  
                  OnJoin();
                  OnLeave();
  
                  discord.UsingAudio(x =&gt;
                  {
                      x.Mode = AudioMode.Outgoing;
                      RegisterJoinVoiceCommand();
                  });
  
                  discord.ExecuteAndWait(async () =&gt;
                  {
                      await discord.Connect("MyToken", TokenType.Bot);
                  });
              }
  
              private void RegisterJoinVoiceCommand()
              {
                  commands.CreateCommand("summon")
                      .Do(async (e) =&gt;
                      {
                          await e.Channel.SendMessage("```Joining masta!```");
                          await discord.GetService&lt;AudioService&gt;().Join(discord.FindServers("VoiceChannel").FirstOrDefault().VoiceChannels.FirstOrDefault());
                      });
              }
  
              private void RegisterCatdCommand()
              {
                  commands.CreateCommand("catd")
                      .Do(async (e) =&gt;
                      {
                          Message[] msg2Del;
                          msg2Del = await e.Channel.DownloadMessages(1);
                          await e.Channel.DeleteMessages(msg2Del);
                          int imgIndex = rand.Next(cats.Length);
                          await e.Channel.SendFile("Cats/"+cats[imgIndex]);
                      });
              }
              private void RegisterCatCommand()
              {
                  commands.CreateCommand("cat")
                      .Do(async (e) =&gt;
                      {
                          int imgIndex = rand.Next(cats.Length);
                          await e.Channel.SendFile("Cats/" + cats[imgIndex]);
                      });
              }
              private void RegisterHiCommand()
              {
                  commands.CreateCommand("hi")
                      .Do(async (e) =&gt;
                      {
                          await e.Channel.SendMessage("HelloWorld!");
                      });
              }
  
              private void OnJoin()
              {
                  discord.UserJoined += async (s, e) =&gt;
                  {
                      var channel = e.Server.FindChannels("general").FirstOrDefault();
                      var user = e.User.Name;
                      await channel.SendMessage(string.Format("@"+user + " has joined!"));
                  };
              }
  
              private void OnLeave()
              {
                  discord.UserLeft += async (s, e) =&gt;
                  {
                      var channel = e.Server.FindChannels("general").FirstOrDefault();
                      var user = e.User.Name;
                      await channel.SendMessage(string.Format("@"+user + " has left!"));
                  };
              }
  
              private void Log(object sender, LogMessageEventArgs e)
              {
                  Console.WriteLine(e.Message);
              }
          }
      }
  </code></pre>
  
  <p>I've done everything like it's written in the documentation <a href="http://rtd.discord.foxbot.me/en/legacy/features/voice.html#joining-a-channel" rel="nofollow noreferrer">here</a>.</p>
  
  <p>It executes the SendMessange command but it doesn't join the voice channel. </p>
  
  <p>But Visual Studio says: 
  <a href="https://i.stack.imgur.com/GAJfR.png" rel="nofollow noreferrer">here</a>. </p>
  
  <p>Did I make a mistake? </p>
  
  <p>Thank you for your answers.</p>