Skip to content

Instantly share code, notes, and snippets.

@tomaszwro
Created February 19, 2021 08:34
Show Gist options
  • Save tomaszwro/c6574aa95c0c4009adcba92a8da2cec1 to your computer and use it in GitHub Desktop.
Save tomaszwro/c6574aa95c0c4009adcba92a8da2cec1 to your computer and use it in GitHub Desktop.
Discord-to-Slack bot
require "discordrb"
require "httparty"
def notify_slack(message)
HTTParty.post(
"https://hooks.slack.com/services/xxx/xxxx/xxxxx",
body: JSON.dump({ text: message }),
headers: { "Content-Type" => "application/json" }
)
end
bot = Discordrb::Bot.new(token: "xxxx.xxx.xxxx")
bot.voice_state_update do |event|
case
when event.channel.nil?
notify_slack "✂️ #{event.user.name} disconnected"
when event.old_channel.nil?
notify_slack "👋 #{event.user.name} connected to #{event.channel.name}"
when event.channel.name != event.old_channel.name
notify_slack "🔀 #{event.user.name} switched to #{event.channel.name}"
end
end
at_exit { bot.stop }
bot.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment