From d3367af119f797b3d15280324d776158a5755373 Mon Sep 17 00:00:00 2001 From: Paulo Date: Tue, 5 Feb 2019 02:07:19 -0200 Subject: [PATCH] Fix NullReferenceException when the webhook was deleted --- .../DataTypes/WebhookCreateAuditLogData.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs index 21388f985..7ecfb6886 100644 --- a/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs +++ b/src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs @@ -10,9 +10,10 @@ namespace Discord.Rest /// public class WebhookCreateAuditLogData : IAuditLogData { - private WebhookCreateAuditLogData(IWebhook webhook, WebhookType type, string name, ulong channelId) + private WebhookCreateAuditLogData(IWebhook webhook, ulong webhookId, WebhookType type, string name, ulong channelId) { Webhook = webhook; + WebhookId = webhookId; Name = name; Type = type; ChannelId = channelId; @@ -31,21 +32,29 @@ namespace Discord.Rest var name = nameModel.NewValue.ToObject(discord.ApiClient.Serializer); var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); - var webhook = RestWebhook.Create(discord, (IGuild)null, webhookInfo); + var webhook = webhookInfo == null ? null : RestWebhook.Create(discord, (IGuild)null, webhookInfo); - return new WebhookCreateAuditLogData(webhook, type, name, channelId); + return new WebhookCreateAuditLogData(webhook, entry.TargetId.Value, type, name, channelId); } // Doc Note: Corresponds to the *current* data /// - /// Gets the webhook that was created. + /// Gets the webhook that was created if it still exists. /// /// - /// A webhook object representing the webhook that was created. + /// A webhook object representing the webhook that was created if it still exists. /// public IWebhook Webhook { get; } + /// + /// Gets the webhook id. + /// + /// + /// The webhook identifier. + /// + public ulong WebhookId { get; } + // Doc Note: Corresponds to the *audit log* data ///