mikthatguy
mikthatguy

Reputation: 21

Save an attachment from a command

I want to make my bot download and save locally the attachments sent in the command (

see the attachment:
see the attachment

is it possible because the only thing I could find is this and it doesn't work as I wanted:

@client.command()
async def hello(ctx):
    files = []
    for attachment in ctx.message.attachments:
        fp = BytesIO()
        await attachment.save(fp)

Upvotes: 2

Views: 3390

Answers (1)

ChrisDewa
ChrisDewa

Reputation: 642

dont use BytesIO as that's meant to be use in memory, just add the filename you wish

@client.command()
async def hello(ctx):
    files = []
    for attachment in ctx.message.attachments:
        # fp = BytesIO()
        await attachment.save(attachment.filename)

In this case i used the same filename as the attachment.

Upvotes: 3

Related Questions