Umm.... What does this mean

I did everything right on a a video or a website but I keep on getting this:

python3 main.py
  File "/home/runner/Kairi/main.py", line 68
    encouragements = []
    ^
IndentationError: expected an indented block after 'if' statement on line 67
exit status 1

What am I doing wrong?

Repl link/Link to where the bug appears:

Screenshots, links, or other helpful context:

code snippet

Hey there! Can you please send your Repl link so we can take a closer look?

Follow this guide to find your Repl link:

Sorry if I am not doing it right

import discord
import os
import requests
import json
import random
from replit import db

client = discord.Client()
sad_words = ["sad", "depressed", "unhappy", "angry", "miserable"]
starter_encouragements = [
  "Cheer up!",
  "Hang in there.",
  "You are a great person / bot!"
]

if "responding" not in db.keys():
  db["responding"] = True

def get_quote():
  response = requests.get("https://zenquotes.io/api/random")
  json_data = json.loads(response.text)
  quote = json_data[0]["q"] + " -" + json_data[0]["a"]
  return(quote)

def update_encouragements(encouraging_message):
  if "encouragements" in db.keys():
    encouragements = db["encouragements"]
    encouragements.append(encouraging_message)
    db["encouragements"] = encouragements
  else:
    db["encouragements"] = [encouraging_message]

def delete_encouragment(index):
  encouragements = db["encouragements"]
  if len(encouragements) > index:
    del encouragements[index]
  db["encouragements"] = encouragements

@client.event
async def on_ready():
  print("We have logged in as {0.user}".format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return

msg = message.content

if msg.startswith("$inspire"):
    quote = get_quote()
    await message.channel.send(quote)

if db["responding"]:
    options = starter_encouragements
    if "encouragements" in db.keys():
      options = options + db["encouragements"]

    if any(word in msg for word in sad_words):
      await message.channel.send(random.choice(options))

if msg.startswith("$new"):
    encouraging_message = msg.split("$new ",1)[1]
    update_encouragements(encouraging_message)
    await message.channel.send("New encouraging message added.")

    if msg.startswith("$del"):
    encouragements = []
    if "encouragements" in db.keys():
      index = int(msg.split("$del",1)[1])
      delete_encouragment(index)
      encouragements = db["encouragements"]
    await message.channel.send(encouragements)

  if msg.startswith("$list"):
    encouragements = []
    if "encouragements" in db.keys():
      encouragements = db["encouragements"]
    await message.channel.send(encouragements)
    
  if msg.startswith("$responding"):
    value = msg.split("$responding ",1)[1]

    if value.lower() == "true":
      db["responding"] = True
      await message.channel.send("Responding is on.")
    else:
      db["responding"] = False
      await message.channel.send("Responding is on.")

client.run(os.getenv("TOKEN"))

Can you send the link to it? (It’s that first section of the guide.)

Sorry if I am doing it wrong:

https://replit.com/@keyblademasterl/Kairi?v=1

Thanks for the help guys. Its my first time coding stuff

1 Like

No, that’s good.

It looks like your if statements have wonky indentation.

I think you can highlight lines 63 through 67 of your code and hold the Shift key and press Tab. This should decrease the indentation by one, and fix the error.

It depends on what exactly you’re trying to do though. This would fix the error, but might not result in your exact wanted functionality.

Did that now its saying this:

python3 main.py
  File "/home/runner/Kairi/main.py", line 68
    encouragements = []
                       ^
IndentationError: unindent does not match any outer indentation level
exit status 1
 

Im sorry if Im a waste of time

Oh, I think you pressed only Tab (which indents it forward). Select the same text, hold down the Shift key, and while holding it still, press the Tab key twice.

No, you’re not. Everyone is here to help other people

Ok. Let me try it. Now its saying Line 62 is wrong

python3 main.py
  File "/home/runner/Kairi/main.py", line 63
    encouraging_message = msg.split("$new ",1)[1]
    ^
IndentationError: expected an indented block after 'if' statement on line 62

It means that the code below that needs another indentation. Highlight 63, 64, and 65 and hit Tab.

If you want that if statement nested inside the db["responding"] one, then highlight 62 through 65 and hit Tab again.

Its says this now

python3 main.py
  File "/home/runner/Kairi/main.py", line 62
    if msg.startswith("$new"):
                              ^
IndentationError: unindent does not match any outer indentation level
exit status 1

Select lines 55 through 60, and do Shift and Tab again.

I had to do the steps again but I just did first one you had me do and then I clicked run and now it says this:

python3 main.py
  File "/home/runner/Kairi/main.py", line 81
    if msg.startswith("$responding"):
                                     ^
IndentationError: unindent does not match any outer indentation level

I am sorry if I am wasting you time. I do appreciate the help

Select lines 76 through 79, and do a Shift + Tab again.

Almost. Now it says this:

python3 main.py
File “/home/runner/Kairi/main.py”, line 52
await message.channel.send(quote)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: ‘await’ outside function

What do I do next? I feel like its almost there

1 Like

it says this:

IndentationError: expected an indented block after 'if' statement on line 50

If just trying to tell you what its telling me