13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DISCORDの千枝ちゃんBOTを24時間起動にしたみた

Posted at

はじめに

前回の記事DISCORDで千枝ちゃんを召喚してみたの続き
BOTを作ったのはいいが、起動するためにはPCでpythonを起動しなければならない。
ただPC24時間つけっぱだと睡眠の妨げになってよろしくないまぁ千枝ちゃんと一緒に寝てると思えば悪くはないが
AWSのEC2たてるなり方法はあるが、お金はかけたくないなぁというのが本音。
第一EC2とか普通すぎて記事にならんしなぁ

Herokuのアカウント取得

色々調べた結果、無料で簡単にできそうな選択肢ということで、Herokuを使ってみることにした。
https://jp.heroku.com/
日本語サイトもあるので、アカウント取得はとくに問題なくいけました。
AWSと違ってクレカ登録もなかったのでそのあたりも抵抗なくアカウント取得できますね。

アプリの登録と実装

CLIの用意

https://devcenter.heroku.com/articles/getting-started-with-python#set-up
ここからインストールすればおっけー。

ファイルの用意

以下のファイルを用意する。
・tiebot.py(DISCORDのbotファイル)
・index.py
・Procfile
・runtime.txt
・requirements.txt

index.pyはなんか適当にpythonファイルを用意する。なんかないとダメらしい(なくてもいける?よくわからない)

index.py
from bottle import route, run

@route("/")
def hello():
        return "hello world"

Procfileで起動コマンドを書く。今回はpythonなのでこんな感じに

Procfile
bot: python tiebot.py

runtime.txtにはpythonのバージョンを記載

runtime.txt
python-3.6.6

requirements.txtはpipのリストを記載。というか下記の通りコマンドを打てば作ってくれる

コンソール
pip freeze > requirements.txt

アプリへコードの登録

コンソール
heroku login
<登録したherokuのIDとpassを入力>
heroku create sasakitiebot(アプリ名) --buildpack heroku/python
git init
heroku git:remote -a sasakitiebot(アプリ名)
git add .
git commit
<適当にコメント>
git push heroku master

ファイルさえ準備できてれば問題なくpushされる...はず。

アプリの実行

登録が成功していれば、herokuをブラウザから確認すると下記の通りリソースが登録されているはず。
真ん中のつまみをONにすれば、pythonが実行されてbotが動いてくれます。
3.jpg

おわりに

私の担当アイドルは橘ありすです(きりっ)
6thライブは猫屋敷も名古屋も両方全通します(きりっ)

13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?