@@ -72,15 +72,14 @@ public BanCommand(ModerationActionsStore actionsStore) {
72
72
this .actionsStore = Objects .requireNonNull (actionsStore );
73
73
}
74
74
75
- private static RestAction <InteractionHook > handleAlreadyBanned (Guild .Ban ban ,
76
- IReplyCallback event ) {
75
+ private static RestAction <Message > handleAlreadyBanned (Guild .Ban ban , InteractionHook hook ) {
77
76
String reason = ban .getReason ();
78
77
String reasonText =
79
78
reason == null || reason .isBlank () ? "" : " (reason: %s)" .formatted (reason );
80
79
81
80
String message = "The user '%s' is already banned%s." .formatted (ban .getUser ().getAsTag (),
82
81
reasonText );
83
- return event . reply (message ).setEphemeral (true );
82
+ return hook . sendMessage (message ).setEphemeral (true );
84
83
}
85
84
86
85
private static RestAction <Boolean > sendDm (ISnowflake target ,
@@ -115,8 +114,8 @@ private static MessageEmbed sendFeedback(boolean hasSentDm, User target, Member
115
114
durationText + dmNoticeText , reason );
116
115
}
117
116
118
- private static Optional <RestAction <InteractionHook >> handleNotAlreadyBannedResponse (
119
- Throwable alreadyBannedFailure , IReplyCallback event , Guild guild , User target ) {
117
+ private static Optional <RestAction <Message >> handleNotAlreadyBannedResponse (
118
+ Throwable alreadyBannedFailure , InteractionHook hook , Guild guild , User target ) {
120
119
if (alreadyBannedFailure instanceof ErrorResponseException errorResponseException ) {
121
120
if (errorResponseException .getErrorResponse () == ErrorResponse .UNKNOWN_BAN ) {
122
121
return Optional .empty ();
@@ -125,7 +124,7 @@ private static Optional<RestAction<InteractionHook>> handleNotAlreadyBannedRespo
125
124
if (errorResponseException .getErrorResponse () == ErrorResponse .MISSING_PERMISSIONS ) {
126
125
logger .error ("The bot does not have the '{}' permission on the guild '{}'." ,
127
126
Permission .BAN_MEMBERS , guild .getName ());
128
- return Optional .of (event . reply (
127
+ return Optional .of (hook . sendMessage (
129
128
"I can not ban users in this guild since I do not have the %s permission."
130
129
.formatted (Permission .BAN_MEMBERS ))
131
130
.setEphemeral (true ));
@@ -134,18 +133,18 @@ private static Optional<RestAction<InteractionHook>> handleNotAlreadyBannedRespo
134
133
logger .warn (LogMarkers .SENSITIVE ,
135
134
"Something unexpected went wrong while trying to ban the user '{}'." ,
136
135
target .getAsTag (), alreadyBannedFailure );
137
- return Optional .of (event . reply ("Failed to ban the user due to an unexpected problem." )
136
+ return Optional .of (hook . sendMessage ("Failed to ban the user due to an unexpected problem." )
138
137
.setEphemeral (true ));
139
138
}
140
139
141
- private RestAction <InteractionHook > banUserFlow (User target , Member author ,
140
+ private RestAction <Message > banUserFlow (User target , Member author ,
142
141
@ Nullable ModerationUtils .TemporaryData temporaryData , String reason ,
143
142
int deleteHistoryDays , Guild guild , SlashCommandInteractionEvent event ) {
144
143
return sendDm (target , temporaryData , reason , guild , event )
145
144
.flatMap (hasSentDm -> banUser (target , author , temporaryData , reason , deleteHistoryDays ,
146
145
guild ).map (banResult -> hasSentDm ))
147
146
.map (hasSentDm -> sendFeedback (hasSentDm , target , author , temporaryData , reason ))
148
- .flatMap (event :: replyEmbeds );
147
+ .flatMap (event . getHook ():: sendMessageEmbeds );
149
148
}
150
149
151
150
private AuditableRestAction <Void > banUser (User target , Member author ,
@@ -208,14 +207,16 @@ public void onSlashCommand(SlashCommandInteractionEvent event) {
208
207
int deleteHistoryDays = Math
209
208
.toIntExact (Objects .requireNonNull (event .getOption (DELETE_HISTORY_OPTION )).getAsLong ());
210
209
210
+ event .deferReply ().queue ();
211
+ InteractionHook hook = event .getHook ();
211
212
// Ban the user, but only if not already banned
212
213
guild .retrieveBan (target ).mapToResult ().flatMap (alreadyBanned -> {
213
214
if (alreadyBanned .isSuccess ()) {
214
- return handleAlreadyBanned (alreadyBanned .get (), event );
215
+ return handleAlreadyBanned (alreadyBanned .get (), hook );
215
216
}
216
217
217
218
return handleNotAlreadyBannedResponse (
218
- Objects .requireNonNull (alreadyBanned .getFailure ()), event , guild , target )
219
+ Objects .requireNonNull (alreadyBanned .getFailure ()), hook , guild , target )
219
220
.orElseGet (() -> banUserFlow (target , author , temporaryData .orElse (null ),
220
221
reason , deleteHistoryDays , guild , event ));
221
222
}).queue ();
0 commit comments