前提・実現したいこと
pythonでdiscordのbotを作りました。定型文に反応して定型文を返すだけのbotです。そして、そのbotをherokuでwebアプリとして動かそうとしたのですが動きませんでした。herokuのログを見てみると構文のエラーが原因らしいです。ですが、Visual Studioでデバックするとbotはちゃんと動きます。プログラム単体では動くのにherokuで動かすと構文のエラーになる原因がわかりません、教えてください。
発生している問題・エラーメッセージ
herokuのログです。7行目や16行目を見て判断しました
2018-08-07T06:36:02.355203+00:00 heroku[worker.1]: Starting process with command python discordbot.py
2018-08-07T06:36:03.127561+00:00 heroku[worker.1]: State changed from starting to up
2018-08-07T06:36:04.334696+00:00 heroku[worker.1]: Process exited with status 1
2018-08-07T06:36:04.284177+00:00 app[worker.1]: File "discordbot.py", line 7
2018-08-07T06:36:04.284200+00:00 app[worker.1]: async def on_ready():
2018-08-07T06:36:04.284202+00:00 app[worker.1]: ^
2018-08-07T06:36:04.284204+00:00 app[worker.1]: SyntaxError: invalid syntax
2018-08-07T06:36:04.566531+00:00 heroku[worker.1]: State changed from up to crashed
2018-08-07T06:36:04.568287+00:00 heroku[worker.1]: State changed from crashed to starting
2018-08-07T06:36:05.911411+00:00 heroku[worker.1]: Starting process with command python discordbot.py
2018-08-07T06:36:06.708335+00:00 heroku[worker.1]: State changed from starting to up
2018-08-07T06:36:07.885783+00:00 heroku[worker.1]: Process exited with status 1
2018-08-07T06:36:07.810291+00:00 app[worker.1]: File "discordbot.py", line 7
2018-08-07T06:36:07.810337+00:00 app[worker.1]: async def on_ready():
2018-08-07T06:36:07.810339+00:00 app[worker.1]: ^
2018-08-07T06:36:07.810341+00:00 app[worker.1]: SyntaxError: invalid syntax
2018-08-07T06:36:08.139429+00:00 heroku[worker.1]: State changed from up to crashed
該当のソースコード
import discord # インストールした discord.py
client = discord.Client() # 接続に使用するオブジェクト
@client.event# 起動時に通知してくれる処理
async def on_ready():
print('ログインしました')
@client.event
async def on_message(message):
if message.content.startswith('おはよう'):
reply = 'おはようございます!'
await client.send_message(message.channel, reply)
client.run('トークン')
補足情報(FW/ツールのバージョンなど)
コードは
https://qiita.com/1ntegrale9/items/9d570ef8175cf178468f
に乗っているものを使わせていただきました
python3.6.6(herokuでもruntime.txtの設定で同じです)
ライブラリ
discord.py
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。