I want to let my discord bot send images/gifs

前端 未结 1 1946
有刺的猬
有刺的猬 2021-02-10 00:07

I\'ve been desperately looking for answers but I can never find anything that helps! I\'ve been trying every bit of code I find that might work but either the command doesn\'t l

相关标签:
1条回答
  • 2021-02-10 00:37

    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(channel, 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
    0 讨论(0)
提交回复
热议问题