I want to send discord.png
to a text channel using Python and the Discord API, but I keep getting an error:
{"message": "Cannot send an empty message", "code": 50006"}
I think I've done everything as the Documentation said, and I don't know what's the problem. I know, I could just use an already existing python library for this (like discord.py) but I'm only playing with the API, and I cant't figure out what is the issue here.
headers = {"Authorization": f"Bot {TOKEN}", "Content-Type": "multipart/form-data"}
f = open("discord.png", "rb")
file_data = f.read()
f.close()
file_data = base64.b64encode(file_data).decode()
payload_json = '{"content": "Discord", "tts": False}'
data = {
"content": "Discord",
"tts": False,
"file": file_data
}
headers["User-Agent"] = "DiscordBot"
#headers["Content-Type"] = "multipart/form-data" #edited but then realised i already set the content-type
headers["Content-Disposition"] = 'form-data; name="file" filename="discord.png"'
r = requests.post(f"{http_api}/channels/{CHANNEL_ID}/messages", data, headers=headers)
print(r.content)