public static async Task AddGuildUserAsync(ulong guildId, BaseDiscordClient client, ulong userId, string accessToken, Action <AddGuildUserProperties> func, RequestOptions options) { var args = new AddGuildUserProperties(); func?.Invoke(args); if (args.Roles.IsSpecified) { var ids = args.Roles.Value.Select(r => r.Id); if (args.RoleIds.IsSpecified) { args.RoleIds.Value.Concat(ids); } else { args.RoleIds = Optional.Create(ids); } } var apiArgs = new AddGuildMemberParams { AccessToken = accessToken, Nickname = args.Nickname, IsDeafened = args.Deaf, IsMuted = args.Mute, RoleIds = args.RoleIds.IsSpecified ? args.RoleIds.Value.Distinct().ToArray() : Optional.Create <ulong[]>() }; await client.ApiClient.AddGuildMemberAsync(guildId, userId, apiArgs, options); }
//Users public static async Task <RestGuildUser> AddGuildUserAsync(IGuild guild, BaseDiscordClient client, ulong userId, string accessToken, Action <AddGuildUserProperties> func, RequestOptions options) { AddGuildUserProperties args = new AddGuildUserProperties(); func?.Invoke(args); if (args.Roles.IsSpecified) { IEnumerable <ulong> ids = args.Roles.Value.Select(r => r.Id); if (args.RoleIds.IsSpecified) { args.RoleIds.Value.Concat(ids); } else { args.RoleIds = Optional.Create(ids); } } AddGuildMemberParams apiArgs = new AddGuildMemberParams { AccessToken = accessToken, Nickname = args.Nickname, IsDeafened = args.Deaf, IsMuted = args.Mute, RoleIds = args.RoleIds.IsSpecified ? args.RoleIds.Value.Distinct().ToArray() : Optional.Create <ulong[]>() }; GuildMemberJson model = await client.ApiClient.AddGuildMemberAsync(guild.Id, userId, apiArgs, options); return(model is null ? null : RestGuildUser.Create(client, guild, model)); }