'Discord PY On member Join add Roles
I am a bit new to Discord PY and am looking for a way to add roles if a person DM's a Key to the bot. I researched and typed this code but am getting errors please Help The Code IS
Mod = 789737793042776074
@Client.event
async def on_member_join(person):
async for guild in Client.fetch_guilds(limit=150):
channel = person
await channel.send(f"Thanks for Joining {guild.name}")
reply = await Client.wait_for('message', timeout=60)
if reply.content == 'STron':
# role = get(guild.roles, id = Mod)
await channel.send('Sshh I Gave you Moderator')
await person.add_roles(id = Mod)
I am getting an error
Ignoring exception in on_member_join
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "main.py", line 28, in on_member_join
await person.add_roles(id = Mod)
TypeError: add_roles() got an unexpected keyword argument 'id'
Solution 1:[1]
@client.event
async def on_member_join(user):
await user.send(f"Message and variables")
await user.add_roles(id) ##or await user.add_roles(ctx.guild.get_role(Name or Id))
Solution 2:[2]
async def on_member_join(member):
role = discord.utils.get(member.guild.roles, name="Role name here")
await member.add_roles(role)
This should help. Try and read the docs or research discord.utils.get
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user14994417 |
| Solution 2 | DoctorRiptide |
