From 87fa081bcd10c5c80b827e434f66f55ed37b8f57 Mon Sep 17 00:00:00 2001 From: Chris Sdogkos Date: Mon, 26 Jan 2026 16:16:22 +0200 Subject: [PATCH] hotfix(DynamicVoiceChat): delay deleting `channelLeft` on history fetch By letting the JDA asynchornously retrieve the voice channel history and figure out if we are going to delete the channel in question without making sure one finishes before the other gets executed, we receive this: RestAction queue returned failure: [ErrorResponseException] 10003: Unknown Channel net.dv8tion.jda.api.exceptions.ContextException at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54) at net.dv8tion.jda.api.requests.Request.(Request.java:78) at net.dv8tion.jda.internal.requests.RestActionImpl.queue(RestActionImpl.java:203) at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:577) at org.togetherjava.tjbot.features.voicechat.DynamicVoiceChat.handleVoiceChannelLeave(DynamicVoiceChat.java:84) at org.togetherjava.tjbot.features.voicechat.DynamicVoiceChat.onVoiceUpdate(DynamicVoiceChat.java:68) at org.togetherjava.tjbot.features.system.BotCore.lambda$onGuildVoiceUpdate$1(BotCore.java:306) at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:186) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:214) Delay deleting `channelLeft` channel by 500ms and use `RestAction#onSuccess` to make sure that the channel history request is done _first_ and completely, before we move on to deleting the channel. Signed-off-by: Chris Sdogkos --- .../tjbot/features/voicechat/DynamicVoiceChat.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/voicechat/DynamicVoiceChat.java b/application/src/main/java/org/togetherjava/tjbot/features/voicechat/DynamicVoiceChat.java index 6adcc7b8d7..20fb23c787 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/voicechat/DynamicVoiceChat.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/voicechat/DynamicVoiceChat.java @@ -20,6 +20,7 @@ import org.togetherjava.tjbot.features.VoiceReceiverAdapter; import java.util.Optional; +import java.util.concurrent.TimeUnit; /** * Handles dynamic voice channel creation and deletion based on user activity. @@ -30,6 +31,7 @@ */ public final class DynamicVoiceChat extends VoiceReceiverAdapter { private static final Logger logger = LoggerFactory.getLogger(DynamicVoiceChat.class); + private static final long DELETE_VOICE_CHANNEL_ACTION_DELAY_MS = 500L; private final VoiceChatCleanupStrategy voiceChatCleanupStrategy; private final DynamicVoiceChatConfig dynamicVoiceChannelConfig; @@ -87,13 +89,14 @@ private void handleVoiceChannelLeave(AudioChannelUnion channelLeft) { return; } - channelLeft.asVoiceChannel().getHistory().retrievePast(2).queue(messages -> { + channelLeft.asVoiceChannel().getHistory().retrievePast(2).onSuccess(messages -> { if (messages.size() > 1) { archiveDynamicVoiceChannel(channelLeft); } else { - channelLeft.delete().queue(); + channelLeft.delete() + .queueAfter(DELETE_VOICE_CHANNEL_ACTION_DELAY_MS, TimeUnit.MILLISECONDS); } - }); + }).queue(); } }