Skip to content

Instantly share code, notes, and snippets.

@NAKNAO-nnct
Last active August 26, 2021 17:49
Show Gist options
  • Save NAKNAO-nnct/581911e235c8e0e644484a34a17c28d3 to your computer and use it in GitHub Desktop.
Save NAKNAO-nnct/581911e235c8e0e644484a34a17c28d3 to your computer and use it in GitHub Desktop.
Discordのボイスチャンネルに誰かが入ったら通知するbot ref: https://qiita.com/trompot/items/5251704272cce302af33
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
$ gem install discordrb
https://discordapp.com/oauth2/authorize?client_id=ここに取得したClientID&scope=bot&permissions=0
$ ruby bot.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment