#How to get the user who triggered an event?

1 messages · Page 1 of 1 (latest)

mellow kernel
#

Is it possible to get a user who triggered on_guild_channel_delete()? I know the only parameter there is channel, but I'm just asking because I think I missed something.

regal whale
#

could read the audit log entry

prisma widget
#

You have to read the audit log entry

mellow kernel
#

I thought

#

But the event doesn't work

#

It won't do anything

#

I tried to set moderation intent, but it was useless

regal whale
#

you need guilds intent

#

which is part of default intents

mellow kernel
#

Nothing changed

regal whale
#

show your code

mellow kernel
#
# Intents

intents = discord.Intents.default()
intents.message_content = True
intents.guilds = True
bot = discord.Bot(help_command = None, intents=intents)

...

# The code

@commands.Cog.listener()
async def on_audit_log_entry(entry):
        print(entry)
regal whale
#

guilds is part of default, you don't need to set it

#

oh, I thought you were talking about the channel delete event

mellow kernel
#

Yes, I know

#

Ohh no

#

That's working

#

My bot can't read audit logs

#

That's the problem

regal whale
#

yea well then give it permissions for that

mellow kernel
#

I did...I had given it moderation intent and it didn't work

#

And the bot has administrator permission

regal whale
#

ah

mellow kernel
#

So it must access it

regal whale
#

And the cog you put that in is loaded for sure?

mellow kernel
#

Yes

#

For sure

regal whale
#

Hm, not sure why it doesn't work then
Maybe someone else knows why

mellow kernel
#

Could it be a library bug?

regal whale
#

Highly doubt it

mellow kernel
#

Hmm

#

Okay then, leave it as it is

#

I'll find another way

#

Thank you

prisma widget
#

Just get the audit log on the event.

forest cradle
#
@commands.Cog.listener()

without a self?

prisma widget
#

.rtfm guild.audit

fervent blazeBOT
regal whale
forest cradle
#

In a cog it does ;3

mellow kernel
#

It does, but it would throw an error

#

My console is clear

forest cradle
#

how did you load the cog?

mellow kernel
#

I forgot to write self

#

But I have it in my code

mellow kernel
regal whale
#

you can also do bot.load_extensions("cogs/")
not sure if that's the exact right syntax, I can't check my code rn, but just because it's simpler to manage a lot of cogs this way

mellow kernel
#

I tried it, it threw an error

regal whale
#

yea I'll send the right one in a bit, not too important rn tho

mellow kernel
#

But that's okay, I have a cogs folder and all cogs in there

mellow kernel
#

Soo, what should I do with that event?

regal whale
regal whale
#

that'd be my only guess apart from that, if that's not the issue I'd just say do what dark said and get the audit log entry when the channel delete event is called

mellow kernel
#

That syntax you wanted to show me

regal whale
#

ye I'll send it when I can check my code

mellow kernel
#

And all of them works

#

Except the audit log one

forest cradle
#
client.load_extension("cogs", recursive=True)

if you want to load all the cogs in one folder

#

without any hard coding list

mellow kernel
#

Ohh, that's cool

#

Thank you

regal whale
#

my way was bot.load_extensions("cogs"), but you have to do bot.load_extensions("cogs.subfolder") for any subfolders

mellow kernel
#

By the way, did you come up with a solution to that event?

thorn geode
#

(how you code it)

mellow kernel
#
import discord
from discord.ext import commands

class Events(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_audit_log_entry(self, entry):
        print(entry)

def setup(bot):
    bot.add_cog(Events(bot))
#

For example

thorn geode
mellow kernel
#

I think I did, but I'm not sure

#

Wait

sage wyvernBOT
thorn geode
mellow kernel
#

Yes, this one works

sage wyvernBOT
mellow kernel
#

Thank you