Creating a file download feature for Discord bot users using discord.py buttons

I’m working on a Discord bot and trying to figure out how to let users download files directly to their own computers when they click a button. Right now I have this setup:

# Setup file retrieval button
fileButton = Button(style=discord.ButtonStyle.primary, label='Get File', row=2)
fileButton.callback = self.fetch_file
self.add_item(fileButton)

async def fetch_file(self, interaction: discord.Interaction):
    # Update button appearance after click
    self.children[-1].style = discord.ButtonStyle.success
    await interaction.response.edit_message(view=self)
    
    file_response = requests.get(self.file_link)
    
    with open('downloaded_image.jpg', 'wb') as output_file:
        output_file.write(file_response.content)

The problem is this only saves the file to my bot’s server directory. What I actually need is for the file to download directly to the user’s device when they press the button. Can discord.py handle this kind of client-side downloading, or do I need a different approach?

Discord bots can’t trigger automatic downloads to users’ computers - browsers and Discord block this for security reasons. Your best bet is sending files as attachments through Discord’s chat. There’s actually a cleaner way than what Mike71 suggested. Skip saving files to your server and stream them directly: discord.File(io.BytesIO(requests.get(self.file_link).content), filename='your_file.jpg') then send with interaction.followup.send(). Users can right-click the attachment to save it. Just watch out for failed requests and file size limits.

This gets asked all the time - Discord won’t let bots force downloads to user machines, period. But here’s a workaround: use webhooks to post file links externally. Set up a webhook that catches your bot’s request and returns a proper HTTP download response. Way cleaner than attachments and users get real file downloads instead of saving Discord attachments.

Attachments work fine for most cases, but if you’re handling bigger files regularly, try setting up a simple Flask or FastAPI endpoint that serves files with proper download headers. When users click the Discord button, your bot responds with a link like yourserver.com/download/file123 that triggers a browser download instead of opening in Discord. Keeps your channels cleaner and users get more control over where files save. I’ve run this setup for months with no problems - just add basic rate limiting and maybe token-based access if your files need protection.

Everyone’s right - Discord can’t trigger direct downloads. But you’re approaching this wrong. Stop messing with file attachments or manual hosting and automate everything.

Use Latenode for your file processing. User clicks your Discord button → Latenode grabs the file, processes it, uploads to cloud storage, creates a temp download link, and sends it back to Discord.

I built this exact thing for our team bot. It pulls files from our API, auto-compresses them, stores on AWS S3 with expiring URLs, then drops clean download links in Discord. Takes 30 seconds to set up.

Users get real download links they can use anytime. Files don’t spam your Discord channels. You don’t deal with storage headaches on your bot server. Want file conversion or virus scanning? Add it without touching bot code.

The visual builder makes tweaking the workflow dead simple later.

yup, u can’t directly let users download files due to Discord’s setup. instead, use discord.File() to send it as an attachment. give this a shot: await interaction.followup.send(file=discord.File(io.BytesIO(file_response.content), filename='downloaded_image.jpg'))

You can’t do this with Discord’s API. Bots run server-side and can’t access users’ local files - that’d be a massive security risk. Here’s a better workaround: host your files on a web server and send download links instead. GitHub releases, Google Drive with public sharing, or a simple web endpoint all work great. When someone clicks your button, just respond with an embed containing the download URL. Users get more control over where they save stuff, and you won’t spam channels with huge attachments. Just add proper access controls if the files are sensitive.