I'm making a discord bot that checks whether a certain key is in my database or not. All of the keys are listed in the first column of my CSV file. The value row[2] cointains a boolean parameter that tells the user whether the key is already activated or not. My problem is that the second for loop is being completely ignored. Instead of running the for loop, it directly tries to run await client.send_message(message.author, status) that obviously throws the following exception
Local variable 'status' referenced before assignment
@client.event
async def on_message(message):
elif message.content.startswith("!activate"):
with open('database.csv', 'rt') as csvfile:
content = csv.reader(csvfile, delimiter=',')
key_list = []
for row in content:
key_list.append(row[0])
key = message.content.split(" ")[1]
try:
if key in key_list:
for row in content:
print(row[0])
if row[0] == key:
print(row[2])
status = row[2]
await client.send_message(message.author, status)
else:
await client.send_message(message.author, "Your key was not found in our database. Make sure you use the proper format: ```!activate KEY```")
except Exception as E:
print(E)
await client.send_message(message.author, "Your key was not found in our database. Make sure you use the proper format: ```!activate KEY```")
Thanks in advance everyone.
elif, which is an error. Please fix the function.