-1

I'm currently writing some code in Python and whenever I try to run the program I get this error.

Here is the code;

 if month == time.strftime("%m") and day == time.strftime("%d"):
            continue
        elif hour == time.strftime("%H") and minute != time.strftime("%M"):
            channelD["just_sent"] = False
            with open("data.json", "w") as write_file:
                json.dump(data, write_file)
        elif hour == time.strftime("%H") and minute == time.strftime("%M"):
        if just_sent = channelD["just_sent"]:
            continue
            else:
                channel = bot.get_channel(i)
                await bot.send_message(channel, content=channelD["message"])
                print("24h message sent!")
James Smith
  • 3
  • 1
  • 2

2 Answers2

3

Maybe you just need to indent it properly like this:

if month == time.strftime("%m") and day == time.strftime("%d"):
    continue
elif hour == time.strftime("%H") and minute != time.strftime("%M"):
    channelD["just_sent"] = False
    with open("data.json", "w") as write_file:
        json.dump(data, write_file)
elif hour == time.strftime("%H") and minute == time.strftime("%M"):
    if just_sent == channelD["just_sent"]:  # notice == instead of =
        continue
    else:
        channel = bot.get_channel(i)
        await bot.send_message(channel, content=channelD["message"])
        print("24h message sent!")

There is no way for me to find out whether the last else: should be on the indentation level of the if above it or of the indentation level of the elif above it. That depends on the semantics of the code. You should check that.

Python interprets the indentation levels to figure out where blocks start and end. In this it is unlike many other languages.

Alfe
  • 56,346
  • 20
  • 107
  • 159
2

Give this a go

if month == time.strftime("%m") and day == time.strftime("%d"):
    continue
elif hour == time.strftime("%H") and minute != time.strftime("%M"):
    channelD["just_sent"] = False
    with open("data.json", "w") as write_file:
        json.dump(data, write_file)
elif hour == time.strftime("%H") and minute == time.strftime("%M"):
    if just_sent = channelD["just_sent"]:
        continue
    else:
        channel = bot.get_channel(i)
        await bot.send_message(channel, content=channelD["message"])
        print("24h message sent!")
JimmyA
  • 676
  • 5
  • 13