discord-net/Discord.Net

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

Misha12 opened this issue · 1 comments

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required 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

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"
       ]
    }
  ]
}