Browse Source

Fix NullReferenceException when the webhook was deleted

pull/1256/head
Paulo GitHub 6 years ago
parent
commit
d3367af119
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 5 deletions
  1. +14
    -5
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs

+ 14
- 5
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs View File

@@ -10,9 +10,10 @@ namespace Discord.Rest
/// </summary> /// </summary>
public class WebhookCreateAuditLogData : IAuditLogData 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; Webhook = webhook;
WebhookId = webhookId;
Name = name; Name = name;
Type = type; Type = type;
ChannelId = channelId; ChannelId = channelId;
@@ -31,21 +32,29 @@ namespace Discord.Rest
var name = nameModel.NewValue.ToObject<string>(discord.ApiClient.Serializer); var name = nameModel.NewValue.ToObject<string>(discord.ApiClient.Serializer);


var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); 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 // Doc Note: Corresponds to the *current* data


/// <summary> /// <summary>
/// Gets the webhook that was created.
/// Gets the webhook that was created if it still exists.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// A webhook object representing the webhook that was created.
/// A webhook object representing the webhook that was created if it still exists.
/// </returns> /// </returns>
public IWebhook Webhook { get; } public IWebhook Webhook { get; }


/// <summary>
/// Gets the webhook id.
/// </summary>
/// <returns>
/// The webhook identifier.
/// </returns>
public ulong WebhookId { get; }

// Doc Note: Corresponds to the *audit log* data // Doc Note: Corresponds to the *audit log* data


/// <summary> /// <summary>


Loading…
Cancel
Save