【发布时间】:2021-05-09 07:56:59
【问题描述】:
我正在尝试使用此代码制作一个不和谐的机器人,在 Visual Code Studio 中一切正常,但我在终端中收到此错误。我知道I get a syntax error when I import discord in the cmd but not in vs code,但它并没有解决问题,我也提前道歉,我是一个python初学者,几乎不知道如何运行代码:
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)
当我尝试运行代码时,我不断收到此语法错误:
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
【问题讨论】:
-
这能回答你的问题吗? Python [Invalid syntax] with async def
-
@RandomDavis 不,我已经看过那个帖子了。
-
那么你在哪个版本的 Python 上运行它?
-
@RandomDavis 3.9.1
-
其实2.7.16
标签: python discord.py