Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 245
nad Avatar asked Sep 09 '18 03:09

nad


People also ask

Can Discord bots have GIFs?

Let's face it, everyone loves Nitro for the emotes and avatars. But let bots have . gifs for avatars as well! Maybe only one bot can have it, but that's one of the coolest features on Discord!

How do I send an image to a discord bot?

Normally you can just send the url of the discord image and discord will do it. If it local however, https://stackoverflow.com/questions/52241051/i-want-to-let-my-discord-bot-send-images-gifs 5 months ago

How do I add GIFs to my Discord messages?

You’ll see the GIF icon hanging out with the emoji picker in your text channels. By clicking on the GIF icon, you’ll find a variety of categories. All that much more accessible for your GIF needs. You can also use the search bar at the top to really capture your emotions. Note: Make sure you've updated your Discord app fully on your mobile device!

How do I upload images to a discord text channel?

Here we'll focus on two different methods of uploading images and other embedded media into a Discord text channel. The first way to upload an image into Discord is that simple- Just drag an image or GIF from another source and drop it into the Discord window.

Did You Know you can search for and post gifs on Discord?

Did you know, you can search for and post GIFs directly on the Discord app? Let us assist you with sending GIFs to your friends in a snap! No more hunting around folders or websites! First things first - you can only send gifs, not jif. What does this Article Cover? It’s super simple!


2 Answers

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):

  1. 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)
    
  2. Passing the file name directly:

    await channel.send(file=discord.File('my_image.png'))
    

Here are some useful links:

  • discord.py docs
  • Related discord.py FAQ
  • discord.py GitHub repository
  • Related discord.py GitHub post
like image 97
Aviv Shai Avatar answered Oct 23 '22 10:10

Aviv Shai


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.

like image 31
Evan Scallan Avatar answered Oct 23 '22 08:10

Evan Scallan