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 (![Keycap: 0 :zero: 0️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0030-20e3.png)
![Keycap: 1 :one: 1️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0031-20e3.png)
![Keycap: 2 :two: 2️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0032-20e3.png)
![Keycap: 3 :three: 3️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0033-20e3.png)
![Keycap: 4 :four: 4️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0034-20e3.png)
![Keycap: 5 :five: 5️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0035-20e3.png)
![Keycap: 6 :six: 6️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0036-20e3.png)
![Keycap: 7 :seven: 7️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0037-20e3.png)
![Keycap: 8 :eight: 8️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0038-20e3.png)
![Keycap: 9 :nine: 9️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0039-20e3.png)
). 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. ![Keycap: 0 :zero: 0️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0030-20e3.png)
![Keycap: 3 :three: 3️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0033-20e3.png)
![Keycap: 7 :seven: 7️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0037-20e3.png)
).
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:
Output (after pressing the button emoji):
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?
![Keycap: 0 :zero: 0️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0030-20e3.png)
![Keycap: 1 :one: 1️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0031-20e3.png)
![Keycap: 2 :two: 2️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0032-20e3.png)
![Keycap: 3 :three: 3️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0033-20e3.png)
![Keycap: 4 :four: 4️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0034-20e3.png)
![Keycap: 5 :five: 5️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0035-20e3.png)
![Keycap: 6 :six: 6️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0036-20e3.png)
![Keycap: 7 :seven: 7️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0037-20e3.png)
![Keycap: 8 :eight: 8️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0038-20e3.png)
![Keycap: 9 :nine: 9️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0039-20e3.png)
![Keycap: 10 :keycap_ten: 🔟](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/1f51f.png)
![Keycap: 0 :zero: 0️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0030-20e3.png)
![Keycap: 3 :three: 3️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0033-20e3.png)
![Keycap: 7 :seven: 7️⃣](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/0037-20e3.png)
![Keycap: 10 :keycap_ten: 🔟](https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/1f51f.png)
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:
Code:
@client.event
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:
try:
user = await client.fetch_user(payload.user_id)
except discord.NotFound:
print("User not found")
return
if member is None:
try:
member = await guild.fetch_member(payload.user_id)
except discord.NotFound:
print("Member not found")
return
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 = [
reaction.emoji
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}>")
else:
print("Incorrect code")
Output (after pressing the button emoji):
Code:
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?