Skip to content

sxmurxy0/Discord-Webhook-API

Repository files navigation

Discord-Webhook-API:stars:


Java API tool for easy work with discord webhooks. Send files, embeds or just text messages.
More information and examples are here. You can also use discord text formatting in your messages.

Example message

Снимок экрана 2023-07-05 004509

Example's code

It doesn't matter in what order you will add components. Discord manages it itself.

    private final WebhookAgent webhook = new WebhookAgent("your.webhook.url");
    
    public void test() {
    	DiscordMessage message = DiscordMessage.builder()
    		.withUsername("CUSTOM USERNAME")
    		.withAvatar("https://foni.club/uploads/posts/2023-01/1673429102_foni-club-p-super-puper-mega-krutie-oboi-48.jpg")
    		.withContent("Your message. **You can** `write anything you` __want__")
    		.addEmbed(DiscordEmbed.builder()
    				.withTitle("Testing testing title!")
    				.withDescription("Description time")
    				.withColor(Color.WHITE)
    				.withAuthor(new AuthorEmbed("sxmurxy", "https://sun6-21.userapi.com/s/v1/if1/dBGCgSOmmhlMRrHKvpRg7-tBe2C61B-SF37DfOxFIlJWolDCE9o0KIsegJXqzaaCX1if5y4k.jpg?size=639x639&quality=96&crop=0,76,639,639&ava=1", "https://vk.com/traplicate"))
    				.withImage(new ImageEmbed("https://yt3.googleusercontent.com/wxbc8Sby-cCy3zjWtFeLr3iO-j8hg_PfaSCiGJ-WioNTxv29EzNF6l07Ce0M4jsxoCE9EC_VXg=s900-c-k-c0x00ffffff-no-rj"))
    				.withThumbnail(new ThumbnailEmbed("https://sun6-21.userapi.com/s/v1/if1/dBGCgSOmmhlMRrHKvpRg7-tBe2C61B-SF37DfOxFIlJWolDCE9o0KIsegJXqzaaCX1if5y4k.jpg?size=639x639&quality=96&crop=0,76,639,639&ava=1"))
    				.withTimestamp(System.currentTimeMillis())
    				.addFields(new FieldEmbed("Field1", "Value1", true),
    						new FieldEmbed("Field2", "Value2", true),
    						new FieldEmbed("Field3", "Value3", true), 
    						new FieldEmbed("Field4", "Value4", true))
    				.withFooter(new FooterEmbed("Footer text right there!", "https://sun6-21.userapi.com/s/v1/if1/dBGCgSOmmhlMRrHKvpRg7-tBe2C61B-SF37DfOxFIlJWolDCE9o0KIsegJXqzaaCX1if5y4k.jpg?size=639x639&quality=96&crop=0,76,639,639&ava=1"))
    				.build())
    		.addFile(new File("C:/Users/%USERNAME%/Downloads/file"))
    		.build();
    	
    	webhook.execute(message);
    }

Dependencies

dependencies {
    implementation 'com.google.code.gson:gson:2.10'
    implementation 'org.apache.httpcomponents:httpmime:4.5.14'
}