Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

python - 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'
question from:https://stackoverflow.com/questions/65650641/discord-py-on-member-join-add-roles

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...