Created
March 25, 2021 17:48
-
-
Save Hopefuls/253c6721c7e65d415d8cda32b50c65f9 to your computer and use it in GitHub Desktop.
Basic Example of implementing a ping command using the CommandHandler
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
package me.hopedev.testproj; | |
import me.hopedev.commandhandler.CommandBuilder; | |
import org.javacord.api.DiscordApi; | |
import org.javacord.api.DiscordApiBuilder; | |
public class Main { | |
public static void main(String[] args) { | |
// init javacord | |
DiscordApi api = new DiscordApiBuilder().setToken("token").login().join(); | |
//CommandBuilder | |
CommandBuilder builder = new CommandBuilder("!", api); | |
// add !ping | |
builder.addCommand("ping", new PingCommand(), "Gets the ping of the bot", "!ping"); | |
//build | |
builder.build(); | |
} | |
} |
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
package me.hopedev.testproj; | |
import me.hopedev.commandhandler.Command; | |
import me.hopedev.commandhandler.CommandData; | |
import me.hopedev.commandhandler.CommandExecutor; | |
import org.javacord.api.entity.message.Message; | |
import java.util.ArrayList; | |
public class PingCommand implements CommandExecutor { | |
@Override | |
public void execute(CommandData data, ArrayList<Command> commands) { | |
long ping1, ping2, ms; | |
ping1 = System.currentTimeMillis(); | |
Message message = data.getChannel().sendMessage("Ping..").join(); | |
ping2 = System.currentTimeMillis(); | |
ms = ping2-ping1; | |
message.edit("Pong! `"+ms+"ms`"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment