【问题标题】:How to make discord bot send images from an online link python如何使不和谐机器人从在线链接python发送图像
【发布时间】:2021-06-30 06:25:48
【问题描述】:

我希望我的 discord bod 在使用命令时从在线链接发送图像,而不是使用本地链接。我该怎么做?

【问题讨论】:

  • 欢迎来到堆栈!你说的在线链接是什么意思?你试过什么吗?请查看How to ask a good question 并相应地编辑您的问题。

标签: python-3.x discord.py


【解决方案1】:

详细解释在FAQ of the docs

import io
import aiohttp

async with aiohttp.ClientSession() as session:
    async with session.get(my_url) as resp:
        if resp.status != 200:
            return await channel.send('Could not download file...')
        data = io.BytesIO(await resp.read())
        await channel.send(file=discord.File(data, 'cool_image.png'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多