如何在discord.py中删除附有.exe文件的邮件



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

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

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

最新更新