Repository navigation
Embeds and Webhooks
Use the EmbedBuilder to create a ChatEmbed. Everything is optional, only what you set is sent.
ChatEmbed embed = new EmbedBuilder()
.setTitle("Server rules")
.setDescription("Please be nice to each other.")
.setUrl("https://example.com/rules")
.setColor(0x5865F2) // RGB, or setColor(88, 101, 242)
.setAuthor("Moderation team", null, "https://example.com/icon.png")
.setThumbnail("https://example.com/thumb.png")
.setImage("https://example.com/banner.png")
.addField("Rule 1", "Be respectful", false)
.addField("Rule 2", "No spam", true)
.setFooter("Last updated", "https://example.com/footer.png")
.setTimestamp(Instant.now())
.build();Messages take an array of embeds:
channel.sendMessage(new ChatEmbed[]{embed}).queue(); // only embeds
channel.sendMessage("Read this!", false, false, null, new ChatEmbed[]{embed}).queue();
message.reply(new ChatEmbed[]{embed}).queue(); // reply to a messageEmbeds can also be set when editing: message.setEmbeds(new ChatEmbed[]{embed}).queue().
ChatMessage#getEmbeds() returns the embeds of a message. Parts that aren't there (footer, image, ...) are null, getColor() is -1 when there is no color, and getFields() is empty when there are no fields.
Webhooks of a server can be managed through the RestClient, which needs the permissions to manage webhooks:
RestClient rest = jg_api.getRestClient();
rest.createWebhook(serverId, "Announcer", channelId).queue(webhook -> {
System.out.println(webhook.getId() + " / " + webhook.getToken());
});
rest.getWebhooks(serverId, channelId).queue(webhooks -> { ... });Guilded only returns the token of a webhook when it is created. Keep it somewhere safe.
Use the WebhookBuilder. It doesn't use your bot's token, the token of the webhook is enough:
// From the URL that Guilded shows you for the webhook
WebhookBuilder.fromUrl(jg_api, "https://media.guilded.gg/webhooks/<id>/<token>")
.setUsername("Announcer")
.setAvatarUrl("https://example.com/avatar.png")
.setContent("Hello from a webhook!")
.addEmbed(embed)
.send()
.queue();
// From an id and token
new WebhookBuilder(jg_api, webhookId, webhookToken).setContent("Hi").send().queue();
// From a Webhook entity that was just created
rest.createWebhook(serverId, "Announcer", channelId).queue(webhook ->
new WebhookBuilder(jg_api, webhook).setContent("I'm alive!").send().queue());fromUrl throws an IllegalArgumentException if the URL isn't a webhook URL.
JG_API
Getting started
Guides
More