discord-net / Discord.Net

An unofficial .Net wrapper for the Discord API (https://discord.com/)
https://discordnet.dev
MIT License
3.31k stars 739 forks source link

[Bug]: Getting audit logs for thread updated throws NullReferenceException #2621

Closed Misha12 closed 1 year ago

Misha12 commented 1 year ago

Check The Docs

Verify Issue Source

Check your intents

Description

Model transformation while downloading audit logs from Discord API throws null reference exception in the ThreadUpdateAuditLogData.Create method.

Version

3.9.0

Working Version

No response

Logs

System.NullReferenceException: Object reference not set to an instance of an object.
   at Discord.Rest.ThreadUpdateAuditLogData.Create(BaseDiscordClient discord, AuditLog log, AuditLogEntry entry)
   at Discord.Rest.AuditLogHelper.CreateData(BaseDiscordClient discord, AuditLog log, AuditLogEntry entry)
   at Discord.Rest.RestAuditLogEntry..ctor(BaseDiscordClient discord, AuditLog fullLog, AuditLogEntry model, IUser user)
   at Discord.Rest.RestAuditLogEntry.Create(BaseDiscordClient discord, AuditLog fullLog, AuditLogEntry model)
   at Discord.Rest.GuildHelper.<>c__DisplayClass33_1.<GetAuditLogsAsync>b__2(AuditLogEntry x)
   at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
   at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   at Discord.Rest.GuildHelper.<>c__DisplayClass33_0.<<GetAuditLogsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Discord.PagedAsyncEnumerable`1.Enumerator.MoveNextAsync()
   at System.Linq.AsyncEnumerable.SelectManyAsyncIterator`2.ToListAsync(CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs:line 432
   at System.Linq.AsyncEnumerable.SelectManyAsyncIterator`2.ToListAsync(CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs:line 432
   at System.Linq.AsyncEnumerable.SelectManyAsyncIterator`2.ToArrayAsync(CancellationToken cancellationToken) in /_/Ix.NET/Source/System.Linq.Async/System/Linq/Operators/SelectMany.cs:line 423
   at Discord.AsyncEnumerableExtensions.FlattenAsync[T](IAsyncEnumerable`1 source)
   at Discord.WebSocket.SocketGuild.Discord.IGuild.GetAuditLogsAsync(Int32 limit, CacheMode cacheMode, RequestOptions options, Nullable`1 beforeId, Nullable`1 userId, Nullable`1 actionType)
   at GrillBot.App.Handlers.ThreadUpdated.ForumThreadTagsUpdated.FindAuditLogAsync(IGuild guild, IThreadChannel thread) in E:\Projects\grillbot\src\GrillBot.App\Handlers\ThreadUpdated\ForumThreadTagsUpdated.cs:line 63

Sample

var guild = await _discordClient.GetGuildsAsync().First(); // The guild doesn't matter. _discordClient have type IDiscordClient
var auditLogs = await guild.GetAuditLogsAsync(actionType: ActionType.ThreadUpdated);

Packages

AspNetCore.HealthChecks.NpgSql Discord.NET Microsoft.AspNetCore.Authentication.JwtBearer Microsoft.AspNetCore.Mvc.NewtonsoftJson Microsoft.EntityFrameworkCore.Design Microsoft.Extensions.Diagnostics.HealthChecks NSwag.AspNetCore Quartz.Extensions.Hosting Serilog.AspNetCore

Misha12 commented 1 year ago

Response from Discord API for one entry of audit log:

{
  "id": "1081517144476495912",
  "user_id": "370506820197810176",
  "target_id": "1059533270817198191",
  "action_type": 111,
  "changes": [
    {
      "key": "applied_tags",
      "new_value": [
         "1081510073433604177",
         "1059533209848791121"
       ],
       "old_value": [
         "1081510073433604177"
       ]
    }
  ]
}