Python exec() 函数 - SyntaxError:解析

时间:2021-04-10 21:25:05

标签: python discord.py

我正在尝试在一个文件中运行多个 discord bot,我认为最简单的方法是遍历它并使用 exec 函数来声明 bot 和它们的事件。

我有问题的代码:

for i in range(23):
    exec("bot" + str(i + 1) + " = commands.Bot(command_prefix=PREFIX, intents=INTENTS)")

for i in range(23):
    exec("@bot" + str(i+1) + ".event")
    async def on_ready():
        loginmsg()

我得到的错误

    exec("@bot" + str(i+1) + ".event")
  File "<string>", line 1
    @bot1.event
               ^
SyntaxError: unexpected EOF while parsing

请尽量保持简单,我是个新手。

0 个答案:

没有答案