#dont understand this error

1 messages · Page 1 of 1 (latest)

craggy saddle
#

I got this error while using python can someone tell me how to fix

safe star
#

Can you share the errors?

craggy saddle
#

The left is the code

#

idk wdym by error

limber scroll
#

That error is when you have an indent that is inconsistent with the rest of the code block. I would look at the lines of code in that area and line them up properly.

#

You really don’t give us much to go off, but I see you might be missing a colon in the previous line?

limber scroll
#

Drop the colon

craggy saddle
limber scroll
# craggy saddle This happened

SyntaxError: ‘await’ outside async function
Your setup function needs to be an async function: async def setup(client):

limber scroll
craggy saddle
#

start is the same as the other

#

Ok

#

Lemme try

craggy saddle
craggy saddle
limber scroll
#
    client.add_cog(music(client))
    await ctx.voice_client.connect()```
craggy saddle
limber scroll
#

well one function call has the ctx as an argument in it and the other one doesn't so you have to make them match

limber scroll
#

yes see they dont match

craggy saddle
#

as a ct

limber scroll
#

you need to pass ctx to match the function definition

#

so cogs[i].setup(client, ctx)

#

where ctx is the context

craggy saddle
limber scroll
#

yes

craggy saddle
limber scroll
#

so you have to define it

#

it is an instance of discord.ext.commands.Context

craggy saddle
limber scroll
#

So you just want to initialize not connect to the voice channel?

#

Okay

#
    client.add_cog(music(client))
    ```

And then you don’t need a for loop, just call setup(client)
#

Then I don’t know why you had an await there 🤷

craggy saddle
#

def setup(client):
client.add_cog(music(client))

craggy saddle
craggy saddle
limber scroll
craggy saddle
#

tried to await it like you did but it said it’s out of place tried to space it and delete spaces still

limber scroll
#

await setup(client)

craggy saddle
craggy saddle
#

it always indents even though I matched it and put parths

craggy saddle
#

pls help

barren depot
#

what IDE do you use?

#

@craggy saddle

craggy saddle
#

but not sure what IDE

barren depot
#

hm alright, don't know that one hehe

  1. in your Image you have 2 code lines in one line....
    it should be:
for i in range( len(cogs) ):
  await client.setup( cogs[i] )

Not sure if this is right to setup the cogs, but the syntax is right this way.

#

most IDEs have an option to format the code, using it may prevent the ident exceptions.
( Shown with an example in the screenshots )

craggy saddle
#

Undefined name “cog” is the error

barren depot
#

i have no clue what the hell you're doing here.

#
#

when you learned the syntax and how to use the language you should try to learn the discord docs

craggy saddle
#

i making it for my friends and me

#

followed a tut

#

it had alot of errors