discord.py, Cogs: How Would I assign a nickname on join?

61 Views Asked by At

The title says the gist of what I'm asking.

I'm trying to make an on_member_join event that will assign a nickname to new users. It's not giving me any output other than the standard new user joining. It's in a cog.

Any and all help would be appreciated! I've scoured the internet and can't seem to find an answer for this.

Note: I've been coding off-and-on with python and d.py since 2020, self-taught. I'm decently advanced in it, so don't worry if the answer is complex.

I've tried the following code:

    @commands.Cog.listener()
    async def on_member_join(self, member):
      await member.edit(nick="[G-P]" + member.name)

But it doesn't work. No erros are shown in the console either.

2

There are 2 best solutions below

0
On BEST ANSWER

I actually figured this out later. for some reason, the code just wasn't working. This actually did end up working as is!

3
On

You probably need the Intents.members intent enabled in your code and on the developer portal, so it would look like:

intents = discord.Intents.default()
intents.members = True

then add these intents to your bot constructor on your main file where you load your cogs. Also go to the Developer Portal https://discord.com/developers/applications and on the bot section and enable Server Members Intent, also make sure your bot has the manage nicknames permission on your server.