0

So far I've made the bot answer to the command but now I want the bot to reply once somebody has reacted, this is the code I have tried:

@client.command()
async def war(ctx): 
    embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000)
    msg = await ctx.send(embed=embed)
    await msg.add_reaction(emojigood)
    await msg.add_reaction(emojibad)
    
async def on_reaction_add(reaction, user):
  if reaction.emoji == emojigood:
   embed = discord.Embed(title='War', description='Please now choose a country', color=0x00000)
   await channel.send(embed=embed)
  • No, my question is not about the variables. –  Jun 03 '21 at 08:49
  • I refer to your `if` statement. It seems odd. What is `emojigood`? – Tomerikoo Jun 03 '21 at 08:56
  • I have already made 2 variables emojigood and emojibad, they will show the emoji thumbs up and thumbs down –  Jun 03 '21 at 09:01
  • What are their values? The result of the `in` operator is a boolean: either `True` or `False`. So it doesn't seem to make sense to compare that to `emojigood`. Did you mean `if reaction.emoji == emojigood and 'you sure' in message.content:`? – Tomerikoo Jun 03 '21 at 09:02
  • those were me trying to test something out the if should really be asking, if reaction.emoji==emojigood –  Jun 03 '21 at 09:05
  • Then I don't follow... Please post a [mre]. If you know your `if` is wrong, why did you post it? – Tomerikoo Jun 03 '21 at 09:07
  • The problem is my code, what I'm asking is how to make the bot reply with embed after either the thumbs up or down reaction has been clicked, I'm new to python so I don't understand the code so I don't know what is wrong or right, most fo this code is made from tutorials and very little is me, the if code should work but it isn't so I need to figure a different stratergy and that is what my question is. –  Jun 03 '21 at 09:18
  • Does this answer your question: https://stackoverflow.com/questions/65093402/how-do-i-get-my-bot-to-respond-only-to-reactions-on-a-specific-message-discor – Pewi Jun 03 '21 at 11:29

1 Answers1

0

Here's a piece of sample code to explain the bot.wait_for() method using your example, the official docs also have examples and the valid methods and attributes Here

@client.command()
async def war(ctx): 
    embed = discord.Embed(title='War', description='You are starting a war, do you want to continue?', color=0x00000)
    msg = await ctx.send(embed=embed)
    await msg.add_reaction(emojigood)
    await msg.add_reaction(emojibad)
    def check(r):
        return (r.emoji == emojigood or r.emoji == emojibad) and r.message == msg
    #Checks whether the message is the same, and the emoji is one of the accepted ones, and returns either True or False
    r = await ctx.bot.wait_for('reaction_add', check=check)
    #this is equivalent to a event listener within your command, it will stop there until a reaction that meets the requirements has been found 
    #(This won't block other commands and functions)
    if r.emoji == emojigood:
        embed1 = discord.Embed(title='War', description='Please now choose a country', color=0x00000)
        await ctx.send(embed=embed1)
Alyx
  • 436
  • 4
  • 16
  • I tried it with a print statement but it didn't print anything in the terminal when I reacted –  Jun 03 '21 at 21:28
  • Ah, i just went and checked, if you change "reaction" in the wait_for statement to "reaction_add", i think it should work – Alyx Jun 03 '21 at 21:32
  • @Therandomcoder also it needs to be single quotes, i can never remember which things do or dont – Alyx Jun 03 '21 at 21:38
  • when putting in the command I get this error –  Jun 04 '21 at 05:23
  • Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped –  Jun 04 '21 at 05:23
  • raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: check() takes 1 positional argument but 2 were given –  Jun 04 '21 at 05:23
  • Oh, sorry, i didn't know u was required, just change it to check(r, u) – Alyx Jun 04 '21 at 16:02