-2

I am making a command in discord.py which sends forest link to a particular channel

@client.command(aliases=['forest','forestcode','forest-code'])
async def code(self, ctx):
  await ctx.message.delete()
  embed = discord.Embed(
            title="Forest code",
            description="Please send the link for the forest session"
        )
        sent = await ctx.send(embed=embed)
      
        

  try:
            msg = await self.bot.wait_for(
                "message",
                timeout=60,
                check=lambda message: message.author == ctx.author
                                      and message.channel == ctx.channel
            )

  if msg:
                await sent.delete()
                await msg.delete()
                await ctx.send("The link for forest session by" + msg.author + "is" msg.content)

There is this error popping up

  File "main.py", line 49
    sent = await ctx.send(embed=embed)
    ^
IndentationError: unexpected indent

Could anyone help me out ?

  • 3
    Remove 6 spaces before `sent = ...` – Abhyudaya Sharma Sep 08 '21 at 07:47
  • Does this answer your question? [What to do with "Unexpected indent" in python?](https://stackoverflow.com/questions/1016814/what-to-do-with-unexpected-indent-in-python) – Abhyudaya Sharma Sep 08 '21 at 07:48
  • 1
    The question is not related to discord.py. An indentation error can happen anywhere with python. All you need to do to fix this is remove the 'tab' before the 8th line `sent = await ctx.send(embed=embed)` – CaptAngryEyes Sep 08 '21 at 07:51

2 Answers2

3

There are a lot of issues with the code

  • line 8 is indented too much
  • a try statement without a except/finally
  • excessive unnecessary indents on lines 13-18 and 21-23 (not really a big issue)
  • 2 space indents instead of 4 (not really a big issue)
  • unnecessary empty lines 9,10,12,19 (not really a bit issue)

Add this ot the top of your file

import asyncio

Then the fixed code is

@client.command(aliases=['forest','forestcode','forest-code'])
async def code(self, ctx):
    await ctx.message.delete()
    embed = discord.Embed(
        title="Forest code",
        description="Please send the link for the forest session"
    )
    sent = await ctx.send(embed=embed)
    try:
        msg = await self.bot.wait_for(
            "message",
            timeout=60,
            check=lambda message: message.author == ctx.author and message.channel == ctx.channel
        )
    except asyncio.TimeoutError:
        await ctx.send("You did not send")
    else:
        await sent.delete()
        await msg.delete()
        await ctx.send("The link for forest session by" + msg.author + "is" + msg.content)
Consider learning more about indents and try statements in python :)
Wasi Master
  • 1,112
  • 2
  • 11
  • 22
1

You have a wrong indent in line 49. Re-write your code like this:

@client.command(aliases=['forest','forestcode','forest-code'])
async def code(self, ctx):
    await ctx.message.delete()
    embed = discord.Embed(
            title="Forest code",
            description="Please send the link for the forest session"
        )
    sent = await ctx.send(embed=embed)



    try:
        msg = await self.bot.wait_for(
            "message",
            timeout=60,
            check=lambda message: message.author == ctx.author
                                  and message.channel == ctx.channel
        )

    if msg:
        await sent.delete()
        await msg.delete()
        await ctx.send("The link for forest session by" + msg.author + "is" msg.content)
marsolmos
  • 748
  • 9
  • 24