diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs
index 378ca069b..a1bb1795f 100644
--- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs
+++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs
@@ -680,12 +680,16 @@ namespace Discord
/// The number of audit log entries to fetch.
/// The that determines whether the object should be fetched from cache.
/// The options to be used when sending the request.
+ /// The audit log entry ID to get entries before.
+ /// The type of actions to filter.
+ /// The user ID to filter entries for.
///
/// A task that represents the asynchronous get operation. The task result contains a read-only collection
/// of the requested audit log entries.
///
Task> GetAuditLogsAsync(int limit = DiscordConfig.MaxAuditLogEntriesPerBatch,
- CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
+ CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null,
+ ActionType? actionType = null);
///
/// Gets a webhook found within this guild.
diff --git a/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs b/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs
index ceabccbc8..f136fa7aa 100644
--- a/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs
+++ b/src/Discord.Net.Rest/API/Rest/GetAuditLogsParams.cs
@@ -1,8 +1,10 @@
-namespace Discord.API.Rest
+namespace Discord.API.Rest
{
class GetAuditLogsParams
{
public Optional Limit { get; set; }
public Optional BeforeEntryId { get; set; }
+ public Optional UserId { get; set; }
+ public Optional ActionType { get; set; }
}
}
diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs
index d3db3e301..0ca7ef7a6 100644
--- a/src/Discord.Net.Rest/DiscordRestApiClient.cs
+++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs
@@ -1321,11 +1321,25 @@ namespace Discord.API
var ids = new BucketIds(guildId: guildId);
Expression> endpoint;
+ var queryArgs = new StringBuilder();
if (args.BeforeEntryId.IsSpecified)
- endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}&before={args.BeforeEntryId.Value}";
- else
- endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}";
+ {
+ queryArgs.Append("&before=")
+ .Append(args.BeforeEntryId);
+ }
+ if (args.UserId.IsSpecified)
+ {
+ queryArgs.Append("&user_id=")
+ .Append(args.UserId.Value);
+ }
+ if (args.ActionType.IsSpecified)
+ {
+ queryArgs.Append("&action_type=")
+ .Append(args.ActionType.Value);
+ }
+ // still use string interp for the query w/o params, as this is necessary for CreateBucketId
+ endpoint = () => $"guilds/{guildId}/audit-logs?limit={limit}{queryArgs.ToString()}";
return await SendAsync("GET", endpoint, ids, options: options).ConfigureAwait(false);
}
diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
index a9b51c113..3f5565ccf 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
@@ -380,7 +380,7 @@ namespace Discord.Rest
// Audit logs
public static IAsyncEnumerable> GetAuditLogsAsync(IGuild guild, BaseDiscordClient client,
- ulong? from, int? limit, RequestOptions options)
+ ulong? from, int? limit, RequestOptions options, ulong? userId = null, ActionType? actionType = null)
{
return new PagedAsyncEnumerable(
DiscordConfig.MaxAuditLogEntriesPerBatch,
@@ -392,6 +392,10 @@ namespace Discord.Rest
};
if (info.Position != null)
args.BeforeEntryId = info.Position.Value;
+ if (userId.HasValue)
+ args.UserId = userId.Value;
+ if (actionType.HasValue)
+ args.ActionType = (int)actionType.Value;
var model = await client.ApiClient.GetAuditLogsAsync(guild.Id, args, options);
return model.Entries.Select((x) => RestAuditLogEntry.Create(client, model, x)).ToImmutableArray();
},
diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
index 7ed258155..2c21b0939 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
@@ -627,12 +627,15 @@ namespace Discord.Rest
///
/// The number of audit log entries to fetch.
/// The options to be used when sending the request.
+ /// The audit log entry ID to get entries before.
+ /// The type of actions to filter.
+ /// The user ID to filter entries for.
///
/// A task that represents the asynchronous get operation. The task result contains a read-only collection
/// of the requested audit log entries.
///
- public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null)
- => GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options);
+ public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null)
+ => GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType);
//Webhooks
///
@@ -866,10 +869,11 @@ namespace Discord.Rest
Task IGuild.DownloadUsersAsync() =>
throw new NotSupportedException();
- async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options)
+ async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options,
+ ulong? beforeId, ulong? userId, ActionType? actionType)
{
if (cacheMode == CacheMode.AllowDownload)
- return (await GetAuditLogsAsync(limit, options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
+ return (await GetAuditLogsAsync(limit, options, beforeId: beforeId, userId: userId, actionType: actionType).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
else
return ImmutableArray.Create();
}
diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
index 09046ecf1..cd0ab3db2 100644
--- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
+++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
@@ -801,12 +801,15 @@ namespace Discord.WebSocket
///
/// The number of audit log entries to fetch.
/// The options to be used when sending the request.
+ /// The audit log entry ID to filter entries before.
+ /// The type of actions to filter.
+ /// The user ID to filter entries for.
///
/// A task that represents the asynchronous get operation. The task result contains a read-only collection
/// of the requested audit log entries.
///
- public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null)
- => GuildHelper.GetAuditLogsAsync(this, Discord, null, limit, options);
+ public IAsyncEnumerable> GetAuditLogsAsync(int limit, RequestOptions options = null, ulong? beforeId = null, ulong? userId = null, ActionType? actionType = null)
+ => GuildHelper.GetAuditLogsAsync(this, Discord, beforeId, limit, options, userId: userId, actionType: actionType);
//Webhooks
///
@@ -1160,10 +1163,11 @@ namespace Discord.WebSocket
=> Task.FromResult(Owner);
///
- async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options)
+ async Task> IGuild.GetAuditLogsAsync(int limit, CacheMode cacheMode, RequestOptions options,
+ ulong? beforeId, ulong? userId, ActionType? actionType)
{
if (cacheMode == CacheMode.AllowDownload)
- return (await GetAuditLogsAsync(limit, options).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
+ return (await GetAuditLogsAsync(limit, options, beforeId: beforeId, userId: userId, actionType: actionType).FlattenAsync().ConfigureAwait(false)).ToImmutableArray();
else
return ImmutableArray.Create();
}