add_roles的Discord.py问题

时间:2020-09-06 23:31:36

标签: python discord.py

@client.command()
async def vmute(ctx, user, time, * reason) :
    role = discord.utils.get(ctx.guild.roles, name="VcMuted" )
    await user.add_roles(role)
    print(user, role, time)

我真的不知道我在做什么错。使用user,我最终得到:

AttributeError: 'str' object has no attribute 'add_roles'

与客户端(又名bot)一起,我最终得到:

AttributeError: 'Bot' object has no attribute 'add_roles'

我一直在搜索10个堆栈页面,API页面,并用谷歌搜索1小时。我不知道我在这里想念什么。如果有人能告诉我删除角色的操作员是什么,我将不胜感激。这是我的一个命令,我是python的新手。这只是我无法运行的小事情。

1 个答案:

答案 0 :(得分:0)

user参数返回一个字符串,使用type hints来指定类型,就像user: discord.Member一样。

@client.command()
async def vmute(ctx, user: discord.Member, time, *reason):
    role = discord.utils.get(ctx.guild.roles, name="VcMuted")
    await user.add_roles(role)
    print(user, role, time)