Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.

Bot Examples

Jared edited this page Jul 26, 2022 · 14 revisions

Ping Pong Bot

Main Class

public class Bot {
    private static JG_API jg_api;

    public static void main(String[] args) {
        try {
            jg_api = new JG_API.ClientBuilder()
                    .setParentServerId(ConfigManager.getInstance().getProperty("GUILDED_SERVER_ID"))
                    .setToken(ConfigManager.getInstance().getProperty("GUILDED_TOKEN"))
                    .addListenerAdapter(new EventHandler())
                    .build();

            jg_api.login();
            jg_api.start();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

EventHandler

public class EventHandler extends ListenerAdapter {
    @Override
    public void onReadyEvent(ReadyEvent event) {
        System.out.println(event.getJGAPI().getClientUser().getName() + " is now ready!");
    }

    @Override
    public void onChatMessageCreatedEvent(ChatMessageCreatedEvent event) {
        ChatMessage message = event.getMessage();
        String content = message.getContent();
        String[] args = content.split(" ");
        if (args.length < 1) return; // It's not enough arguments, disregard
        String command = args[0];

        if (command.equalsIgnoreCase("ping")) {
            message.getChannel().sendMessage("pong!").queue();
        }
    }
}

Commands with arguments

TBD

Message Deletion

TBD

Clone this wiki locally