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?
推荐答案
您在guild.audit_logs(limit = 100)中将 async用于...该函数具有更多不同的参数,您可以全部找到这里.
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屋!