【问题标题】:Discord.py How to get the list of all the audit logs?Discord.py 如何获取所有审计日志的列表?
【发布时间】:2020-07-16 12:51:43
【问题描述】:

我正在寻找一种将所有审核日志打印在 txt 文件中的方法,因为我希望机器人随后将该 txt 文件发送到管理员的电子邮件。如何获取所有审核日志?

【问题讨论】:

    标签: discord.py discord.py-rewrite


    【解决方案1】:

    你使用async for ... in guild.audit_logs(limit=100) 该函数还有很多不同的参数,你可以找到here

    这是一个如何使用它的示例:

    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)
    

    附加信息: 这是一个异步迭代器,这意味着它只能在异步函数中使用

    每个审计日志条目都是this class,我建议仔细阅读一下。

    【讨论】:

      猜你喜欢
      • 2020-10-19
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 2017-09-19
      • 2018-04-26
      相关资源
      最近更新 更多