private static void CreateLobby(Discord discord, LobbyManager lobbyManager)
        {
            var transaction = lobbyManager.GetLobbyCreateTransaction();

            transaction.SetCapacity(6);
            transaction.SetType(LobbyType.Public);
            //transaction.SetMetadata("a", "123");
            //transaction.SetMetadata("a", "456");
            //transaction.SetMetadata("b", "111");
            //transaction.SetMetadata("c", "222");

            lobbyManager.CreateLobby(transaction, (Result result, ref Lobby lobby) =>
            {
                if (result != Result.Ok)
                {
                    return;
                }

                var secret = lobbyManager.GetLobbyActivitySecret(lobby.Id);

                Console.WriteLine("Secret: " + secret);

                // Check the lobby's configuration.
                Console.WriteLine("lobby {0} with capacity {1} and secret {2}", lobby.Id, lobby.Capacity, lobby.Secret);

                //// Check lobby metadata.
                //foreach (var key in new string[] { "a", "b", "c" })
                //{
                //    Console.WriteLine("{0} = {1}", key, lobbyManager.GetLobbyMetadataValue(lobby.Id, key));
                //}

                // Print all the members of the lobby.
                foreach (var user in lobbyManager.GetMemberUsers(lobby.Id))
                {
                    Console.WriteLine("lobby member: {0}", user.Username);
                }

                // Send everyone a message.
                //lobbyManager.SendLobbyMessage(lobby.Id, "Hello from C#!", (_) =>
                //{
                //    Console.WriteLine("sent message");
                //});

                //// Update lobby.
                //var lobbyTransaction = lobbyManager.GetLobbyUpdateTransaction(lobby.Id);
                //lobbyTransaction.SetMetadata("d", "e");
                //lobbyTransaction.SetCapacity(16);
                //lobbyManager.UpdateLobby(lobby.Id, lobbyTransaction, (_) =>
                //{
                //    Console.WriteLine("lobby has been updated");
                //});

                //// Update a member.
                //var lobbyID = lobby.Id;
                //var userID = lobby.OwnerId;
                //var memberTransaction = lobbyManager.GetMemberUpdateTransaction(lobbyID, userID);
                //memberTransaction.SetMetadata("hello", "there");
                //lobbyManager.UpdateMember(lobbyID, userID, memberTransaction, (_) =>
                //{
                //    Console.WriteLine("lobby member has been updated: {0}", lobbyManager.GetMemberMetadataValue(lobbyID, userID, "hello"));
                //});

                //// Search lobbies.
                //var query = lobbyManager.GetSearchQuery();
                //// Filter by a metadata value.
                //query.Filter("metadata.a", LobbySearchComparison.GreaterThan, LobbySearchCast.Number, "455");
                //query.Sort("metadata.a", LobbySearchCast.Number, "0");
                //// Only return 1 result max.
                //query.Limit(1);
                //lobbyManager.Search(query, (_) =>
                //{
                //    Console.WriteLine("search returned {0} lobbies", lobbyManager.LobbyCount());
                //    if (lobbyManager.LobbyCount() == 1)
                //    {
                //        Console.WriteLine("first lobby secret: {0}", lobbyManager.GetLobby(lobbyManager.GetLobbyId(0)).Secret);
                //    }
                //});

                //lobbyManager.ConnectLobby(lobby.Id, secret, (Result result, ref Lobby lobby) =>
                //{
                //    Console.WriteLine("Connected to Lobby " + lobby.Id + " ? " + result);
                //});

                // Connect to voice chat.
                lobbyManager.ConnectVoice(lobby.Id, (_) =>
                {
                    Console.WriteLine("Connected to voice chat!");
                });

                //// Setup networking.
                //lobbyManager.ConnectNetwork(lobby.Id);
                //lobbyManager.OpenNetworkChannel(lobby.Id, 0, true);

                UpdateActivity(discord);

                discord.GetOverlayManager().OpenVoiceSettings((result) =>
                {
                    if (result == Result.Ok)
                    {
                        Console.WriteLine("Overlay is open to the voice settings for your application/");
                    }
                });
            });
        }
    void connect()
    {
        System.Environment.SetEnvironmentVariable("DISCORD_INSTANCE_ID", "0");
        //System.Environment.SetEnvironmentVariable("DISCORD_INSTANCE_ID", "1");
        discord = new Discord.Discord(AppClientId, (System.UInt64)Discord.CreateFlags.Default);
        UserManager userManager = discord.GetUserManager();

        userManager.OnCurrentUserUpdate += () => {
            var currentUser = userManager.GetCurrentUser();
            userLabel.text = currentUser.Username;
            disconnectButton.interactable       = true;
            updateStateInput.interactable       = true;
            updateDetailInput.interactable      = true;
            updateButton.interactable           = true;
            clearButton.interactable            = true;
            dropDownFriends.interactable        = true;
            inviteToJoinButton.interactable     = true;
            inviteToSpectateButton.interactable = true;
        };

        var relationshipManager = discord.GetRelationshipManager();

        // Assign this handle right away to get the initial relationships update.
        // This callback will only be fired when the whole list is initially loaded or was reset

        // Wait for OnRefresh to fire to access a stable list
        // Filter a user's relationship list to be just friends
        // Use this list as your base
        relationships = new List <Relationship>();
        relationshipManager.OnRefresh += () => {
            relationshipManager.Filter((ref Relationship relationship) => {
                return(relationship.Type == Discord.RelationshipType.Friend);
            });

            // Loop over all friends a user has.
            List <Dropdown.OptionData> options = new List <Dropdown.OptionData>();
            for (var i = 0; i < relationshipManager.Count(); i++)
            {
                // Get an individual relationship from the list
                var r = relationshipManager.GetAt((uint)i);
                relationships.Add(r);

                Dropdown.OptionData option = new Dropdown.OptionData();
                option.text = r.User.Username;
                options.Add(option);
            }
            dropDownFriends.AddOptions(options);
        };

        var activityManager = discord.GetActivityManager();

        LobbyManager lobbyManager = discord.GetLobbyManager();

        // Received when someone accepts a request to join or invite.
        // Use secrets to receive back the information needed to add the user to the group/party/match
        activityManager.OnActivityJoin += secret => {
            Debug.Log("OnJoin " + secret);
            lobbyManager.ConnectLobbyWithActivitySecret(secret, (Discord.Result result, ref Discord.Lobby lobby) => {
                Debug.Log("Connected to lobby: " + lobby.Id);
                // Connect to voice chat, used in this case to actually know in overlay if your successful in connecting.
                lobbyManager.ConnectVoice(lobby.Id, (Discord.Result voiceResult) => {
                    if (voiceResult == Discord.Result.Ok)
                    {
                        Debug.Log("New User Connected to Voice! Say Hello! Result: " + voiceResult);
                    }
                    else
                    {
                        Debug.Log("Failed with Result: " + voiceResult);
                    };
                });
                //Connect to given lobby with lobby Id
                lobbyManager.ConnectNetwork(lobby.Id);
                lobbyManager.OpenNetworkChannel(lobby.Id, 0, true);
                foreach (var user in lobbyManager.GetMemberUsers(lobby.Id))
                {
                    //Send a hello message to everyone in the lobby
                    lobbyManager.SendNetworkMessage(lobby.Id, user.Id, 0,
                                                    Encoding.UTF8.GetBytes(string.Format("Hello, " + user.Username + "!")));
                }
                //Sends this off to a Activity callback named here as 'UpdateActivity' passing in the discord instance details and lobby details
                UpdateActivity(discord, lobby);
            });
        };

        void UpdateActivity(Discord.Discord discord, Discord.Lobby lobby)
        {
            //Creates a Static String for Spectate Secret.
            string discordSpectateSecret  = "wdn3kvj320r8vk3";
            string spectateActivitySecret = discordSpectateSecret;
            var    activity1 = new Discord.Activity
            {
                State   = "Playing Co-Op",
                Details = "In a Multiplayer Match!",

                Assets =
                {
                    LargeImage = "matchimage1",
                    LargeText  = "Inside the Arena!",
                },
                Party =
                {
                    Id   = lobby.Id.ToString(),
                    Size =
                    {
                        CurrentSize = lobbyManager.MemberCount(lobby.Id),
                        MaxSize     = (int)lobby.Capacity,
                    },
                },
                Secrets =
                {
                    Spectate = spectateActivitySecret,
                    Join     = "123",
                },
                Instance = true,
            };

            activityManager.UpdateActivity(activity1, result => {
                Debug.Log("Updated to Multiplayer Activity: " + result);

                // Send an invite to another user for this activity.
                // Receiver should see an invite in their DM.
                // Use a relationship user's ID for this.
                // activityManager
                //   .SendInvite(
                //       364843917537050624,
                //       Discord.ActivityActionType.Join,
                //       "",
                //       inviteResult =>
                //       {
                //           Console.WriteLine("Invite {0}", inviteResult);
                //       }
                //   );
            });
        }

        statusLabel.text = "Connected.";
    }