From 926dc0f1b768cba7fe89e0458ccc60eee667ef7b Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 27 Apr 2023 22:53:28 +0500 Subject: [PATCH] Make sure the audit log enumerable is not empty when determining message deleter Signed-off-by: Octol1ttle --- EventHandler.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/EventHandler.cs b/EventHandler.cs index 3eb42dc..017c604 100644 --- a/EventHandler.cs +++ b/EventHandler.cs @@ -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(