3
3
import net .dv8tion .jda .api .entities .*;
4
4
import net .dv8tion .jda .api .events .interaction .command .SlashCommandInteractionEvent ;
5
5
import net .dv8tion .jda .api .exceptions .ErrorResponseException ;
6
+ import net .dv8tion .jda .api .interactions .InteractionHook ;
6
7
import net .dv8tion .jda .api .interactions .callbacks .IReplyCallback ;
7
8
import net .dv8tion .jda .api .interactions .commands .OptionType ;
8
9
import net .dv8tion .jda .api .interactions .commands .build .OptionData ;
9
10
import net .dv8tion .jda .api .requests .ErrorResponse ;
10
11
import net .dv8tion .jda .api .requests .RestAction ;
11
- import net .dv8tion .jda .api .requests .restaction .interactions .ReplyCallbackAction ;
12
12
import org .jetbrains .annotations .NotNull ;
13
13
import org .slf4j .Logger ;
14
14
import org .slf4j .LoggerFactory ;
@@ -92,11 +92,16 @@ public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
92
92
}
93
93
TextChannel overviewChannel = maybeOverviewChannel .orElseThrow ();
94
94
95
+ InteractionHook eventHook = event .getHook ();
96
+ Member author = event .getMember ();
97
+ Guild guild = event .getGuild ();
98
+ event .deferReply (true ).queue ();
99
+
95
100
overviewChannel .createThreadChannel ("[%s] %s" .formatted (category , title ))
96
- .flatMap (threadChannel -> handleEvent (event , threadChannel , event . getMember () , title ,
97
- category ))
101
+ .flatMap (threadChannel -> handleEvent (eventHook , threadChannel , author , title , category ,
102
+ guild ))
98
103
.queue (any -> {
99
- }, e -> handleFailure (e , event ));
104
+ }, e -> handleFailure (e , eventHook ));
100
105
}
101
106
102
107
private boolean handleIsStagingChannel (@ NotNull IReplyCallback event ) {
@@ -125,11 +130,11 @@ private boolean handleIsValidTitle(@NotNull CharSequence title, @NotNull IReplyC
125
130
return false ;
126
131
}
127
132
128
- private @ NotNull RestAction <Message > handleEvent (@ NotNull IReplyCallback event ,
133
+ private @ NotNull RestAction <Message > handleEvent (@ NotNull InteractionHook eventHook ,
129
134
@ NotNull ThreadChannel threadChannel , @ NotNull Member author , @ NotNull String title ,
130
- @ NotNull String category ) {
131
- return sendInitialMessage (event . getGuild () , threadChannel , author , title , category )
132
- .flatMap (any -> notifyUser (event , threadChannel ))
135
+ @ NotNull String category , @ NotNull Guild guild ) {
136
+ return sendInitialMessage (guild , threadChannel , author , title , category )
137
+ .flatMap (any -> notifyUser (eventHook , threadChannel ))
133
138
.flatMap (any -> helper .sendExplanationMessage (threadChannel ));
134
139
}
135
140
@@ -153,22 +158,21 @@ private RestAction<Message> sendInitialMessage(@NotNull Guild guild,
153
158
.flatMap (message -> message .editMessage (contentWithRole ));
154
159
}
155
160
156
- private static @ NotNull ReplyCallbackAction notifyUser (@ NotNull IReplyCallback event ,
161
+ private static @ NotNull RestAction < Message > notifyUser (@ NotNull InteractionHook eventHook ,
157
162
@ NotNull IMentionable threadChannel ) {
158
- return event . reply ("""
163
+ return eventHook . editOriginal ("""
159
164
Created a thread for you: %s
160
- Please ask your question there, thanks.""" .formatted (threadChannel .getAsMention ()))
161
- .setEphemeral (true );
165
+ Please ask your question there, thanks.""" .formatted (threadChannel .getAsMention ()));
162
166
}
163
167
164
- private static void handleFailure (@ NotNull Throwable exception , @ NotNull IReplyCallback event ) {
168
+ private static void handleFailure (@ NotNull Throwable exception ,
169
+ @ NotNull InteractionHook eventHook ) {
165
170
if (exception instanceof ErrorResponseException responseException ) {
166
171
ErrorResponse response = responseException .getErrorResponse ();
167
172
if (response == ErrorResponse .MAX_CHANNELS
168
173
|| response == ErrorResponse .MAX_ACTIVE_THREADS ) {
169
- event . reply (
174
+ eventHook . editOriginal (
170
175
"It seems that there are currently too many active questions, please try again in a few minutes." )
171
- .setEphemeral (true )
172
176
.queue ();
173
177
return ;
174
178
}
0 commit comments