python - “命令引发异常: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”
我怎样才能解决这个问题?
解决方案
推荐阅读
- spring-mvc - HTTP 状态 500 - 在 Tomcat 9.0.22 中找不到 javax.servlet.ServletException 文件
- javascript - Firebase - 使用第二个帐户登录后,以前的帐户数据仍然可见
- php - 我在 Laravel 中的显示功能有什么问题?
- .htaccess - 如何使用htaccess在斜杠后将所有子域重定向到另一个带有参数的子域?
- android-studio - 将 Depth API 与场景形式一起使用
- vue.js - 如何从 axios 发布响应中获取自定义标头?
- python - 每次运行类时附加新的日期时间记录
- ruby-on-rails - 耙子中止;运行 bundle exec rake db:migrate 时出现 SystemStackError、NoMethodError
- f# - F# Singleton 和处理内部资源
- c# - UNITY C# - 如何获取标有自定义属性的类实例的所有字段(字段)?