(discord.py) 'async_generator' has no attribute 'flatten'

Jul 7, 2023
Reaction score
I'm trying to make a bot where it will send a message if given a command and react to that message with all the number emojis from 0-10 (0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟). It will then react with another emoji that is a purple button and it's a custom emoji. The message itself will contain 4 random number emojis (ex. 0️⃣3️⃣7️⃣🔟).

When it sends the message, if a user sees it, the user must see the 4-digit code in the message and react to the numbers provided accordingly. Then they'll press the purple button to "submit" the code. If the code is right, they get a success message. If the code is wrong, the bot does nothing.

Everything is working so far (the bot sends the message on command and adds the reactions) except for the success message. I get an error in the output shown in the resources below.

Global variables:

buttonCode is a list of the 4 randomly chosen number emojis.

buttonMsgId is the message ID of the message sent when the command is given

buttonExpected is set to "purple" when the command is given

Code snippet:


async def on_raw_reaction_add(payload):

    global buttonCode

    global buttonMsgId

    global buttonExpected

    channel = client.get_channel(payload.channel_id)

    message = await channel.fetch_message(payload.message_id)

    guild = discord.utils.find(lambda g: g.id == payload.guild_id, client.guilds)

    user = client.fetch_user(payload.user_id)

    member = message.guild.get_member(payload.user_id)

    if user is None:


        user = await client.fetch_user(payload.user_id)

      except discord.NotFound:

        print("User not found")


    if member is None:


        member = await guild.fetch_member(payload.user_id)

      except discord.NotFound:

        print("Member not found")


    if payload.emoji.id == 1123299506633576539 and payload.message_id == buttonMsgId and buttonExpected == "purple":

      print("Purple Button Detected")

      await message.remove_reaction(payload.emoji, member)

      user_reactions = [


            for reaction in message.reactions

            if user in await reaction.users().flatten()


      if set(user_reactions) == set(buttonCode):

            print(f"{user} reacted to {message.id} with the expected emojis.")

      print (f"buttonCode: {set(buttonCode)}")

      print(f"emojis: {user_reactions}")

      if user_reactions == set(buttonCode):

        print("Correct code")

        await channel.send(f"Success! Code Button redeemed by <@{payload.user_id}>")


        print("Incorrect code")

Output (after pressing the button emoji):

Traceback (most recent call last):

File " /home/runner/Bot-Yozy/venv/lib/pytho n3.8/site-packages/discord/client.py", line 441, in _run_event

await coro(*args, **kwargs)

File "main.py", , line 152, in on_raw_reacti on_add

user reactions = [

File "main.py", line 155, in <listcomp> if user in await reaction.users) .flatte

AttributeError: 'async_generator' object has no attribute 'flatten'

I've tried ChatGPT, but its solution faced me with bigger errors, and the solutions to those errors just brought me back to this one, creating a loop. How would I fix this once and for all?

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Latest member

Latest Threads