//REST methods
        internal async Task <DiscordApplicationCommand> CreateCommandAsync(CommandCreatePayload pld, ulong?guildid)
        {
            string route;

            if (guildid == null)
            {
                route = $"/applications/{Client.CurrentApplication.Id}/commands";
            }
            else
            {
                route = $"/applications/{Client.CurrentApplication.Id}/guilds/{guildid}/commands";
            }

            var bucket = Client.ApiClient.Rest.GetBucket(RestRequestMethod.POST, route, new { }, out var path);

            var url = Utilities.GetApiUriFor(path);
            var res = await Client.ApiClient.DoRequestAsync(Client, bucket, url, RestRequestMethod.POST, route, payload : DiscordJson.SerializeObject(pld));

            var ret = JsonConvert.DeserializeObject <DiscordApplicationCommand>(res.Response);

            ret.Discord = Client;

            return(ret);
        }
        private void RegisterCommands(Type t, ulong?guildid)
        {
            CommandMethod[]   InternalCommandMethods   = Array.Empty <CommandMethod>();
            GroupCommand[]    InternalGroupCommands    = Array.Empty <GroupCommand>();
            SubGroupCommand[] InternalSubGroupCommands = Array.Empty <SubGroupCommand>();

            Client.Ready += (s, e) =>
            {
                _ = Task.Run(async() =>
                {
                    try
                    {
                        List <CommandCreatePayload> ToUpdate = new List <CommandCreatePayload>();

                        var ti = t.GetTypeInfo();

                        var classes = ti.DeclaredNestedTypes;
                        foreach (var tti in classes.Where(x => x.GetCustomAttribute <SlashCommandGroupAttribute>() != null))
                        {
                            var groupatt   = tti.GetCustomAttribute <SlashCommandGroupAttribute>();
                            var submethods = tti.DeclaredMethods;
                            var subclasses = tti.DeclaredNestedTypes;
                            if (subclasses.Any(x => x.GetCustomAttribute <SlashCommandGroupAttribute>() != null) && submethods.Any(x => x.GetCustomAttribute <SlashCommandAttribute>() != null))
                            {
                                throw new ArgumentException("Slash command groups cannot have both subcommands and subgroups!");
                            }
                            var payload = new CommandCreatePayload
                            {
                                Name        = groupatt.Name,
                                Description = groupatt.Description
                            };
                            var commandmethods = new Dictionary <string, MethodInfo>();
                            foreach (var submethod in submethods.Where(x => x.GetCustomAttribute <SlashCommandAttribute>() != null))
                            {
                                var commandattribute = submethod.GetCustomAttribute <SlashCommandAttribute>();
                                var subpayload       = new DiscordApplicationCommandOption(commandattribute.Name, commandattribute.Description);

                                var parameters = submethod.GetParameters();
                                if (!ReferenceEquals(parameters.First().ParameterType, typeof(InteractionContext)))
                                {
                                    throw new ArgumentException($"The first argument must be an InteractionContext!");
                                }
                                parameters = parameters.Skip(1).ToArray();
                                foreach (var parameter in parameters)
                                {
                                    var optionattribute = parameter.GetCustomAttribute <OptionAttribute>();
                                    if (optionattribute == null)
                                    {
                                        throw new ArgumentException("Arguments must have the Option attribute!");
                                    }

                                    var type = parameter.ParameterType;
                                    ApplicationCommandOptionType parametertype;
                                    if (ReferenceEquals(type, typeof(string)))
                                    {
                                        parametertype = ApplicationCommandOptionType.String;
                                    }
                                    else if (ReferenceEquals(type, typeof(long)))
                                    {
                                        parametertype = ApplicationCommandOptionType.Integer;
                                    }
                                    else if (ReferenceEquals(type, typeof(bool)))
                                    {
                                        parametertype = ApplicationCommandOptionType.Boolean;
                                    }
                                    else if (ReferenceEquals(type, typeof(DiscordChannel)))
                                    {
                                        parametertype = ApplicationCommandOptionType.Channel;
                                    }
                                    else if (ReferenceEquals(type, typeof(DiscordUser)))
                                    {
                                        parametertype = ApplicationCommandOptionType.User;
                                    }
                                    else if (ReferenceEquals(type, typeof(DiscordRole)))
                                    {
                                        parametertype = ApplicationCommandOptionType.Role;
                                    }
                                    else
                                    {
                                        throw new ArgumentException("Cannot convert type! Argument types must be string, long, bool, DiscordChannel, DiscordUser or DiscordRole.");
                                    }

                                    DiscordApplicationCommandOptionChoice[] choices = null;
                                    var choiceattributes = parameter.GetCustomAttributes <ChoiceAttribute>();
                                    if (choiceattributes.Any())
                                    {
                                        choices = Array.Empty <DiscordApplicationCommandOptionChoice>();
                                        foreach (var att in choiceattributes)
                                        {
                                            choices = choices.Append(new DiscordApplicationCommandOptionChoice(att.Name, att.Value)).ToArray();
                                        }
                                    }

                                    var list = subpayload.Options?.ToList() ?? new List <DiscordApplicationCommandOption>();

                                    list.Add(new DiscordApplicationCommandOption(optionattribute.Name, optionattribute.Description)
                                    {
                                        Required = !parameter.IsOptional,
                                        Type     = parametertype,
                                        Choices  = choices
                                    });

                                    subpayload.Options = list;
                                }

                                commandmethods.Add(commandattribute.Name, submethod);

                                payload.Options.Add(new DiscordApplicationCommandOption(commandattribute.Name, commandattribute.Description)
                                {
                                    Required = null,
                                    Options  = subpayload.Options,
                                    Type     = ApplicationCommandOptionType.SubCommand
                                });

                                InternalGroupCommands = InternalGroupCommands.Append(new GroupCommand {
                                    Name = groupatt.Name, ParentClass = tti, Methods = commandmethods
                                }).ToArray();
                            }
                            foreach (var subclass in subclasses.Where(x => x.GetCustomAttribute <SlashCommandGroupAttribute>() != null))
                            {
                                var subgroupatt   = subclass.GetCustomAttribute <SlashCommandGroupAttribute>();
                                var subsubmethods = subclass.DeclaredMethods.Where(x => x.GetCustomAttribute <SlashCommandAttribute>() != null);

                                var command = new SubGroupCommand {
                                    Name = groupatt.Name
                                };

                                var subpayload = new DiscordApplicationCommandOption(subgroupatt.Name, subgroupatt.Description)
                                {
                                    Required = null,
                                    Type     = ApplicationCommandOptionType.SubCommandGroup,
                                    Options  = new List <DiscordApplicationCommandOption>()
                                };

                                foreach (var subsubmethod in subsubmethods)
                                {
                                    var commatt       = subsubmethod.GetCustomAttribute <SlashCommandAttribute>();
                                    var subsubpayload = new DiscordApplicationCommandOption(commatt.Name, commatt.Description)
                                    {
                                        Type = ApplicationCommandOptionType.SubCommand,
                                    };
                                    var parameters = subsubmethod.GetParameters();
                                    if (!ReferenceEquals(parameters.First().ParameterType, typeof(InteractionContext)))
                                    {
                                        throw new ArgumentException($"The first argument must be an InteractionContext!");
                                    }
                                    parameters = parameters.Skip(1).ToArray();
                                    foreach (var parameter in parameters)
                                    {
                                        var optionattribute = parameter.GetCustomAttribute <OptionAttribute>();
                                        if (optionattribute == null)
                                        {
                                            throw new ArgumentException("Arguments must have the Option attribute!");
                                        }

                                        var type = parameter.ParameterType;
                                        ApplicationCommandOptionType parametertype;
                                        if (ReferenceEquals(type, typeof(string)))
                                        {
                                            parametertype = ApplicationCommandOptionType.String;
                                        }
                                        else if (ReferenceEquals(type, typeof(long)))
                                        {
                                            parametertype = ApplicationCommandOptionType.Integer;
                                        }
                                        else if (ReferenceEquals(type, typeof(bool)))
                                        {
                                            parametertype = ApplicationCommandOptionType.Boolean;
                                        }
                                        else if (ReferenceEquals(type, typeof(DiscordChannel)))
                                        {
                                            parametertype = ApplicationCommandOptionType.Channel;
                                        }
                                        else if (ReferenceEquals(type, typeof(DiscordUser)))
                                        {
                                            parametertype = ApplicationCommandOptionType.User;
                                        }
                                        else if (ReferenceEquals(type, typeof(DiscordRole)))
                                        {
                                            parametertype = ApplicationCommandOptionType.Role;
                                        }
                                        else
                                        {
                                            throw new ArgumentException("Cannot convert type! Argument types must be string, long, bool, DiscordChannel, DiscordUser or DiscordRole.");
                                        }

                                        DiscordApplicationCommandOptionChoice[] choices = null;
                                        var choiceattributes = parameter.GetCustomAttributes <ChoiceAttribute>();
                                        if (choiceattributes.Any())
                                        {
                                            choices = Array.Empty <DiscordApplicationCommandOptionChoice>();
                                            foreach (var att in choiceattributes)
                                            {
                                                choices = choices.Append(new DiscordApplicationCommandOptionChoice(att.Name, att.Value)).ToArray();
                                            }
                                        }

                                        var list = subsubpayload.Options?.ToList() ?? new List <DiscordApplicationCommandOption>();

                                        list.Add(new DiscordApplicationCommandOption(optionattribute.Name, optionattribute.Description)
                                        {
                                            Required = !parameter.IsOptional,
                                            Type     = parametertype,
                                            Choices  = choices
                                        });

                                        subsubpayload.Options = list;
                                    }
                                    subpayload.Options = subpayload.Options.ToArray().Append(subsubpayload).ToList();
                                    commandmethods.Add(commatt.Name, subsubmethod);
                                }
                                command.SubCommands.Add(new GroupCommand {
                                    Name = subgroupatt.Name, ParentClass = subclass, Methods = commandmethods
                                });
                                InternalSubGroupCommands = InternalSubGroupCommands.Append(command).ToArray();
                                payload.Options.Add(subpayload);
                            }
                            ToUpdate.Add(payload);
                        }

                        var methods = ti.DeclaredMethods;
                        foreach (var method in methods.Where(x => x.GetCustomAttribute <SlashCommandAttribute>() != null))
                        {
                            var commandattribute = method.GetCustomAttribute <SlashCommandAttribute>();
                            var payload          = new CommandCreatePayload
                            {
                                Name        = commandattribute.Name,
                                Description = commandattribute.Description
                            };

                            var parameters = method.GetParameters();
                            if (!ReferenceEquals(parameters.First().ParameterType, typeof(InteractionContext)))
                            {
                                throw new ArgumentException($"The first argument must be an InteractionContext!");
                            }
                            parameters = parameters.Skip(1).ToArray();
                            foreach (var parameter in parameters)
                            {
                                var optionattribute = parameter.GetCustomAttribute <OptionAttribute>();
                                if (optionattribute == null)
                                {
                                    throw new ArgumentException("Arguments must have the SlashOption attribute!");
                                }

                                var type = parameter.ParameterType;
                                ApplicationCommandOptionType parametertype;
                                if (ReferenceEquals(type, typeof(string)))
                                {
                                    parametertype = ApplicationCommandOptionType.String;
                                }
                                else if (ReferenceEquals(type, typeof(long)))
                                {
                                    parametertype = ApplicationCommandOptionType.Integer;
                                }
                                else if (ReferenceEquals(type, typeof(bool)))
                                {
                                    parametertype = ApplicationCommandOptionType.Boolean;
                                }
                                else if (ReferenceEquals(type, typeof(DiscordChannel)))
                                {
                                    parametertype = ApplicationCommandOptionType.Channel;
                                }
                                else if (ReferenceEquals(type, typeof(DiscordUser)))
                                {
                                    parametertype = ApplicationCommandOptionType.User;
                                }
                                else if (ReferenceEquals(type, typeof(DiscordRole)))
                                {
                                    parametertype = ApplicationCommandOptionType.Role;
                                }
                                else
                                {
                                    throw new ArgumentException($"Cannot convert type! Argument types must be string, long, bool, DiscordChannel, DiscordUser or DiscordRole.");
                                }

                                DiscordApplicationCommandOptionChoice[] choices = null;
                                var choiceattributes = parameter.GetCustomAttributes <ChoiceAttribute>();
                                if (choiceattributes.Any())
                                {
                                    choices = Array.Empty <DiscordApplicationCommandOptionChoice>();
                                    foreach (var att in choiceattributes)
                                    {
                                        choices = choices.Append(new DiscordApplicationCommandOptionChoice(att.Name, att.Value)).ToArray();
                                    }
                                }

                                payload.Options.Add(new DiscordApplicationCommandOption(optionattribute.Name, optionattribute.Description)
                                {
                                    Required = !parameter.IsOptional,
                                    Type     = parametertype,
                                    Choices  = choices
                                });
                            }
                            InternalCommandMethods = InternalCommandMethods.Append(new CommandMethod {
                                Method = method, Name = commandattribute.Name, ParentClass = t
                            }).ToArray();
                            ToUpdate.Add(payload);
                        }

                        var commands = await BulkCreateCommandsAsync(ToUpdate, guildid);
                        foreach (var command in commands)
                        {
                            if (InternalCommandMethods.Any(x => x.Name == command.Name))
                            {
                                InternalCommandMethods.First(x => x.Name == command.Name).Id = command.Id;
                            }

                            else if (InternalGroupCommands.Any(x => x.Name == command.Name))
                            {
                                InternalGroupCommands.First(x => x.Name == command.Name).Id = command.Id;
                            }

                            else if (InternalSubGroupCommands.Any(x => x.Name == command.Name))
                            {
                                InternalSubGroupCommands.First(x => x.Name == command.Name).Id = command.Id;
                            }
                        }
                        CommandMethods.AddRange(InternalCommandMethods);
                        GroupCommands.AddRange(InternalGroupCommands);
                        SubGroupCommands.AddRange(InternalSubGroupCommands);
                    }
                    catch (Exception ex)
                    {
                        Client.Logger.LogError(ex, $"There was an error registering slash commands");
                        Environment.Exit(-1);
                    }
                });

                return(Task.CompletedTask);
            };
        }