pycord icon indicating copy to clipboard operation
pycord copied to clipboard

Files and Attachment are not working, "giving attribute errors"

Open ritwick06 opened this issue 5 years ago • 5 comments

Summary

discord.Files and discord.Attachment are giving attribute error when awaited or saved

Reproduction Steps

bytesio = io.BytesIO() background.save(bytesio, "PNG") bytesio.seek(0) file = Attachment(bytesio, filename="yourfile.png") await ctx.send(file=file)

Minimal Reproducible Code

No response

Expected Results

bytesio = io.BytesIO()
background.save(bytesio, "PNG")
bytesio.seek(0)
file = Attachment(bytesio, filename="yourfile.png")
await ctx.send(file=file)

tthought this will send me the image (file)

Actual Results

gave me an attribute error image

Intents

default

System Information

image

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

No response

ritwick06 avatar Sep 14 '21 14:09 ritwick06

The error clearly states that the background variable which is an Editor object doesnt have a "save" attribute. Are you sure this problem is related to this library?

Dorukyum avatar Sep 14 '21 14:09 Dorukyum

The error clearly states that the background variable which is an Editor object doesnt have a "save" attribute. Are you sure this problem is related to this library?

yes because i even tried without saving

ritwick06 avatar Sep 14 '21 14:09 ritwick06

The following example seemed to work for me in my testing with discord.File, I used a random image for reference

        # Reading bytes from a random image into a bystream.
        with open("random_image.png", "rb") as image:
            f = image.read()
            b = bytearray(f)

        # Creating BytesIO object from bytestream
        myio = io.BytesIO(b)

        # Sending file named "random_image_2.png" composed from the bytestream
        file = discord.File(myio, filename="random_image_2.png")
        await ctx.send(file=file)

OEUG99 avatar Sep 14 '21 16:09 OEUG99

I'm using easy_pil

On Tue, 14 Sep 2021, 9:52 pm OEUG99, @.***> wrote:

The following example seemed to work for me in my testing with discord.File, I used a random image for reference `

Reading bytes from a random image into a bystream.

with open("random_image.png", "rb") as image: f = image.read() b = bytearray(f)

# Creating BytesIO object from bytestream
myio = io.BytesIO(b)

# Sending file named "random_image_2.png" composed from the bytestream
file = discord.File(myio, filename="random_image_2.png")
await ctx.send(file=file)

`

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Pycord-Development/pycord/issues/193#issuecomment-919308818, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATUQKPJSMVQ4KJGIOZ3GVHDUB5ZDPANCNFSM5EAI56QA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ritwick06 avatar Sep 14 '21 16:09 ritwick06

This is not a bug with this library, your background doesn't have a save method.

CodeWithSwastik avatar Sep 15 '21 13:09 CodeWithSwastik