Search code examples
pythondiscorddiscord.pydiscord-buttons

How to make a discord bot button that can download the file to the client's local with discord.py


I have made a button in the view class like this:

# Create Download Button
downlaodButton = Button(style=discord.ButtonStyle.grey, label='Download', row=1)
downlaodButton.callback = self.download
self.add_item(downlaodButton)

async def download(self, interaction: discord.Interaction):
 # Change Button Color And Accessbility After Clicking it
 self.children[-2].style = discord.ButtonStyle.blurple
 await interaction.response.edit_message(view=self)

 response = requests.get(self.image_url)

 with open('my_photo.png','wb') as f:
   f.write(response.content)

It does download the photos to my project directory but what I really want is when a user click that button it will start downloading the photo to their computer. Is it possible to implement with discord.py?


Solution

  • It's not possible with the discord.py api to make a download on a client pc. you can only upload the image in discord or give the user an url where he can download the image. If you use an url you can make it download directly depending on the browser. But the Discord Client won't download anything by clicking on a button.