def get_responsible(self, guild: discord.Guild, action: str, *, target: discord.Member=None) -> discord.AuditLogEntry:
"""
Checks the audit log for recent action performed on some user.
:param guild: The :class:`discord.Guild` to look at.
:param action: The name of the :class:`discord.AuditLogAction` attribute to check for.
:param target: The targeted user to check for.
:returns: The audit log entry.
"""
try:
# get the audit logs for the action specified
entries = await guild.audit_logs(limit=1, action=getattr(discord.AuditLogAction, action)).flatten()
# only check for entries performed on target, and happened in the last 2 seconds
def check(entry):
created_ago = (datetime.datetime.utcnow() - entry.created_at).total_seconds()
return (entry.target == target if target else True) and created_ago <= 2
return discord.utils.find(check, entries)
except discord.Forbidden:
pass
评论列表
文章目录