From 09f8dbd9561b3da9d60e837074132574f54ca43b Mon Sep 17 00:00:00 2001 From: p5nbTgip0r Date: Fri, 15 Jan 2021 13:31:56 -0800 Subject: [PATCH] :bug: JDA: Fix webhook messages throwing NPE (#214) * Fix NPE with webhook messages. Webhook messages would be constructed as `JDAGuildSender`, which calls `Objects.requireNonNull(event.getMember())` however the JDA documentation states that the `getMember()` method will `be null in case of Message being received in a PrivateChannel or isWebhookMessage() returning true.` If the message is a webhook message, a generic `JDACommandSender` instance will be constructed instead of a `JDAGuildSender` * Add webhook fix to changelog --- CHANGELOG.md | 2 +- .../java/cloud/commandframework/jda/JDACommandSender.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73279162..164c15cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Issue where suggestions were shown multiple times when using Brigadier ([#184](https://github.com/Incendo/cloud/pull/184)) - Issue where the command manager was in the wrong state if no commands had been registered ([#196](https://github.com/Incendo/cloud/pull/196)) - - Issues with JDA ([#198](https://github.com/Incendo/cloud/pull/198)) ([#199](https://github.com/Incendo/cloud/pull/199)) + - Issues with JDA ([#198](https://github.com/Incendo/cloud/pull/198)) ([#199](https://github.com/Incendo/cloud/pull/199)) ([#214](https://github.com/Incendo/cloud/pull/214)) - Console suggestions for Bukkit ## [1.3.0] - 2020-12-18 diff --git a/cloud-discord/cloud-jda/src/main/java/cloud/commandframework/jda/JDACommandSender.java b/cloud-discord/cloud-jda/src/main/java/cloud/commandframework/jda/JDACommandSender.java index af587a99..1ab2ccaa 100644 --- a/cloud-discord/cloud-jda/src/main/java/cloud/commandframework/jda/JDACommandSender.java +++ b/cloud-discord/cloud-jda/src/main/java/cloud/commandframework/jda/JDACommandSender.java @@ -66,7 +66,9 @@ public class JDACommandSender { * @return Constructed JDA Command Sender */ public static @NonNull JDACommandSender of(final @NonNull MessageReceivedEvent event) { - if (event.isFromType(ChannelType.PRIVATE)) { + if (event.isWebhookMessage()) { + return new JDACommandSender(event, event.getAuthor(), event.getChannel()); + } else if (event.isFromType(ChannelType.PRIVATE)) { return new JDAPrivateSender(event, event.getAuthor(), event.getPrivateChannel()); }