I'm making a Discord Bot and would like to know if it's possible to get what did an eval print.
I know you can start recording for prints when the eval starts and stop when the eval finishes and this way you'd get what was printed during the eval, but the program uses async and I'm afraid if I do that I could also get stuff printed outside of the eval.
Is there any way to get what was printed just during one eval?
Thank you!
I know using eval is bad, but I'm not asking whether if eval is good or bad.
I can't believe I didn't think of this before.
Set print to a function of yours which both logs the stuff and then passes it to the normal print function and make the eval use it, like this:
try: #Imagine this was in a try
printlog = []
print = yourfunction #yourfunction appends to printlog prints that
#go through it and then prints them normally
eval(stuff)
#printlog now has what was printed
And this way you'll get what was printed only inside that eval no matter anything else is running at the same time.