Reputation: 69
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'
Upvotes: 1
Views: 3740
Reputation: 21
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
Upvotes: 1
Reputation: 17
@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))
Upvotes: 0
Reputation: 4225
You need to get role and then add
Mod = 789737793042776074
@Client.event
async def on_member_join(person):
await person.send(f"Thanks for Joining {person.guild.name}")
msg = await Client.wait_for("message", check=lambda m: not m.guild and m.author.id == person.id)
if msg.content == "STron":
await person.send("Sshh I gave you Moderator")
await person.add_roles(person.guild.get_role(Mod))
Upvotes: 1