I don't even know why you're making this so complicated.
Since you already have the member
as an "argument" you can work with it and don't have to define member
again.
We can get the ID of member
very easily with member.id
. If we want to compare this with a real ID, we do the following:
if member.id = TheIDHere:
# Do what you want to do
The function for the role is correct, yet I cannot find a use for await member.id(member)
. What is the point of this/has it any use?
How you add the role at the end is also correct, but the code must be indented properly and best you work with an if / else
statement, otherwise the bot will still give an error at the end in the console if always the wrong member
joins.
The whole code:
@client.event
async def on_member_join(member):
role = discord.utils.get(member.guild.roles, id=IDOfTheRole) # Get the role from member.guild and the id
if member.id == TheIDHere: # If the member.id matches
await member.add_roles(role) # Add the role for the specific user
else: # If it does not match
return # Do nothing
You may also need to enable the members
Intent, here are some good posts on that: