【发布时间】:2023-04-06 16:21:02
【问题描述】:
我正在用 Python 编写一个 Discord 机器人。如果附件的扩展名为 .exe 或 .dll,我需要编写一个删除消息的事件,我该怎么做?
【问题讨论】:
-
到目前为止你尝试了什么?
标签: python-3.x discord discord.py
我正在用 Python 编写一个 Discord 机器人。如果附件的扩展名为 .exe 或 .dll,我需要编写一个删除消息的事件,我该怎么做?
【问题讨论】:
标签: python-3.x discord discord.py
要检查文件的扩展名,首先您必须获取带有message.attachments 的文件。然后创建一个循环并检查它们的名称。
@bot.event
async def on_message(message):
for file in message.attachments:
if file.filename.endswith((".exe", ".dll")):
await message.delete()
【讨论】: