Skip to content

Instantly share code, notes, and snippets.

@itsmefox
Last active November 23, 2022 16:08
Show Gist options
  • Save itsmefox/3eacbad53bcaa17acfb9d70a9302688e to your computer and use it in GitHub Desktop.
Save itsmefox/3eacbad53bcaa17acfb9d70a9302688e to your computer and use it in GitHub Desktop.
Creating a Discord Bot with Kotlin - PingCommand
class PingCommand : ListenerAdapter() {
private val logger: Logger = LoggerFactory.getLogger(javaClass)
//This gets called when a slash command gets used.
override fun onSlashCommandInteraction(event: SlashCommandInteractionEvent) {
//Check if this is our /ping command
if (event.name == "ping") {
logger.info("Command /ping got used")
//Reply to the user
val startTime = System.currentTimeMillis()
event.reply("Ping ...").setEphemeral(true).queue {
it.editOriginal("Pong: ${System.currentTimeMillis() - startTime}ms").queue()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment