【问题标题】:How would I check a Discord message for an image?我将如何检查图像的 Discord 消息?
【发布时间】:2021-07-05 20:00:00
【问题描述】:

我目前正在尝试为我的朋友制作一个机器人,以便他可以完成他的 Discord 服务器的制作,他希望该机器人能够使用 Discord.py 对图像添加反应。 到目前为止,这是我检查图像的代码:

async def on_message(ctx, message)
    pic_ext = ['.jpg','.png','.jpeg']
    for ext in pic_ext:
    if message.content.endswith(ext):
        ctx.send("Image!")```

【问题讨论】:

  • 您可以查看attachments。你已经这样做了吗?

标签: python discord discord.py bots


【解决方案1】:

正如 Dominik 所说:您应该检查附件。我发现这样做的一种方法是:

async def on_message(message):
    if len(message.attachments) > 0: #Checks if there are attachments
        for file in message.attachments:
            for ext in pic_ext:
                if file.filename.endswith(ext):
                    print(f"This message has an Image called: {file.filename}")

【讨论】:

    猜你喜欢
    • 2021-06-21
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 2020-08-01
    • 2017-04-25
    • 2021-01-24
    • 2022-08-19
    • 2018-06-24
    相关资源
    最近更新 更多