I know that I shouldn't use exec because it's insecure but the code it run comes from the same file and is a string. How can I use exec to run an async function? It always returns me SyntaxError: 'await' outside function if I try it.
Edit: This is the Code where I am using exec:
async def command_processor(guild):
while True:
commands = {"[1] - Bot Permissions abrufen" : "print_permissions(guild)",
"Derzeit nicht verwendbar - [2] - Invite zu Gilde erstellen (max Nutzungen pro Invite: 1)" : "await print_invite(guild)",
"[3] - Gebannte Benutzer auflisten (benötigt Berechtigung {Mitglieder bannen}" : "print_banned(guild)",
"[4] - Ausgewählten Server wechseln" : "change_guild()",
"[5] - Ausgewählten Bot wechseln" : "change_bot()",
"[6] - Beenden" : "sys.exit()"
}
print("\n\n--------------- Befehle ---------------\n")
for i in range(len(commands.keys())):
print(list(commands.keys())[i])
sel = input()
print()
try:
int(sel)
except:
print("Bitte hier nur die Zahl eingeben")
if int(sel) in range(len(commands.keys())):
exec(list(commands.values())[int(sel)-1])
{'1. Exit': sys.exit}. Then you can dolist(commands.values())[int(sel)-1])()later on.