From cc671499cd3229ca584e722f7093098139badcd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sun, 20 Nov 2022 05:47:29 +0100 Subject: [PATCH] Fix null argument error in clearchat --- .../beatrice/hidekobot/listeners/SlashCommandListener.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/SlashCommandListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/SlashCommandListener.java index 388fd6b..664c3f8 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/SlashCommandListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/SlashCommandListener.java @@ -7,6 +7,7 @@ import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.interactions.InteractionHook; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; import org.jetbrains.annotations.NotNull; import wtf.beatrice.hidekobot.utils.RandomUtil; @@ -51,7 +52,11 @@ public class SlashCommandListener extends ListenerAdapter return; } - int toDeleteAmount = event.getOption("amount").getAsInt(); // not null because the int arg is required + /* get the amount from the command args. + NULL should not be possible because we specified them as mandatory, + but apparently the mobile app doesn't care and still sends the command if you omit the args. */ + OptionMapping amountMapping = event.getOption("amount"); + int toDeleteAmount = amountMapping == null ? 1 : amountMapping.getAsInt(); if(toDeleteAmount <= 0) {