Here are some issues with the code you provided:
on_reaction_add
is an event function. This is not recommended for what you're trying to do, and it would be preferable if you used the .command()
instead.
- You need to use
wait_for()
if you're using a command. Your bot isn't going to be listening for a reaction until you tell it to via wait_for()
.
Here is some code that may help fix these problems:
@client.command() # or @bot.command() depending on what you're using
async def rps(ctx): # you mentioned 'AI', so you won't need any arguments
msg = await ctx.send("✂...")
# adding reactions
await msg.add_reaction("")
await msg.add_reaction("")
await msg.add_reaction("✂")
bot_choice = random.randint(1, 3) # picking a random number from 1 to 3
# this is the check and wait_for
def check(reaction, user):
return user == ctx.author and str(reaction) in ["", "", "✂"] and reaction.message == msg
reaction, user = await client.wait_for("reaction_add", check=check) # or bot.wait_for
if str(reaction.emoji) == "":
if bot_choice == 1: # Rock
await ctx.send('I pick Rock, we tie!')
if bot_choice == 2: # Paper
await ctx.send('I pick Paper, I win!')
if bot_choice == 3: # Scissors
await ctx.send('I pick Scissors, I lose')
# Then you do the same thing for the others. Don't forget to add this when including Paper and Scissors!
Here is this exact code working below. I renamed it test
since I already have a rps
command, but you get the point.

Other References: