Search code examples
pythonfor-loopbeautifulsoupindentationdiscord.py

IndentationError: expected an indented block discord.py


Hello I'm completely new to coding & working on a discord bot with python3 that utilizes bs4 & requests to show me all of the listings on a certain car I'm looking for. Not sure if I'm writing the code right or if the indentation is actually the cause of this problem any advice would be greatly appreciated!

import discord
from discord.ext import commands
import requests
import bs4
import lxml

req = requests.get('https://dallas.craigslist.org/search/cto?query=300zx')
soup = bs4.BeautifulSoup(req.text, 'lxml')

client = commands.Bot(command_prefix = '!')

@client.event
async def on_ready():
    print('Bot is ready.')

@client.command()
async def search(ctx):
    listings = soup.findAll('li', class_='result-row')
    listing1 = listings[0]
    def listing():
    global listing1
    for listing1 in listings:
        title = listing1.p.a.text
        link = listing1.p.a['href']
        price = listing1.span.text
    await ctx.send(f'Title: {title}\nLink: {link}\nPrice: {price}')

client.run('token')

  File "bot.py", line 21
    global listing1
         ^
IndentationError: expected an indented block

Solution

  • def listing():
        global listing
        ...
    

    You forgot an indentation here