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))
是的。我试过了,但出现错误
类型错误:on_raw_reaction_add() 缺少 1 个必需的位置参数:'payload'
我如何解决这个错误?
答案 0 :(得分:0)
raw_reaction_add
事件不会同时接收 Context 和 RawReactionActionEvent 对象;仅给出有效负载,因此您的侦听器中应该只有两个参数,即 sequenceHeadline
和 sequenceContent
。