Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

python - Keep getting syntax error for: async def on_ready():

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
question from:https://stackoverflow.com/questions/66055414/keep-getting-syntax-error-for-async-def-on-ready

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...