pycord icon indicating copy to clipboard operation
pycord copied to clipboard

Add file kwarg in discord.Message.edit

Open caffe-ian opened this issue 5 years ago • 3 comments

Summary

Add file keyword argument in discord.Message.edit

What is the feature request for?

The core library

The Problem

Add file keyword argument in discord.Message.edit. I've looked up official Discord's API and it already supports file kwarg. Link: Official Discord API

It would be useful to add it for editing an image or file sent in the message.

The Ideal Solution

Add file kwarg in discord.Message.edit

The Current Solution

No response

Additional Context

No response

caffe-ian avatar Nov 05 '21 06:11 caffe-ian

Solution to this issue I implemented it myself. I used the send_multipart_helper function in discord.http.py but adding message.edit payload into the form, and also changed route method to 'PATCH', thats all you have to do. You will understand everything once you read the send_multipart_helper function in discord.http.py in the source.

Basically what you have to do is

  1. In discord.Message.edit function, check if file/files kwarg is not None -> Go to step 2. Else edit message as normal way
  2. Call the send_multipart_helper function but sending the discord.Message.edit arguments to the function.
  3. Add discord.Message.edit arguments into the payload variable in the function
  4. Add the payload to the form value

And then request as usual with the route arg, form and files kwarg.

Might not be the best solution but that is what I did. No errors at all.

caffe-ian avatar Nov 07 '21 13:11 caffe-ian

You can PR that if you feel its good.

CodeWithSwastik avatar Nov 07 '21 14:11 CodeWithSwastik

Done in #417.

Dorukyum avatar Nov 11 '21 16:11 Dorukyum