11
私はPythonを使ってdiscordのボットを書きたいと思っています。私はそれを実行しようとしたときPython [非合法の構文] with async def
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
なぜですか?私はそれを前に受けたことがありませんでした。
関数定義の前に 'async'を使用するのは、Python 3.4以降でのみ有効なシンタックです。 –
はい私は "python3 1.py"を使ってスクリプトを実行しています – Andy
だから、Python 3.4以上のものは動作するはずですか?私のサーバーが何とか夜間にPythonのバージョンを変更したので、それは本当に奇妙です:P – Andy