I am trying to create dm
JavaScript
x
19
19
1
import requests
2
import json
3
4
url = 'https://discordapp.com/api/v6/users/@me/channels'
5
token = 'token'
6
body = {
7
'recipient_id': '123456789'
8
}
9
10
data = {'data':json.dumps(body)}
11
headers = {
12
"Authorization": token,
13
"Content-Type":"application/json"
14
}
15
16
r = requests.post(url, data=data, headers=headers)
17
print(r.content)
18
print(r.text)
19
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