What am I doing wrong?
@bot.event
async def on_member_join(member):
print(f"{member} join")
role_1 = member.guild.get_role(start_role_id)
await member.add_roles(role_1)
I searched for answers on the forums for a long time and nothing helped.
Did you enable intents
in Discord Developer Portal ? while initializing bot add intents=discord.Intents.all()
. Also I fixed your code.
bot = commands.Bot(command_prefix='', intents=discord.Intents.all())
@bot.event
async def on_member_join(member):
print(f"{member} join")
role1 = discord.utils.get(member.server.roles, id=role_id)
await member.add_roles(role1)
Try this:
bot = commands.Bot(command_prefix='PREFIX_HERE',
intents=discord.Intents.all())
@bot.event
async def on_member_join(member):
print(f"{member} has joined")
my_role = discord.utils.get(member.guild.roles, id=role_id)
await member.add_roles(my_role)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.