MinnDevelopment/discord-webhooks

Error in Sending Webhooks

G-Kumaran opened this issue · 14 comments

Version :

<dependency>
    <groupId>club.minnced</groupId>
    <artifactId>discord-webhooks</artifactId>
    <version>0.3.2</version>
</dependency>

Environment:
Java 8 with SpringBoot

Code:

WebhookClient.withUrl("https://discordapp.com/api/webhooks/736596600071127061/[REDACTED]")
     .send("Test");

Error:

ERROR 20760 --- [596600071127061] c.minnced.discord.webhook.WebhookClient  : Sending a webhook message failed with non-OK http response

club.minnced.discord.webhook.exception.HttpException: Request returned failure 400: {"code": 50035, "errors": {"allowed_mentions": {"_errors": [{"code": "MODEL_TYPE_CONVERT", "message": "Only dictionaries may be used in a ModelType"}]}}, "message": "Invalid Form Body"}
	at club.minnced.discord.webhook.WebhookClient.failure(WebhookClient.java:375) [discord-webhooks-0.3.2.jar:na]
	at club.minnced.discord.webhook.WebhookClient.executePair(WebhookClient.java:438) [discord-webhooks-0.3.2.jar:na]
	at club.minnced.discord.webhook.WebhookClient.drainQueue(WebhookClient.java:411) [discord-webhooks-0.3.2.jar:na]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_252]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_252]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_252]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.8.0_252]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_252]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_252]
	at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_252]

I'm unable to reproduce this with your provided code.

Yeah i received your ping.
But i can consistently reproduce this issue in my code.
Any more debugging info that i can provide to assist you?

To test Ive manually created a webhook without this api and yet i still get this issue.
So I'm guessing issue isn't in the api...

Damn

Potentially this is an issue with your dependencies which somehow conflict with the JSON library?

You could be right, created a new project with only just the spring-boot-starter and the discord-webhooks dependancies without the any other dependancies. Webhooks now pass.
What json library is discord-webhooks api using? Im on Jackson.

Jackson shouldn't conflict with org.json though. More likely some of your other dependencies relies on a different version of org.json

After hours of combination and errors, not able to identify the actual issue.

But found the cause of issue.

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-test</artifactId>
	<scope>test</scope>
</dependency>

Addin this to the pom causes the issue, deleting this from the pom and webhook passes.

Can u reproduce the issue based on this?

I don't use maven and have no maven setup but I assume the reason is that maven resolves dependencies on first sight rather than using the latest. The issue might be solved by putting this library as your first dependency.

Update :
Analysis of packages inside the sping-boot-starter-boot:
This package is causing the issue.

<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>

Source : https://github.com/skyscreamer/JSONassert
Im guessing somthing in this breaks the discord api.

Quick note, this is included in the default https://start.spring.io config.

It's likely that some dependency causes a different version of the org.json.JSONObject class to load which can't handle the JSONString interface correctly.

Well i think this issue explains it pretty well: spring-projects/spring-boot#8706

TL;DR: org.skyscreamer:jsonassert depends on com.vaadin.external.google:android-json, which in turn is a "re-implementation" of org.json (using same packages + classes), effectively breaking anything that wants to use actual org.json

Then the solution is to exclude this android re-implementation. Closing as resolved.

Thanks for the explanation @kantenkugel