我在响应代码上具有此自动分配角色,并且on_reaction_add正常工作,但是on_reaction_add_remove给我一个错误原因吗?
代码
@ bot.event 异步def on_raw_reaction_add(有效载荷):
msgID = 754487460142121070
user = payload.user_id
member = payload.member
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, bot1.guilds)
role = get(member.guild.roles, name="penis")
if payload is not None:
if payload.message_id == msgID:
if str(payload.emoji) == "<:bbc:639345897922101248>":
await member.add_roles(role)
@ bot.event 异步def on_raw_reaction_remove(有效载荷):
msgID = 754487460142121070
user = payload.user_id
member = payload.member
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, member.guilds)
role = get(member.guild.roles, name="penis")
if payload is not None:
if payload.message_id == msgID:
if str(payload.emoji) == "<:bbc:639345897922101248>":
await member.add_removes(role)
错误raw_reaction_remove
Ignoring exception in on_raw_reaction_remove Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py",
第312行,在_run_event中 等待科罗(* args,** kwargs) 文件“ /Users/CIP/Documents/GitHub/billionaireboysclub/lojinha.py”,行 150,在on_raw_reaction_remove中 公会= discord.utils.find(lambda g:g.id == guild_id,member.guilds) AttributeError:“ NoneType”对象没有属性“行会”
答案 0 :(得分:1)
您没有从payload获得成员对象,因此您在'NoneType' object has no attribute 'guilds'
上获得了member.guilds
但是,代替这个:
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, member.guilds)
我建议:
guild = bot.get_guild(payload.guild_id)
这可能无法解决您的会员问题,但比尝试将公会对象从会员公会中拉出要干净。
您还有一个错字:await member.add_removes(role)
,您的意思可能是remove_roles
编辑:
您可能想通过添加以下内容来过滤掉任何非公会的反应:
if not payload.guild_id:
return
位于on_raw_reaction_add
和on_raw_reaction_remove
的最上方