0

I am trying to make a discord bot with this code, everything is ok in Visual Code Studio but I get this error in terminal. I know about I get a syntax error when I import discord in the cmd but not in vs code but it doesn't solve the problem, I also apologise in advance, im a python beginner and barely knew how to even run the code:

from discord.ext import commands
from utils.logger import Logger

logger = Logger().logger
glados_cores = ["cogs.angry_core"]
bot = commands.Bot(command_prefix="!")
bot.logger = logger


@bot.event
async def on_ready():
    logger.info("---------------bot-ready---------------")
    logger.info("Hello and, again, welcome to the Aperture Science computer-aided enrichment center.")


if __name__ == "__main__":
    for extension in glados_cores:
        try:
            bot.load_extension(extension)
        except Exception as e:
            exc = f"{type(e).__name__}: {e}"
            logger.info(f"{exc} Failed to load extension {extension}")

bot.run(TOKEN)

I keep getting this syntax error when I try to run the code:

Aleksandars-16-MacBook-Pro:Genetic-Lifeform-and-Disk-Operating-System-master aleksandarvasilic$ python main.py
  File "main.py", line 11
    async def on_ready():
        ^
SyntaxError: invalid syntax

1 Answers1

2

This happens if you do not have python 3.5+. If you get a syntax error in cmd it's likely because you have python <3.5 installed on your path.

Shidouuu
  • 169
  • 2
  • 11
  • I have python 3.9.1 – Aleksandar Vasilic Feb 05 '21 at 00:51
  • But are you sure thats what you're using to run the bot? – ChrisDewa Feb 05 '21 at 01:02
  • Wait. You are right. I just checked and I have python version 2.7.16 and don't have pip installed. I think I may have multiple python version installed. A while ago I had a problem with python and pip, so I uninstalled python and pip manually by deleting their folders. My system is probably very confused by everything, how do I fix this? – Aleksandar Vasilic Feb 05 '21 at 01:08
  • I have 2.7.16 not 3.9.1 – Aleksandar Vasilic Feb 05 '21 at 02:09
  • @AleksandarVasilic you could just use `python3` instead of `python` to run scripts. Or alias the command, like described [here](https://stackoverflow.com/questions/18425379/how-to-set-pythons-default-version-to-3-x-on-os-x). – Random Davis Feb 05 '21 at 16:08
  • Easy way to change it is to just reinstall python 3 and make it install on your path – Shidouuu Feb 05 '21 at 18:13