Python 如何在discord.py最新版本中分配角色?
我已经找了一整天了,我似乎找不到一个合适的方式来分配角色给成员。我尝试了几种分配角色的方法:Python 如何在discord.py最新版本中分配角色?,python,python-3.x,discord.py,discord.py-rewrite,Python,Python 3.x,Discord.py,Discord.py Rewrite,我已经找了一整天了,我似乎找不到一个合适的方式来分配角色给成员。我尝试了几种分配角色的方法: @client.command(pass_context=True) async def claimrank(ctx, role: discord.Role): user = ctx.message.author await user.add_roles(role='Rookie') 以及: 更糟糕的是,通过这两次尝试,我没有得到任何错误,但代码没有做任何事情。 请帮忙! 提前谢谢。我
@client.command(pass_context=True)
async def claimrank(ctx, role: discord.Role):
user = ctx.message.author
await user.add_roles(role='Rookie')
以及:
更糟糕的是,通过这两次尝试,我没有得到任何错误,但代码没有做任何事情。
请帮忙!
提前谢谢。我今天从一篇帖子上得到了这个。我将编写代码并查找原始帖子
@client.command(pass_context=True)
async def addrole(ctx):
user = ctx.message.author
role = 'role' #change the role here
try:
await user.add_roles(discord.utils.get(user.guild.roles, name=role))
except Exception as e:
await ctx.send('Cannot assign role. Error: ' + str(e))
找到@Patrick Haugh的原始帖子:
@client.command(pass_context=True)
async def addrole(ctx):
user = ctx.message.author
role = 'role' #change the role here
try:
await user.add_roles(discord.utils.get(user.guild.roles, name=role))
except Exception as e:
await ctx.send('Cannot assign role. Error: ' + str(e))