RoosterQMonee
RoosterQMonee

Reputation: 36

How to see when a channel is deleted with discord.py?

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?

Upvotes: 0

Views: 479

Answers (1)

TheUltimateGuide
TheUltimateGuide

Reputation: 353

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)
      )

Upvotes: 1

Related Questions