我想让我的不和谐机器人发送图像/GIF [英] I want to let my discord bot send images/gifs

查看:73
本文介绍了我想让我的不和谐机器人发送图像/GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在拼命地寻找答案,但是我找不到任何有帮助的东西!我一直在尝试我发现的所有可能起作用的代码,但是该命令无法加载(它表示该机器人正在键入然后停止),或者只是该机器人本身不起作用.

我不是一个很好的编码器,所以我只能写消息,但是我完全不知道如何让它发送图像.顺便说一下,我正在使用python.

对不起,如果已经回答;;

解决方案

我知道您的问题已经解决,但是我将发布答案,以便遇到相同问题的人可以轻松找到解决方案.

要发送图像或GIF,这是两个选项(改编自此处):

  1. 打开文件并将其直接发送到频道:

    with open('my_image.png', 'rb') as f:
        picture = discord.File(f)
        await channel.send(channel, picture)
    

  2. 直接传递文件名:

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

以下是一些有用的链接:

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 load (it says the bot is typing and then stops) or just the bot itself doesn't work.

I'm not a very good coder so I've only been able to write messages but I have absolutely no clue on how to let it send images. I'm using python, by the way..

Sorry if this has already been answered ;;

解决方案

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:

这篇关于我想让我的不和谐机器人发送图像/GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆