我正在尝试使用Python编写不和谐机器人,我遇到了这个机器人,并将其拼凑在一起。
import discord
import asyncio
import random
client = discord.Client()
inEmail = input("Email:")
inPassword = input("Passwd:")
async def background_loop():
await client.wait_until_ready()
while not client.is_closed:
channel = client.get_channel("************")
messages = ["Hello!", "How are you doing?", "Testing!!"]
await client.send_message(channel, random.choice(messages))
await asyncio.sleep(120)
client.loop.create_task(background_loop())
client.run(inEmail, inPassword)
然而,当我试图运行它时,我收到了一个SyntaxError
:
File "1.py", line 7
async def background_loop():
^
SyntaxError: invalid syntax
为什么会这样呢?当我测试它时,我从来没有收到过它。
发布于 2019-08-28 05:01:57
我通过安装github更新的PyMC解决了这个问题(他们纠正了Python3.7中发生的错误):
pip install git+https://github.com/pymc-devs/pymc.git
发布于 2021-09-05 12:55:26
如果你使用的是Mac,试着用python3 discord_bot.py
而不是python discord_bot.py
运行这个文件,因为python
默认是2.7版。
https://stackoverflow.com/questions/43948454
复制相似问题