Skip to content

Instantly share code, notes, and snippets.

@itsmefox
Last active November 23, 2022 16:04
Show Gist options
  • Save itsmefox/e7fb37bc768bd54f850aebf84a30317e to your computer and use it in GitHub Desktop.
Save itsmefox/e7fb37bc768bd54f850aebf84a30317e to your computer and use it in GitHub Desktop.
Creating a Discord Bot with Kotlin - PingCommand
public class PingCommand extends ListenerAdapter {
private Logger logger = LoggerFactory.getLogger(this.getClass());
//This gets called when a slash command gets used.
@Override
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
//Check if this is our /ping command
if (event.getName().equals("ping")) {
logger.info("Command /ping got used");
//Reply to the user
long startTime = System.currentTimeMillis();
event.reply("Ping ...").setEphemeral(true).queue(hook -> {
hook.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