简体   繁体   English

Discord Bot 你如何扮演 dms 的角色? Python

[英]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?当你用 !roledm dm 机器人时,它会得到你的名字,但它如何进入我的不和谐服务器并扮演他们的角色? how do I role people without using discord.utils.get( member.server.roles) , I just want to use my server ID to role them.我如何在不使用 discord.utils.get(member.server.roles) 的情况下扮演角色,我只想使用我的服务器 ID 来扮演他们的角色。

You need to use get to return the roles in your guild.您需要使用get返回公会中的角色。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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