简体   繁体   中英

Discord Bot how do you role someone from dms? Python

Here is my code

@client.command()
async def roledm(ctx):
    member = ctx.message.author

When you dm the bot with !roledm it gets your name but how would it go to my discord server and role them? how do I role people without using discord.utils.get( member.server.roles) , I just want to use my server ID to role them.

You need to use get to return the roles in your guild.

@client.command()
async def roledm(ctx):
    guild = client.get_guild(id=0000000000000000000000) # Guild ID
    role = discord.utils.get(guild.roles, id=0000000000000000000000)  # Role ID
    member = guild.get_member(ctx.message.author.id)
    await member.add_roles(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM