类型错误:on_raw_reaction_add() 缺少 1 个必需的位置参数:"有效负载"


import discord
from discord.ext import commands
class GetRole(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name = '역할')
async def GetRoles(self, ctx):
m = await ctx.send(':one: 을 눌러 <@&817598594009661450> 역할을 얻으세요.n:two: 를 눌러 <@&817978024700018719> 역할을 얻으세요.n:three: 를 눌러 <@&817978098531172362> 역할을 얻으세요.')
await m.add_reaction('1️⃣')

@commands.Cog.listener()
async def on_raw_reaction_add(self, ctx, payload: discord.RawReactionActionEvent):
user = self.bot.get_user(payload.id)
if user.bot:
return
if str(payload.reaction.emoji) == "1️⃣":
role = self.bot.get_role(817598594009661450)
await user.add_roles(role)
await user.send('DONE!')

def setup(bot):
bot.add_cog(GetRole(bot))

是的。我试过了,但是出现了错误

TypeError: on_raw_reaction_add()缺少1个必需的位置参数:'payload'

如何修复这个错误?

raw_reaction_add事件没有同时接收Context和raw反动事件对象;只给出了有效负载,因此侦听器中应该只有两个参数,即selfpayload

最新更新