Last active
August 26, 2021 17:49
-
-
Save NAKNAO-nnct/581911e235c8e0e644484a34a17c28d3 to your computer and use it in GitHub Desktop.
Discordのボイスチャンネルに誰かが入ったら通知するbot ref: https://qiita.com/trompot/items/5251704272cce302af33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TOKEN = '自分で取得してね' | |
CLIENT_ID = ID(数字) | |
# 通知用のチャンネルID | |
inform_channel = チャンネルID または '#チャンネルname' | |
# bot | |
bot = Discordrb::Commands::CommandBot.new token: TOKEN, client_id: CLIENT_ID, prefix:'/' | |
# 誰かがvoice channelに出入りしたら発火 | |
bot.voice_state_update do |event| | |
# 発火させたユーザー名を取得 | |
user = event.user.name | |
# もしデータが空だと抜けていったチャンネルを取得 | |
if event.channel == nil then | |
# チャンネル名を取得 | |
channel_name = event.old_channel.name | |
# 退出したことをinform_channelに通知 | |
bot.send_message(inform_channel, "@everyone #{user} が #{channel_name}を出たで~") | |
else | |
# チャンネル名を取得 | |
channel_name = event.channel.name | |
# 入室したことをinform_channelに通知 | |
bot.send_message(inform_channel, "@everyone #{user} が #{channel_name}に入ったで~") | |
end | |
end | |
# botを起動 | |
bot.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ gem install discordrb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://discordapp.com/oauth2/authorize?client_id=ここに取得したClientID&scope=bot&permissions=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby bot.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment