'I want to let my Discord Bot send images/gifs
I've been trying every bit of code I find that might work but either the command doesn't load (it says the bot is typing and then stops) or just the bot itself doesn't work. I'm using Python.
Solution 1:[1]
I know your problem is already solved, but I will post an answer so that people who have this same problem will be able to find the solution easily.
To send an image or GIF, here are two options (adapted from here):
Opening the file and sending it directly to the channel:
with open('my_image.png', 'rb') as f: picture = discord.File(f) await channel.send(file=picture)Passing the file name directly:
await channel.send(file=discord.File('my_image.png'))
Here are some useful links:
Solution 2:[2]
Alternatively, you can use URLs for images/gifs by adding the link as a standard message to be sent by your bot.
async def _cowgif(self, ctx):
await ctx.send("http://imgur.com/gallery/YiMUiop")
Note that this is an asynchronous request.
Solution 3:[3]
You can use file parameter
await ctx.send("Any text", file=Discord.File("NAME.png"))
If u get an error with file path:
import os
os.chdir("C:/Users/COMPUTER-NAME/Desktop/Bot-Folder/")
await ctx.send("Any text", file=Discord.File("NAME.png"))
If you use embed:
embed.set_image(url="IMG_URL")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Evan Scallan |
| Solution 3 | Ali FGT |
