Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the URL of an attachment in Discord.py

I am trying to get the URL of the file that the user attaches so I can use it later on in my code however I'm not too sure on how to go about doing so.

@client.command(pass_context=True)
async def readURL(ctx, url):
    # Do something

References:

  • discord.ext.commands
  • Attachment.url

1 Answers

If I'm understanding the question correctly, it would go like this:

@client.command() # context is automatically passed in rewrite
async def readURL(ctx):
    attachment = ctx.message.attachments[0] # gets first attachment that user
                                            # sent along with command
    print(attachment.url)

References:

  • Attachment.url
  • Message.attachments
like image 171
Diggy. Avatar answered Jan 26 '26 05:01

Diggy.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!