2

I am new to discord.py and hence I was trying to learn how it works Got a curiosity if we can send large files via a bot I can send ones smaller than 8Mb but it shows error for larger files

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 413 Payload Too Large (error code: 40005): Request entity too large

Is there some way to fix this?

Arpan Mandal
  • 21
  • 1
  • 2

1 Answers1

7

This error is due to Discord's own file upload limits.

  • As a regular user or bot, you can only upload files up to 8MB.
  • If you are in a server that is boosted up to level 2, you can upload up to 50MB files, even with your bot (I have tested this myself).
  • If you have Discord Nitro, you can upload up to 100MB files. I am not sure at the moment if your own Discord Nitro also applies to bots bound to your account, but I plan to test that this weekend. Tested, it does not apply to your bot

As you can tell, none of the cases above allow you to upload files that are larger than 150MB so you will need to reduce the file size if you want to upload the files. You could do one of two things:

  1. Do a try catch for the Payload Too Large exception and then ignore uploading files that are too large
  2. Use PIL to reduce the file size to 8MB (or 50MB for boosted servers) if it is too large AND is an image. This question is a good place to start How to reduce the image file size using PIL
Brade
  • 415
  • 1
  • 4
  • 13
  • 3
    Technically there's an option 3; upload the file to an external service and link it. – Random Davis Feb 25 '21 at 23:01
  • Yeah that is definitely an alternative. If it is an image, imgur may work. If not, dropbox or mega may work (assuming they all have APIs that you could use from python). – Brade Feb 25 '21 at 23:05
  • Any way to reduce file size for video files? I actually wanted the bot to download a video from a certain url and then post it in my server but I Don't have any method to reduce a Video file size to 8Mb or less ohter than reducing quality – Arpan Mandal Feb 26 '21 at 23:06
  • I doubt there is a way to reduce a 150MB video down to 8MB without a significant drop in quality. You would be better off just posting the URL. If it is a direct URL to an mp4, Discord *should* embed it properly but Discord doesn't always work very well with automatic embedding – Brade Feb 28 '21 at 22:36
  • @Brade Did you find out if Nitro applies to bots bound to your account? – pigeonburger Mar 30 '21 at 21:38
  • 1
    @pigeonburger see the edit. It does not apply to your bot sadly – Brade Mar 31 '21 at 22:37
  • @Brade Damn :( Appreciate your edit tho, thanks!! – pigeonburger Apr 01 '21 at 03:46