From 54886205a684862bb21e7bf56126bfbaa5c4735c Mon Sep 17 00:00:00 2001 From: freya02 <41875020+freya022@users.noreply.github.com> Date: Sat, 18 May 2024 18:20:06 +0200 Subject: [PATCH] Fix null author on DMs received from other bots --- .../jda/api/entities/channel/concrete/PrivateChannel.java | 1 + .../net/dv8tion/jda/internal/entities/EntityBuilder.java | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/PrivateChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/PrivateChannel.java index 6df959b41b..df207f56b9 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/PrivateChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/PrivateChannel.java @@ -39,6 +39,7 @@ public interface PrivateChannel extends MessageChannel *
  • A reaction is added
  • *
  • A message is deleted
  • *
  • This account sends a message to a user from another shard (not shard 0)
  • + *
  • This account receives an interaction response, happens when using an user-installed interaction
  • * * The consequence of this is that for any message this bot receives from a guild or from other users, the user will not be null. * diff --git a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java index 3a13ee5e39..63c7d264de 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/EntityBuilder.java @@ -1630,11 +1630,10 @@ else if (channel instanceof PrivateChannel) } else { - //Note, while PrivateChannel.getUser() can produce null, this invocation of it WILL NOT produce null - // because when the bot receives a message in a private channel that was _not authored by the bot_ then - // the message had to have come from the user, so that means that we had all the information to build - // the channel properly (or fill-in the missing user info of an existing partial channel) + //PrivateChannel.getUser() can produce null, see docs user = ((PrivateChannel) channel).getUser(); + if (user == null) + user = createUser(author); } } else