I'm making a discord.py bot, and I'm trying to implement a command that will tell you how much time there is until the period ends. The code works by itself, but if I try to implement it into the bot I get this error:
NameError: name 'timee' is not defined
(The variable is called 'timee' since I also use the time.sleep() function later)
This is the code it has a problem with:
def setTime():
global timee
print(timee)
if timee > 59 and timee < 100:
timee -= 100
timee += 60
elif timee > 159 and timee < 200:
timee -= 100
timee += 60
elif timee > 259 and timee < 300:
timee -= 100
timee += 60
I have the print(timee)
there to test if it thinks it's defined or not, which it doesn't.
This is my code that calls the setTime
function (and should also set timee)
if currentTime < start:
timee = start - currentTime
print(timee)
setTime()
doThing()
await client.send_message(message.channel, content = "School hasn't started yet! It starts in %s:%s" % (hours, minutes))
print("%s got the time left." % message.author)
Edit: The 'timee' variable is declared outside of the if statement and the function as well.
Edit 2: I tried what someone commented, (The comment is deleted now) which is doing def setTime(timee):
instead of
def setTime():
global timee
And that works. I don't know if this is inefficient or what, but it works. ALSO, this exact same code works if It's not in the discord bot.