Reputation: 8704
I have written this small PoC for discord webhooks and i am getting error that Can not send empty string. I tried to google but couldn't find a documentation or an answer
here is my code
import requests
discord_webhook_url = 'https://discordapp.com/api/webhooks/xxxxxxxxxxxxxxxxxx/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
data = {'status': 'success'}
headers = {'Content-Type': 'application/json'}
res = requests.post(discord_webhook_url, data=data, headers=headers)
print(res.content)
Upvotes: 7
Views: 10455
Reputation: 11
In case anyone else finds this like I did, Ian's answer got me most of the way there but it's not 100%. At the moment, the developer docs state: Note that when sending a message, you must provide a value for at least one of content
, embeds
, components
, or file
.
So, for the above, the payload would have to be something like:
data = {'content': 'status = success'}
https://discord.com/developers/docs/resources/webhook#execute-webhook
Upvotes: 1
Reputation: 705
I'm late, but I came across this issue recently, and seeing as it has not been answered yet, I thought I document my solution to the problem.
For the most part, it is largely due to the structure of the payload being wrong.
https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html provides an example of a working structure. https://discordapp.com/developers/docs/resources/channel#create-message is the official documentation.
I was also able to get a minimum test case working using: {"content": "Test"}
.
If it still fails after that with the same error, the likely causes are:
\
When in doubt, ensure all values are populated, and not ""
. Through trial-and-error / the process of cancellation, you can figure out exactly what key-value pair is causing an issue, so I suggest playing with the webhook via curl before turning it into a full program.
Upvotes: 9