はじまり

よーし!ボットも出来たことだしデプロイするかあー!

うむ。今回は、Herokuを使ってデプロイしてみますか。

👍
手順(準備)
Herokuでデプロイする際に必要なファイルを、デプロイ元のリポジトリに準備します。
Procfile
Dynosサーバが起動した際に走らせるコマンドを書くようです。こんな感じで。
「discordbot」の部分はラベルなので、一応何でも良いそうです。
discordbot: python3 app.py
runtime.txt
使用するPythonのバージョンを書きます。
python-3.8.10
requirements.txt
requirements.txtも書いておきます。
###### Requirements with Version Specifiers ######
### for app ###
py-cord[voice]==2.0.0b1
# janome>=0.4.1
gspread>=5.1.1
oauth2client>=4.1.3
asyncio>=3.4.3
git+https://github.com/landmaster135/landmasterlibrary.git
手順(Heroku画面での操作)
まず、Herokuにログインして(アカウントがなかったらアカウント作成して)ダッシュボード的な場所に遷移します。
そこで、「Create new app」します。

App nameを埋めます。regionはUnited Statesで良さそうです。

次に、「Deployment method」でGitHubを選択します。すると、認証画面が開くので、そこで認証します。
そして、App connected to GitHubでデプロイしたいリポジトリを選択します。

デプロイ方法を「Automatic deploys」にするか「Manual deploy」にするか選べます。
今回は、Manual deployにしたので、下の画面の状態で「Deploy Branch」をクリックするとデプロイが始まります。
すると、ログが書かれるシェル的なものが出てくるので、それが閉じてデプロイが完了するまで待ちます。

デプロイが完了して、Resourcesタブに移動すると、Dynosの部分にProcfileで記述したコマンドが表示されています。
そこで、鉛筆マークを押して、アクティブにして、Confirmします。

アクティブになっているときの画面です。

動作確認
それでは、サーバも動いたので、Discordで確認してみます。
- ボットがオンラインになっているのが確認できます。
- そして、メッセージを打ったら、反応も返ってきています!

おしまい

よっしゃあ〜、動いたな。
Herokuのデプロイはかなり簡単だったな。

そだね。Python以外のアプリをデプロイした際に、手順がどうなるんだろうね。
今度、試してみますか。
参考
以下のサイトを参考にしました。

以上になります!
コメント