Last active
November 23, 2022 16:04
-
-
Save itsmefox/e7fb37bc768bd54f850aebf84a30317e to your computer and use it in GitHub Desktop.
Creating a Discord Bot with Kotlin - PingCommand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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