Discord.py: with open("prefixs.json", "w") ^ IndentationError: unexpected indent

Created on 15 Jun 2020  路  8Comments  路  Source: Rapptz/discord.py

Hi there,

When attempting to run my bot I get this: with open("prefixs.json", "w")
^
IndentationError: unexpected indent

I have checked the code 3 times:

here is the code:
@client.event
async def on_guild_join(guild):
with open("prefixes.json", "r") as f:
prefixes = json.load(f)

    prefixes[str(guild.id)] = "n."


     with open("prefixs.json", "w")
      json.dump(prefixes, f, indent=4)

@client.event
async def on_guild_remove(guild):
with open("prefixes.json", "r") as f:
prefixes =json.load(f)

prefixes.pop(str(guild.id))

with open("prefixes.json", "w") as f:
    json.dump(prefixes, f, indent=4)

@client.command()
aysnc def changeprefix(ctx, prefix)
with open("prefixes.json", "r") as f:
prefixes =json.load(f)

prefixes[str(ctx.guild.id)] = prefix

with open("prefixes.json", "w") as f:
    json.dump(prefixes, f, indent=4)

Thanks

discord py ver: 1.3.3

off-topic

Most helpful comment

The best way to move forward and learn coding is to know how to google.
Ill take the time to show you.
"What is the IndentationError in python"

As mentioned in the "expected an indented block" section, Python not only insists on indentation, it insists on consistent indentation. You are free to choose the number of spaces of indentation to use, but you then need to stick with it.

As the first link.
From that you can come to the conclusion that its a missing tab or space in your code.

All 8 comments

please larn basic python link.

well whats wrong with it

This, is not a discord issue.

Please learn about python before attempting to code a discord bot, there are youtube guides.

First off, I know this is not a discord issue

Second off, I know how to use python!

It鈥檚 just one issue and you guys are clearly NOT looking into the code

Sorry, this is not a valid issue for discord.py. This issue tracker is for problems with the Discord.py library, not with errors in using it, or basic Python errors such as this one.

The error you are seeing is an IndentationError. A quick Google would have gotten you the solution for this.

All right thanks but searching on google didnt help so I decided to remove the code entirely and just left it there.

The best way to move forward and learn coding is to know how to google.
Ill take the time to show you.
"What is the IndentationError in python"

As mentioned in the "expected an indented block" section, Python not only insists on indentation, it insists on consistent indentation. You are free to choose the number of spaces of indentation to use, but you then need to stick with it.

As the first link.
From that you can come to the conclusion that its a missing tab or space in your code.

Was this page helpful?
0 / 5 - 0 ratings