Skip to content

Instantly share code, notes, and snippets.

@tomaszwro
Created February 19, 2021 08:34
Show Gist options
  • Select an option

  • Save tomaszwro/c6574aa95c0c4009adcba92a8da2cec1 to your computer and use it in GitHub Desktop.

Select an option

Save tomaszwro/c6574aa95c0c4009adcba92a8da2cec1 to your computer and use it in GitHub Desktop.

Revisions

  1. tomaszwro created this gist Feb 19, 2021.
    26 changes: 26 additions & 0 deletions discord-to-slack-bot.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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