I have an async function that is supposed to add reactions to a list until a certain reaction is pressed then it will add all appropriate roles. to do this I have a global variable "reactions = []" that gets reset when the "ok" reaction is pressed. VS Code is telling me this on the line "for react in reactions:" : "reactions is used before it is defined. Move the definition before." this is confusing because roleEmojis is another global variable but that works fine.
here is my code:
import os
import discord
import time
from discord.utils import get
from discord.ext import commands
token = "TOKEN"
BOT = commands.Bot("£")
reactions_list = []
@BOT.event
async def on_reaction_add(reaction , user):
if reaction.emoji in roleEmojis.keys() and user != BOT.user:
if reaction == get(reaction.message.guild.emojis, name = "OK"):
for react in reactions_list:
await user.add_roles(roleEmojis[react.emoji])
reactions_list = []
else:
reactions_list.append(reaction)
BOT.run(token)
Side note: I haven't yet figured out how to detect when someone has "un-reacted" to a message, id appreciate any help there