Python discord.py中角色的命令

Python discord.py中角色的命令,python,discord,discord.py,Python,Discord,Discord.py,我正在尝试为我的discord bot添加一个验证系统,其中一个执行c.verify以获得已验证的角色,但是我在提供角色时遇到了问题,并且我发现的一切都不起作用。这就是我所拥有的: @commands.command(pass_context=True) async def verify(self, ctx): role = get(ctx.author.roles, name="TOS Verified") if ctx.ch

我正在尝试为我的discord bot添加一个验证系统,其中一个执行c.verify以获得已验证的角色,但是我在提供角色时遇到了问题,并且我发现的一切都不起作用。这就是我所拥有的:

    @commands.command(pass_context=True)
    async def verify(self, ctx):
        role = get(ctx.author.roles, name="TOS Verified")
        if ctx.channel.id == 769016529450303519:
            await ctx.message.delete()
            await ctx.send(f"{ctx.author.mention} has been verified.")
            sleep(1)
            await ctx.channel.purge(limit = 1)
            await bot.add_roles(ctx.message.author, role)
        else:
            await ctx.message.delete()
            await ctx.send("You can not verify here.")

我得到的错误是“bot没有属性add_roles”。在必须添加角色之前,一切正常,但我不知道为什么我不能添加角色。

好吧,让我们从顶部开始

role = get(ctx.author.roles, name="TOS Verified")
在这里,您正试图从运行命令的人员那里获得一个名为
TOS Verified
的角色,这毫无意义,因为如果他们试图验证,他们就不会拥有该角色。实际上,我们希望从公会的角色中获得以下信息:

role = get(ctx.guild.roles, name="TOS Verified")
第二个问题

await bot.add_roles(ctx.message.author, role)
Bot
没有属性,查看文档,它告诉我们它实际上是一个成员方法。在您的情况下,您的成员对象将是
ctx.author

await ctx.author.add_roles(role)

我已经这样做了,现在我得到的错误是“未知角色”有没有办法通过ID找到角色?我认为这是一个问题,因为它没有正确地抓取角色,因为我只是给它起了名字,即使我把它复制/粘贴到了代码中。你可以使用,
role=ctx.guild.get_role(role_ID)