2

(Using Python 3.6)

Hello !

I'm actually making a Python Discord bot (for a school project) and i'm facing a little problem at this part of the code:

    async def on_message(self, message):
    if not message.author.bot:
        ctx = await bot.get_context(message)
        await self.invoke(ctx)

Here is the error message:

File "/Users/dorian/Desktop/ISN/ISNbotv2/bot.py", line 47
async def on_message(self, message):
        ^
SyntaxError: invalid syntax
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/dorian/Desktop/ISN/ISNbotv2/bot.py"]
[dir: /Users/dorian/Desktop/ISN/ISNbotv2]
[path:
/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

Weirdly when I launch the script with my PC the bot is working, unfortunatly I only have this error only on the MAC I HAVE to use for my school project.

Thanks for your help (and sorry if I made english mistakes, not my main langage)

Adam Smith
  • 52,157
  • 12
  • 73
  • 112
Misubata
  • 41
  • 2
  • 6
  • 1
    Can you do `import sys; print(sys.version)` just to confirm? –  May 30 '18 at 15:42
  • @Tobias I got: 2.7.10 (default, Feb 7 2017, 00:08:15) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] [Finished in 0.1s] – Misubata May 30 '18 at 15:46
  • 2
    Well there you go -- you're on Python 2.7.10, not 3.6. – Adam Smith May 30 '18 at 15:47
  • oh you're right but I also have the IDLE Python 3.6.5 on my computer but apparently Sublime Texte is using Python 2.7.10, is there a way to use 3.6 with ST3 ? – Misubata May 30 '18 at 15:50
  • @MisubataNightcore yes, which is answered in [another question](https://stackoverflow.com/questions/23257984/python-3-4-on-sublime-text-3) – Adam Smith May 30 '18 at 15:51

1 Answers1

1

To double check your version via script. import sys; print(sys.version)

People usually install python 3.7 on top of existing python 2.x that is with the system. When running a command sometimes you will forget to run it as python3.7 instead of just simply python which would run python2.

Therefore it causes the error "Async def invalid syntax"

Run python3.7

CodeGuru
  • 3,645
  • 14
  • 55
  • 99