discord-api-docs icon indicating copy to clipboard operation
discord-api-docs copied to clipboard

Incorrect error on POST /users/@me/channels with invalid raw data

Open Edouard127 opened this issue 1 year ago • 11 comments

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

image image

Client and System Information

Postman https://web.postman.co// Browser Opera GX Windows 10 10.0.19043

Edouard127 avatar Jul 10 '22 03:07 Edouard127

I see no problem here lol

ratelimit-thief avatar Jul 10 '22 10:07 ratelimit-thief

I see no problem here lol

It should return { "code": 50109, "message": "The request body contains invalid JSON." }

Edouard127 avatar Jul 10 '22 14:07 Edouard127

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)

splatterxl avatar Jul 10 '22 14:07 splatterxl

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

Edouard127 avatar Jul 10 '22 14:07 Edouard127

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.

splatterxl avatar Jul 10 '22 14:07 splatterxl

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)

Edouard127 avatar Jul 10 '22 14:07 Edouard127

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

splatterxl avatar Jul 10 '22 14:07 splatterxl

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)

Edouard127 avatar Jul 10 '22 14:07 Edouard127

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.

splatterxl avatar Jul 10 '22 14:07 splatterxl

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

Edouard127 avatar Jul 10 '22 14:07 Edouard127

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 🙂

smddzcy avatar Aug 08 '22 18:08 smddzcy

This one also hit me and took about an hour of extra time to debug.

tmwilder avatar Jan 08 '23 02:01 tmwilder

This is fixed and will be going out with the next API deploy.

appellation avatar Jan 13 '23 01:01 appellation