I'm trying to write a discord bot and in a reminder command I'm attempting to get the script to write a reminder function to a different module and then import the module and await the function.
However I receive the error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'reminders' has no attribute 'a1'
When I try and run the script - but if I input the function into the module manually and then run the script it has no problem using the imported function.
Code:
async def rmcroutine(ctx, n, t):
n = int(n)
if "seconds" in t or "second" in t:
desttime = str(datetime.now() + timedelta(seconds=n))[0:18]
await ctx.send(f"Reminder for at {n} {t}(s) from now at {desttime}.")
requestname = "a" + str(requestcounter)
writein = open("reminders.py", "a")
requestfnc = f"""
async def {requestname}(ctx):
while True:
currentime = str(datetime.now())[0:18]
desttime = '{desttime}'
if currentime == desttime:
await ctx.send(f'Reminder for **{ctx.message.author.display_name}**, set {n} second(s) ago.')
break
"""
requestfnc = requestfnc.lstrip()
writein.write(requestfnc)
importlib.reload(reminders)
await asyncio.sleep(15)
callfunction = f"""reminders.{requestname}(ctx)"""
await eval(callfunction)