Repository navigation
Creating bots with JG_API
Jared Scarito edited this page Oct 18, 2026
·
7 revisions
JG_API needs Java 17+, see Installation on how to add it to your project.
- Go to the server settings page
- Click "Bots" on the left side and you will see all the bots in the server
- Click "Create a bot" to create a new bot
- Click the Kebab menu which is the icon that has 3 dots on top of each other to the right of this newly created bot
- Click "Generate token" and click "Copy"
- This is the token you will use for initializing your
JG_APIinstance
public class Bot {
public static JG_API jg_api;
public static void main(String[] args) {
try {
jg_api = new JG_API.ClientBuilder()
.setToken(ConfigManager.getInstance().getProperty("GUILDED_TOKEN"))
.build();
jg_api.login();
jg_api.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}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) {}
}public class Bot {
private static JG_API jg_api;
public static void main(String[] args) {
try {
jg_api = new JG_API.ClientBuilder()
.setToken(ConfigManager.getInstance().getProperty("GUILDED_TOKEN"))
.addListenerAdapter(new EventHandler())
.build();
jg_api.login();
jg_api.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}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 messageId = message.getId();
String channelId = message.getChannel().getId();
// Note the order of the arguments: the channel first, then the message
event.getJGAPI().getRestClient().deleteMessage(channelId, messageId).queue(
(isDeleted) -> {
if (isDeleted) System.out.println("The channel message was deleted successfully...");
}, Throwable::printStackTrace);
}
}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();
try {
boolean wasDeleted = event.getJGAPI().getRestClient()
.deleteMessage(message.getChannel().getId(), message.getId())
.complete(); // Blocks until Guilded answered
} catch (IOException | RestActionException e) {
e.printStackTrace();
}
}
}- Bot Examples for more things to copy from
- Events to see everything your bot can react to
-
RestActions to understand
queue(),complete()andsubmit() - Embeds and Webhooks for rich messages
JG_API
Getting started
Guides
More