I am trying to create dm
import requests
import json
url = 'https://discordapp.com/api/v6/users/@me/channels'
token = 'token'
body = {
'recipient_id': '123456789'
}
data = {'data':json.dumps(body)}
headers = {
"Authorization": token,
"Content-Type":"application/json"
}
r = requests.post(url, data=data, headers=headers)
print(r.content)
print(r.text)
This code receives response with “400: Bad request” message. I’ve read this but I can’t find any examples of correct usage of this request.
Advertisement
Answer
I finally understood my mistake, I shouldn’t pass dictionary as data but should pass a str, so I changed data=data to data=json.dumps(data) and it worked