title: How do I download an attachment from a discord channel?
body: <p>So, I have been trying to figure out how to download an attachment but I can't seem to figure out how. ctx.message.attachments[0].url doesnt work.</p>
  <pre><code>import discord
  from discord.ext import commands
  
  client = commands.Bot(command_prefix = '-')
  
  @client.command(name='setupwelcome', help='Sets up the welcome message.')
  async def setup(ctx, msgid:int):
    await ctx.send(&quot;Enter welcome message here (If it is a multiline message, write the whole welcome message on a text editor and paste it on discord.&quot;)
    welcomeMessage = await client.wait_for(&quot;message&quot;)
    await ctx.send(&quot;Do you want to include an image in your welcome message?&quot;)
    decisionMessage = await client.wait_for(&quot;message&quot;)
    if decisionMessage.content.lower() == 'y':
      await ctx.send(&quot;Upload the image you want to use:&quot;)
      imageUsed = await ctx.message.attachments[0].url
  </code></pre>
  <p>I keep getting this in my console.</p>
  <pre><code>Ignoring exception in command setupwelcome:
  Traceback (most recent call last):
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py&quot;, line 85, in wrapped
      ret = await coro(*args, **kwargs)
    File &quot;main.py&quot;, line 14, in setup
      imageUsed = await ctx.message.attachment[0].url
  AttributeError: 'Message' object has no attribute 'attachment'
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py&quot;, line 939, in invoke
      await ctx.command.invoke(ctx)
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py&quot;, line 863, in invoke
      await injected(*ctx.args, **ctx.kwargs)
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py&quot;, line 94, in wrapped
      raise CommandInvokeError(exc) from exc
  discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Message' object has no attribute 'attachment'
  </code></pre>
  <p>After fixing imageUsed I get an index error</p>
  <pre><code>Ignoring exception in command setupwelcome:
  Traceback (most recent call last):
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py&quot;, line 85, in wrapped
      ret = await coro(*args, **kwargs)
    File &quot;main.py&quot;, line 14, in setup
      imageUsed = await ctx.message.attachments[0].url
  IndexError: list index out of range
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py&quot;, line 939, in invoke
      await ctx.command.invoke(ctx)
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py&quot;, line 863, in invoke
      await injected(*ctx.args, **ctx.kwargs)
    File &quot;/home/runner/WelcomeBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py&quot;, line 94, in wrapped
      raise CommandInvokeError(exc) from exc
  discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range
  </code></pre>