So right now I am trying to make a command where it retrieves data on a specific blacklisted user. My current solution is to loop through all the fields until it gets a match and then brings back all of the data regarding the user. The only problem is that my for loop doesn't define q
properly causing the last try statement to fail. I suspect the problem is either with my for loop or my try statement. Is there another solution to this?
@commands.command()
async def DBget(self, ctx, *, string: str):
database.db.connect(reuse_if_open=True)
databaseData = [database.MRP_Blacklist_Data.DiscUsername, database.MRP_Blacklist_Data.DiscID, database.MRP_Blacklist_Data.Gamertag, database.MRP_Blacklist_Data.BannedFrom, database.MRP_Blacklist_Data.KnownAlts, database.MRP_Blacklist_Data.ReasonforBan, database.MRP_Blacklist_Data.DateofIncident, database.MRP_Blacklist_Data.TypeofBan, database.MRP_Blacklist_Data.DatetheBanEnds]
for data in databaseData:
try:
q: database.MRP_Blacklist_Data = database.MRP_Blacklist_Data.select().where(data == string).get()
except:
continue
else:
break
try:
await ctx.send(f"{q.DiscUsername}
{q.DiscID}
{q.Gamertag}
{q.BannedFrom}
{q.BanReason}
{q.IncidentDate}
{q.BanType}
{q.ExpireBan}")
except Exception as e:
await ctx.send(f"ERROR!
{e}")
Traceback:
local variable 'q' referenced before assignment
Any help would be appreciated!
question from:
https://stackoverflow.com/questions/65852426/searching-and-bringing-back-data-from-a-db 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…