Discord.py 如何获取所有审计日志的列表? [英] Discord.py How to get the list of all the audit logs?
问题描述
我正在寻找一种将所有审核日志打印在 txt 文件中的方法,因为我希望机器人将该 txt 文件发送到管理员的电子邮件.如何获取所有审核日志?
I'm searching a way to get all the audit logs printed on a txt file, because I want then the bot to send that txt file to the admin's email. How can I get all the audit logs?
推荐答案
你使用 async for ... in guild.audit_logs(limit=100)
该函数有更多不同的参数,您可以找到所有这些参数 这里.
You use async for ... in guild.audit_logs(limit=100)
The function has a lot more different parameters, all of which you can find here.
这是一个如何使用它的示例:
Here is an example on how to use it:
async def save_audit_logs(guild):
with open(f'audit_logs_{guild.name}', 'w+') as f:
async for entry in guild.audit_logs(limit=100):
f.write('{0.user} did {0.action} to {0.target}'.format(entry))
@client.event
async def on_message(message):
if message.content.startswith('audit'):
await save_audit_logs(message.channel.guild)
附加信息:这是一个异步迭代器,这意味着它只能在异步函数中使用.
Additional info: This is an async iterator, meaning it can only be used in async functions.
每个审核日志条目都属于此类,我建议您阅读一下.
Every audit log entry is of this class, I recommend reading up on it a bit.
这篇关于Discord.py 如何获取所有审计日志的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!