Skip to content

Commit

Permalink
Command conversion #3: Ping Command
Browse files Browse the repository at this point in the history
  • Loading branch information
Chew committed Jun 1, 2020
1 parent 1f19443 commit 0eeea57
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/pw/chew/Chewbotcca/Main.java
Expand Up @@ -9,6 +9,7 @@
import org.slf4j.LoggerFactory;
import pw.chew.Chewbotcca.commands.about.HelpCommand;
import pw.chew.Chewbotcca.commands.about.InviteCommand;
import pw.chew.Chewbotcca.commands.about.PingCommand;

import javax.security.auth.login.LoginException;
import java.io.FileInputStream;
Expand Down Expand Up @@ -39,7 +40,8 @@ public static void main(String[] args) throws LoginException, IOException {
client.addCommands(
// About Module
new HelpCommand(),
new InviteCommand()
new InviteCommand(),
new PingCommand()
);

// Register listeners
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/pw/chew/Chewbotcca/commands/about/PingCommand.java
@@ -0,0 +1,26 @@
package pw.chew.Chewbotcca.commands.about;

import com.jagrosh.jdautilities.command.Command;
import com.jagrosh.jdautilities.command.CommandEvent;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;

public class PingCommand extends Command {

public PingCommand() {
this.name = "ping";
this.help = "Ping the bot";
this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS};
this.guildOnly = false;
}

@Override
protected void execute(CommandEvent commandEvent) {
long time = commandEvent.getMessage().getTimeCreated().toInstant().toEpochMilli();
commandEvent.getChannel().sendMessage(new EmbedBuilder().setDescription("Checking ping..").build()).queue((msg) -> {
EmbedBuilder eb = new EmbedBuilder().setDescription("Ping is " + (msg.getTimeCreated().toInstant().toEpochMilli() - time) + "ms");
msg.editMessage(eb.build()).queue();
});
commandEvent.getChannel().getLatestMessageId();
}
}

0 comments on commit 0eeea57

Please sign in to comment.