nad*_*nad 8 python bots discord discord.py
我一直在尝试我发现可能有效的所有代码,但是命令没有加载(它说机器人正在输入然后停止)或者只是机器人本身不起作用。我正在使用 Python。
Avi*_*hai 32
我知道您的问题已经解决,但我会发布一个答案,以便遇到同样问题的人能够轻松找到解决方案。
要发送图像或 GIF,这里有两个选项(改编自此处):
打开文件并直接发送到频道:
with open('my_image.png', 'rb') as f:
picture = discord.File(f)
await channel.send(file=picture)
Run Code Online (Sandbox Code Playgroud)
直接传递文件名:
await channel.send(file=discord.File('my_image.png'))
Run Code Online (Sandbox Code Playgroud)
以下是一些有用的链接:
小智 5
或者,您可以通过将链接添加为要由机器人发送的标准消息来使用图像/gif 的 URL。
async def _cowgif(self, ctx):
await ctx.send("http://imgur.com/gallery/YiMUiop")
Run Code Online (Sandbox Code Playgroud)
请注意,这是一个异步请求。