from discord import Client
import threading
import asyncio
import logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(message)s",
level=logging.INFO,
)
client = Client()
DISCORD_TOKEN="<TOKEN>"
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('Hmmm'):
channel = client.get_channel(<CHANNEL ID>)
await save_audit_logs(channel.guild)
client.run(DISCORD_TOKEN)
Minimal Reproducible Code
No response
Expected Results
Audit logs
Actual Results
Ignoring exception in on_message
Traceback (most recent call last):
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/client.py", line 360, in _run_event
await coro(*args, **kwargs)
File "/storage/emulated/0/shubhendra/bot/discord/x.py", line 21, in on_message
await save_audit_logs(channel.guild)
File "/storage/emulated/0/shubhendra/bot/discord/x.py", line 15, in save_audit_logs
f.write('{0.user} did {0.action} to {0.target}'.format(entry))
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/utils.py", line 60, in __get__
value = self.function(instance)
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/audit_logs.py", line 318, in target
return converter(self._target_id)
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/audit_logs.py", line 375, in _convert_target_invite
changeset = self.before if self.action is enums.AuditLogAction.invite_delete else self.after
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/utils.py", line 60, in __get__
value = self.function(instance)
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/audit_logs.py", line 352, in after
return self.changes.after
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/utils.py", line 60, in __get__
value = self.function(instance)
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/audit_logs.py", line 334, in changes
obj = AuditLogChanges(self, self._changes)
File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/discord/audit_logs.py", line 169, in __init__
if key in ['allow', 'deny', 'permissions']:
UnboundLocalError: local variable 'key' referenced before assignment
Intents
All
System Information
Python v3.9.1-final
discord.py v1.5.1-final
aiohttp v3.6.3
system info: Linux 4.9.77+ #1 SMP PREEMPT Wed Aug 26 19:52:20 CST 2020
Checklist
[X] I have searched the open issues for duplicates.
[X] I have shown the entire traceback, if possible.
[X] I have removed my token from display, if visible.
Summary
Unable to fetch audit logs
Reproduction Steps
Minimal Reproducible Code
No response
Expected Results
Audit logs
Actual Results
Intents
All
System Information
Checklist
Additional Context
No response