Why does my code have a syntax error?

This is my code

import os
import discord
import requests
import json
import random

client = discord.Client()

sad_words = ["sad", "depressed", "unhappy"]

starter_encouragements = [
 "Cheer up",
 "hang in there",
 "You are a great person / bot!"

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']

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

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

  msg = message.content

  if message.content.startswith('$inspire'):
    quote = get_quote()
    await message.channel.send(quote)

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

my_secret = os.environ['Token']

And this is the error message

File “main.py”, line 39
await message.channel.send(random.choice(starter_encouragements))
IndentationError: expected an indented block

I got into coding 2 days ago so i dont really understand coding so, please be as simple as you can

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This error message is telling you that you need to indent inside this if statement.

Indentation is really important in python because it doesn’t use curly brace syntax like JavaScript.

You need to indent here

because the computer need to know that the await is part of the if statement.

You can also look at the previous if statement here and see there is indentation for the await message

Have you gone through FCC’s beginner python tutorial?

If not, then I would suggest going through it.
Once you go through it, this discord bot tutorial will make more sense.

Thank you my code starts working again

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.