feature: Add AddGuildUserAsync guild ID extension method. (#1240)

This commit is contained in:
Alex Gravely
2019-05-18 17:40:04 -04:00
committed by Christopher F
parent 655a0069a1
commit 1356ea9736
2 changed files with 51 additions and 0 deletions

View File

@@ -294,6 +294,34 @@ namespace Discord.Rest
return model is null ? null : RestGuildUser.Create(client, guild, model);
}
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);
}
public static async Task<RestGuildUser> GetUserAsync(IGuild guild, BaseDiscordClient client,
ulong id, RequestOptions options)
{