Make sure the audit log enumerable is not empty when determining message deleter

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-04-27 22:53:28 +05:00
parent e35db12ab3
commit 926dc0f1b7
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF

View file

@ -69,11 +69,17 @@ public static class EventHandler {
await Task.Delay(500);
var auditLogEntry = (await guild.GetAuditLogsAsync(1).FlattenAsync()).First();
if (auditLogEntry.CreatedAt >= DateTimeOffset.UtcNow.Subtract(TimeSpan.FromSeconds(1))
&& auditLogEntry.Data is MessageDeleteAuditLogData data
&& msg.Author.Id == data.Target.Id)
mention = auditLogEntry.User.Mention;
var auditLogEnumerator
= (await guild.GetAuditLogsAsync(1, actionType: ActionType.MessageDeleted).FlattenAsync()).GetEnumerator();
if (auditLogEnumerator.MoveNext()) {
var auditLogEntry = auditLogEnumerator.Current!;
if (auditLogEntry.CreatedAt >= DateTimeOffset.UtcNow.Subtract(TimeSpan.FromSeconds(1))
&& auditLogEntry.Data is MessageDeleteAuditLogData data
&& msg.Author.Id == data.Target.Id)
mention = auditLogEntry.User.Mention;
}
auditLogEnumerator.Dispose();
await Utils.SendFeedbackAsync(
string.Format(