首页 > 解决方案 > “命令引发异常:AttributeError 'Nonetype' 对象没有属性 'id'” 给予设定角色时

问题描述

我正在尝试制作一个反应角色机器人,它能够在反应时设置给定的角色。我努力了:

verifyroleid = int(0)
@bot.command(pass_context=True)
@has_permissions(administrator=True)
async def set(ctx, *, roleid=None):
    em = discord.Embed(title="yBot  |  VERIFY")
    em.add_field(name="SUCCESS: ",value="Set {} as 'verify' role!".format(roleid))
    em.set_footer(text="© 2020 - Powered by yanuu ;k#2137")
    verifyroleid == roleid
    await ctx.send(embed=em)




@bot.command(pass_context=True)
async def verify(ctx):
    em = discord.Embed(title="yBOT  |  VERIFY")
    em.add_field(name="REACT: ", value="React '✅' to this message to get verified!", inline=False)
    em.set_footer(text="© 2020 - Powered by yanuu ;k#2137")
    message = await ctx.send(embed=em)
    await message.add_reaction("✅")
    reaction, user = await bot.wait_for("reaction_add")
    def check(reaction, user):
        return user != bot.user and str(reaction.emoji) in ["✅"]
    while True:
        try:
            reaction, user = await bot.wait_for("reaction_add")
            if str(reaction.emoji) == "✅":
                await message.remove_reaction(reaction, user)
                role = discord.utils.get(ctx.guild.roles, id=verifyroleid)
                await discord.Member.add_roles(user, role)
        except asyncio.TimeoutError:
            await message.delete()
            return

但这会导致错误:

回溯(最后一次调用):文件“C:\Users\macio\AppData\Roaming\Python\Python38\site-packages\discord\client.py”,第 333 行,在 _run_event await coro(*args, **kwargs ) 文件“C:\Users<..>\Documents\pythontest\diskord-test.py”,第 99 行,on_command_error 引发错误文件“C:\Users<..>\AppData\Roaming\Python\Python38\site -packages\discord\ext\commands\bot.py”,第 903 行,在调用 await ctx.command.invoke(ctx) 文件“C:\Users<..>\AppData\Roaming\Python\Python38\site-packages \discord\ext\commands\core.py”,第 859 行,调用等待注入(*ctx.args,**ctx.kwargs)文件“C:\Users<..>\AppData\Roaming\Python\Python38\ site-packages\discord\ext\commands\core.py",第 94 行,在从 exc discord.ext.commands.errors.CommandInvokeError 包装的 raise CommandInvokeError(exc) 中:命令引发异常:AttributeError:“NoneType”对象没有属性“id”

我怎样才能解决这个问题?

标签: pythondiscord.pydiscord.py-rewrite

解决方案


推荐阅读