💎
[使ってみた] discorb + Heroku + GitHub
概要
discorb
is a Discord API wrapper for Ruby.
使用するサービス
まず、上記サービスのアカウントを用意してください。
GitHub でRepository
を作る
-
New
->Repository name
->MyFirstDiscorbBot
->Public
->Create repository
echo "# MyFirstDiscorbBot" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/kaiyu-tech/MyFirstDiscorbBot.git
git push -u origin main
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
ruby "~> 3.0"
gem "discorb"
bundle install
bundle lock --add-platform x86_64-linux
main.rb
require "discorb"
client = Discorb::Client.new
client.once :ready do
puts "Logged in as #{client.user}"
end
client.on :message do |message|
next if message.author.bot?
next unless message.content == "/ping"
message.channel.post("pong!")
end
client.run(ENV["DISCORD_BOT_TOKEN"])
Procfile
worker: bundle exec ruby main.rb
Discord Developer Portal でBot Acount
を作る
-
Applications
->New Application
->NAME
->MyFirstDiscorbBot
->Create
-
Bot
->Add Bot
->Yes, do it!
-
OAuth2
->[x]bot
->[x]applications.commands
->Copy
-
MyFirstDiscorbBot
をサーバーに招待
Heroku でApplication
を作る
-
Create new app
->App name
->my-first-discorb-bot
->Create app
-
Deploy
->GitHub
-
Setting
->Reveal Config Vars
->KEY:
DISCORD_BOT_TOKEN
->VALUE:
※1
->Add
※1
Discord Developer Portal -> Bot
-> TOKEN
-> Copy
-
Deployment method
->GitHub
->App connected to GitHub
-
App connected to GitHub
->repo-name
->MyFirstDiscorbBot
->Connect
-
Automatic deploys
->main
->Enable Automatic Deploys
brew install heroku/brew/heroku
heroku login --interactive
heroku ps:scale worker=1 -a my-first-discorb-bot
これで招待したサーバーのBotが動作します。
Discussion