I'm trying to make a bot that can see when a channel is deleted but I keep getting this error
Ignoring exception in on_guild_channel_delete
Traceback (most recent call last):
File "/home/runner/securityBotV2/venv/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
TypeError: on_guild_channel_delete() takes 1 positional argument but 2 were given
Here is my code
async def on_guild_channel_delete(channel):
entry = await channel.guild.audit_logs(action=discord.AuditLogAction.channel_delete, limit=1).get()
user = client.get_user(int(ID))
await user.send(
"User {} deleted channel {} at time {}".format(entry.user.name, channel.name, entry.created_at)
)
I can't find any errors in my code, What am I doing wrong?
CodePudding user response:
You're forgetting that the first argument in any commands is the context. So instead of your code do
async def on_guild_channel_delete(ctx, channel):
entry = await channel.guild.audit_logs(action=discord.AuditLogAction.channel_delete, limit=1).get()
user = client.get_user(int(ID))
await user.send(
"User {} deleted channel {} at time {}".format(entry.user.name, channel.name, entry.created_at)
)