Reputation: 121
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.
Upvotes: 12
Views: 133635
Reputation: 57
You can use file
parameter
await ctx.send("Any text", file=discord.File("NAME.png"))
If you get an error with file path:
import os
//Not necesarryif the fileis in the same folder!
os.chdir("C:/Users/COMPUTER-NAME/Desktop/Bot-Folder/")
await ctx.send("ANY TEXT", file=discord.File("NAME-OF-THE-IMAGE.png"))
If you use embed:
embed.set_image(url="DIRECT IMAGE URL")
Upvotes: 0
Reputation: 158
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.
Upvotes: 6
Reputation: 1048
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:
Upvotes: 54