discord-api-docs
discord-api-docs copied to clipboard
Incorrect error on POST /users/@me/channels with invalid raw data
Description
Making a POST request to /users/@me/channels/
with an invalid raw data throws a Bots cannot use this endpoint
Steps to Reproduce
curl --location --request POST 'https://discord.com/api/v9/users/@me/channels' \ --header 'Authorization: Bot token' \ --header 'Content-Type: application/json' \ --data-raw '{ "data": { "recipient_id": user id } }'
Expected Behavior
Should returns a schema validation error
Current Behavior
{ "message": "Bots cannot use this endpoint", "code": 20001 }
Screenshots/Videos
Client and System Information
Postman https://web.postman.co// Browser Opera GX Windows 10 10.0.19043
I see no problem here lol
I see no problem here lol
It should return { "code": 50109, "message": "The request body contains invalid JSON." }
It should return
{ "code": 50109, "message": "The request body contains invalid JSON." }
It is completely valid JSON. What you might be thinking of is that it should return a required property missing error.
(Also the data should be top level, outside a data
field)
It should return
{ "code": 50109, "message": "The request body contains invalid JSON." }
It is completely valid JSON. What you might be thinking of is that it should return a required property missing error.
(Also the data should be top level, outside a
data
field)
Sending the same request without the data
property works perfectly
Do you mean sending { "recipient_id": 0000000 }
instead of sending it in { "data": { ... } }
?
If so your bug report is technically incorrect, the expected behaviour is a schema validation error.
Do you mean sending
{ "recipient_id": 0000000 }
instead of sending it in{ "data": { ... } }
?If so your bug report is technically incorrect, the expected behaviour is a schema validation error.
But why it responds with an error saying bots cannot access the endpoint ? It’s unrelated to the actual issue
(my mad I just woke up let me fix the actual issue behavior later)
But why does it respond with an error saying bots cannot access the endpoint?
The client uses this endpoint to create group DMs (which I'm pretty sure bots can't), so I presume instead of throwing a validation error it just tries to make a group DM
I assume the pseudocode of the actual logic would look similar to the following:
if req.recipient_id:
# make direct DM
else:
if auth.user.bot:
raise APIException("Bots cannot use this endpoint")
# etc
But why does it respond with an error saying bots cannot access the endpoint?
The client uses this endpoint to create group DMs (which I'm pretty sure bots can't), so I presume instead of throwing a validation error it just tries to make a group DM
The endpoint is for creating direct messages (in my case)
The endpoint is for creating direct messages (in my case)
Your case isn't entirely what the endpoint does. The endpoint is also used by the client to create group chats.
The endpoint is for creating direct messages (in my case)
Your case isn't entirely what the endpoint does. The endpoint is also used by the client to create group chats.
I meant that I was using it to create a direct message
I also had this same issue. The error message is wrong, it should complain about the request body, but instead it says bots cannot use the endpoint. Bots can use the endpoint, it's just that the bot submits the data wrong 🙂
This one also hit me and took about an hour of extra time to debug.
This is fixed and will be going out with the next API deploy.