Can't download discord image url (403: Forbidden)

Viewed 556

I'm trying to use a bot to download discord image attachments but every request is met with a 403. Here's the code,

import discord
import urllib.request

print('Starting')

bot = discord.Client()

@bot.event
async def on_ready():
    print('Bot is ready!')

@bot.event
async def on_message(message):
    if not message.attachments:
        print(f'{message.author}: {message.content}')
    else:
        attachment = message.attachments[0]
        print(f'{attachment.url}')
        urllib.request.urlretrieve(attachment.url,f'{attachment.filename}.jpg')

bot.run('...')

I am completely lost please help thank you.

0 Answers
Related