Skip to content

Commit f4d45e0

Browse files
committed
Defer using a callback
1 parent 1753b9f commit f4d45e0

File tree

1 file changed

+10
-0
lines changed
  • src/main/kotlin/com/mrkirby153/botcore/command/slashcommand/dsl

1 file changed

+10
-0
lines changed

src/main/kotlin/com/mrkirby153/botcore/command/slashcommand/dsl/Context.kt

+10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.mrkirby153.botcore.command.slashcommand.dsl
22

33
import com.mrkirby153.botcore.builder.MessageBuilder
4+
import com.mrkirby153.botcore.coroutine.await
45
import com.mrkirby153.botcore.utils.SLF4J
56
import kotlinx.coroutines.CoroutineScope
67
import net.dv8tion.jda.api.events.interaction.command.MessageContextInteractionEvent
78
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
89
import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent
10+
import net.dv8tion.jda.api.interactions.InteractionHook
911
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction
1012
import net.dv8tion.jda.api.interactions.commands.context.MessageContextInteraction
1113
import net.dv8tion.jda.api.interactions.commands.context.UserContextInteraction
@@ -80,6 +82,14 @@ class SlashContext(
8082
}
8183
return args
8284
}
85+
86+
/**
87+
* Defers the reply and then executes [handler]. Specify [ephemeral] to defer ephemerally
88+
*/
89+
suspend fun defer(ephemeral: Boolean = false, handler: suspend (InteractionHook) -> Unit) {
90+
val hook = deferReply(ephemeral).await()
91+
handler(hook)
92+
}
8393
}
8494

8595
/**

0 commit comments

Comments
 (0)