Reputation: 395
Having an issue when taking the user's input, or when grabbing the emoji the user is reacting to.
I am getting typeError on_reaction_add() missing 1 required positional argument: 'user'
My code has user
in the on_reaction_add()
, but not really sure what the argument user
really does?
Here is my code for the bot:
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))
Upvotes: 0
Views: 604
Reputation: 5640
Going off of the documentation, on_reaction_add
only takes 2 arguments, you provided 3 (ctx, reaction, and user). That way, whenever Discord triggers this event, it will only pass in 2 arguments, and the user
will be left out, causing your error (missing the 3rd argument, user
).
You should just remove ctx
as a parameter.
but not really sure what the argument user really does?
user
represents the discord.User
instance of the person that added the reaction.
@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
Upvotes: 1