如何检查图像的 Discord 消息?

时间:2021-04-09 23:51:40

标签: python discord discord.py bots

我目前正在尝试为我的朋友制作一个机器人,以便他可以完成他的 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!")```

1 个答案:

答案 0 :(得分:0)

正如 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}")
相关问题