我正在尝试使“反应角色”机器人能够设置反应时给定的角色。我尝试过:
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
但这会导致错误:
回溯(最近通话最近): _run_event中的文件“ C:\ Users \ macio \ AppData \ Roaming \ Python \ Python38 \ site-packages \ discord \ client.py”,行333 等待科罗(* 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 等待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行,已包装 从ex引发CommandInvokeError(exc) discord.ext.commands.errors.CommandInvokeError:命令引发了异常:AttributeError:'NoneType'对象没有属性'id'
我该如何解决?