Discord.py - on_reaction_add() 缺少 1 个必需的位置参数:'user'
Discord.py - on_reaction_add() missing 1 required positional argument: 'user'
在接受用户的输入或抓取用户正在反应的表情符号时出现问题。
我收到 typeError on_reaction_add() missing 1 required positional argument: 'user'
我的代码在 on_reaction_add()
中有 user
,但不确定参数 user
的真正作用是什么?
这是我的机器人代码:
class Changelog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print('Application is loaded')
@commands.group(invoke_without_command=True)
async def application(self, ctx):
embed = discord.Embed(title="Application Commands",
description="Channel: <#channel>", color=0)
await ctx.send(embed=embed)
@application.command()
async def channel(self, ctx, channel: discord.TextChannel):
if ctx.message.author.guild_permissions.administrator:
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(
f'SELECT channel_id FROM application WHERE guild_id = {ctx.guild.id}')
result = cursor.fetchone()
if result is None:
sql = ('INSERT INTO application(guild_id, channel_id) VALUES(?,?)')
val = (ctx.guild.id, channel.id)
await ctx.send(f'Message has been sent and channel has been set to {channel.mention}')
elif result is not None:
sql = ('UPDATE application SET channel_id = ? WHERE guild_id = ?')
val = (channel.id, ctx.guild.id)
await ctx.send(f'Message has been sent and channel has been updated to {channel.mention}')
youtube = ':play_pause:'
staff = ':envelope_with_arrow:'
embed = discord.Embed(title="ReefCraft Applications", color=0)
embed.add_field(
name="** **", value=f"{youtube} YouTube Application\n\n{staff} Staff Application", inline=False)
embed.add_field(name="\n\nInformation",
value="Reacting to one of the emotes will create a new text-channel, where you will write your applicaiton!")
reaction_message = await channel.send(embed=embed)
for emoji in emojis:
await reaction_message.add_reaction(emoji)
cursor.execute(sql, val)
db.commit()
cursor.close()
db.close()
@commands.Cog.listener()
async def on_reaction_add(self, ctx, reaction, user):
emoji = reaction.emoji
if user.bot:
return
if emoji == "\U0001F4E9":
await ctx.send("You clicked the Staff Application")
elif emoji == "\U000023EF":
await ctx.send("You clicked the Youtube Application")
else:
return
def setup(client):
client.add_cog(Changelog(client))
离开 documentation,on_reaction_add
只需要 2 个参数,您提供了 3 个(ctx、reaction 和 user)。这样,每当 Discord 触发此事件时,它只会传入 2 个参数,并且 user
将被遗漏,从而导致您的错误(缺少第三个参数,user
)。
您应该只删除 ctx
作为参数。
but not really sure what the argument user really does?
user
表示添加反应的人的 discord.User
实例。
@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
在接受用户的输入或抓取用户正在反应的表情符号时出现问题。
我收到 typeError on_reaction_add() missing 1 required positional argument: 'user'
我的代码在 on_reaction_add()
中有 user
,但不确定参数 user
的真正作用是什么?
这是我的机器人代码:
class Changelog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print('Application is loaded')
@commands.group(invoke_without_command=True)
async def application(self, ctx):
embed = discord.Embed(title="Application Commands",
description="Channel: <#channel>", color=0)
await ctx.send(embed=embed)
@application.command()
async def channel(self, ctx, channel: discord.TextChannel):
if ctx.message.author.guild_permissions.administrator:
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
cursor.execute(
f'SELECT channel_id FROM application WHERE guild_id = {ctx.guild.id}')
result = cursor.fetchone()
if result is None:
sql = ('INSERT INTO application(guild_id, channel_id) VALUES(?,?)')
val = (ctx.guild.id, channel.id)
await ctx.send(f'Message has been sent and channel has been set to {channel.mention}')
elif result is not None:
sql = ('UPDATE application SET channel_id = ? WHERE guild_id = ?')
val = (channel.id, ctx.guild.id)
await ctx.send(f'Message has been sent and channel has been updated to {channel.mention}')
youtube = ':play_pause:'
staff = ':envelope_with_arrow:'
embed = discord.Embed(title="ReefCraft Applications", color=0)
embed.add_field(
name="** **", value=f"{youtube} YouTube Application\n\n{staff} Staff Application", inline=False)
embed.add_field(name="\n\nInformation",
value="Reacting to one of the emotes will create a new text-channel, where you will write your applicaiton!")
reaction_message = await channel.send(embed=embed)
for emoji in emojis:
await reaction_message.add_reaction(emoji)
cursor.execute(sql, val)
db.commit()
cursor.close()
db.close()
@commands.Cog.listener()
async def on_reaction_add(self, ctx, reaction, user):
emoji = reaction.emoji
if user.bot:
return
if emoji == "\U0001F4E9":
await ctx.send("You clicked the Staff Application")
elif emoji == "\U000023EF":
await ctx.send("You clicked the Youtube Application")
else:
return
def setup(client):
client.add_cog(Changelog(client))
离开 documentation,on_reaction_add
只需要 2 个参数,您提供了 3 个(ctx、reaction 和 user)。这样,每当 Discord 触发此事件时,它只会传入 2 个参数,并且 user
将被遗漏,从而导致您的错误(缺少第三个参数,user
)。
您应该只删除 ctx
作为参数。
but not really sure what the argument user really does?
user
表示添加反应的人的 discord.User
实例。
@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):