From d53ff36a2a9e678a9a7f5792d67b89a7596225d2 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Wed, 15 Dec 2021 20:02:51 +0000 Subject: [PATCH] Prevent IndexOutOfBoundsException in interaction replies (#4690) --- .../discord/interactions/InteractionEventImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java index dd78c232d..37c6dfd40 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/interactions/InteractionEventImpl.java @@ -34,7 +34,12 @@ public class InteractionEventImpl implements InteractionEvent { public void reply(String message) { message = FormatUtil.stripFormat(message).replace("ยง", ""); // Don't ask replyBuffer.add(message); - event.getHook().editOriginal(new MessageBuilder().setContent(Joiner.on('\n').join(replyBuffer).substring(0, Message.MAX_CONTENT_LENGTH)).setAllowedMentions(DiscordUtil.NO_GROUP_MENTIONS).build()) + String reply = Joiner.on('\n').join(replyBuffer); + reply = reply.substring(0, Math.min(Message.MAX_CONTENT_LENGTH, reply.length())); + event.getHook().editOriginal( + new MessageBuilder() + .setContent(reply) + .setAllowedMentions(DiscordUtil.NO_GROUP_MENTIONS).build()) .queue(null, error -> logger.log(Level.SEVERE, "Error while editing command interaction response", error)); }