【问题标题】:How to delete message with attached .exe file in discord.py如何在 discord.py 中删除带有附加 .exe 文件的消息
【发布时间】:2023-04-06 16:21:02
【问题描述】:

我正在用 Python 编写一个 Discord 机器人。如果附件的扩展名为 .exe 或 .dll,我需要编写一个删除消息的事件,我该怎么做?

【问题讨论】:

  • 到目前为止你尝试了什么?

标签: python-3.x discord discord.py


【解决方案1】:

要检查文件的扩展名,首先您必须获取带有message.attachments 的文件。然后创建一个循环并检查它们的名称。

@bot.event
async def on_message(message):
    for file in message.attachments:
        if file.filename.endswith((".exe", ".dll")):
            await message.delete()

【讨论】:

    猜你喜欢
    • 2018-06-29
    • 2021-01-21
    • 2021-06-13
    • 2018-04-29
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 2021-09-08
    相关资源
    最近更新 更多