我有这个问题,但我仍然找不到解决方案,这是代码
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
await payload.member.add_roles(commands.reaction_role)
@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
guild = self.client.get_guild(payload.guild_id)
member = guild.get_member(payload.user_id)
await member.remove_roles(commands.reaction_role)
@commands.command()
async def set_reaction_message(self, ctx, message_id=None, role_id=None):
for channel in ctx.guild.channels:
try:
commands.reaction_message = await channel.fetch_message(int(message_id))
break
except:
pass问题:文件"c:\Users\MY-NAME\Desktop\Overige en Bot\cogs\reaction.py\Discord Bot\cogs\reaction.py",第17行,在on_raw_reaction_add await payload.member.add_roles(commands.reaction_role) AttributeError中:'RawReactionActionEvent‘对象没有’RawReactionActionEvent‘属性。
有人能帮帮我吗?这件事已经困扰我两天了,我甚至找不到解决办法
发布于 2020-06-25 09:14:40
我知道,根据文档,discord.RawReactionActionEvent有效负载具有对象成员。但是为什么不让自己变得更容易,并像在on_raw_reaction_remove事件中一样获取成员呢?下面的方法应该是可行的。
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
guild = self.client.get_guild(payload.guild_id)
member = guild.get_member(payload.user_id)
await member.add_roles(commands.reaction_role)
@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
guild = self.client.get_guild(payload.guild_id)
member = guild.get_member(payload.user_id)
await member.remove_roles(commands.reaction_role)
@commands.command()
async def set_reaction_message(self, ctx, message_id=None, role_id=None):
for channel in ctx.guild.channels:
try:
commands.reaction_message = await channel.fetch_message(int(message_id))
break
except:
passhttps://stackoverflow.com/questions/62559656
复制相似问题