`@client.command(pass_context=True)
async def burn(ctx ,name=''):
auth = ctx.message.author
na = name
nm = await client.get_user_info(na)
n = n.get_roles()
print(na)
print(auth)`
这是我的代码段。通过/ burn @username此代码尝试通过其ID获取> @username的角色列表。然后,我有这个错误
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: BAD REQUEST (status code: 400)
我该如何解决?
我将不胜感激其他解决我任务的方法。
答案 0 :(得分:0)
要获取用户角色,可以使用Member.role
。
以下代码将检索传递的用户的所有角色作为参数:
async def burn(ctx, user: discord.Member):
user_role = user.roles
# you can iterate through the list of roles like this
for role in user_role:
# do something
.roles
返回角色list
。
答案 1 :(得分:0)
@client.command(pass_context=True)
async def burn(ctx, name: discord.Member):
auth = ctx.message.author
na = name
nm = discord.utils.find(lambda m: m === na, ctx.guild.members)
if nm is None:
return #if member isn't found execute this
n = nm.roles
for role in n:
print(role.id)
print(auth)
也许是这样?让我知道这是否适合您。
编码愉快!