Ask coding questions

← Back to all posts
SYNTAX ERROR!!!!!!!!!!!
Abesthebot (1)

I have no clue what's the syntax error the tutorial matches my code. Here's the screenshot of the tutorial.

Answered by maxina (61) [earned 5 cycles]
View Answer
Comments
hotnewtop
maxina (61)

Error:
You aren't closing your print statement.
Correct code:
import discord
import os

client = discord.Client()

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

@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')

  client.run(os.getenv('TOKEN'))
RYANTADIPARTHI (6017)

Solution

This is because you aren't closing your quotes. You have a print statement, but you aren't closing it.

import discord
import os

client = discord.Client()

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

  @client.event
  async def on_message(message):
    if message.author == client.user:
      return
    if message.content.startswith('$hello'):
      await message.channel.send('Hello!')

      client.run(os.getenv('TOKEN'))

like that.
That should work

alanchen12 (31)

Basically the issue is that you never closed the quotes. The reason why this is is because the person who made the tutorial had text wrapping since the console was expanded or the screen wasn't that big. you can solve it by putting the end quote on the previous line.

Abesthebot (1)

@alanchen12 THANK YOU SO MUch I’m in my early teens so I didn’t really understand much but would you mind showing an example of putting the end quote on the previous line?

alanchen12 (31)

Instead of

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

use

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

@Abesthebot

19wintersp (1142)

The indent on lines 11-18 are unnecessary: it shouldn't have a tab in front. Also, line 9 should be on the same line as line 8, it just looks like that because the text is wrapping. Here's a fixed version

The reason you are getting this error is because Python is having an issue with the missing quote and closing bracket on line 8.