Skip to content

Instantly share code, notes, and snippets.

@Plutor
Forked from tomaszwro/discord-to-slack-bot.rb
Last active May 16, 2022 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Plutor/24bf5496025c50ee533fd3f0c538355a to your computer and use it in GitHub Desktop.
Save Plutor/24bf5496025c50ee533fd3f0c538355a to your computer and use it in GitHub Desktop.
Discord-to-Slack bot
require "discordrb"
require "httparty"
def notify_slack(message)
HTTParty.post(
# people_who_play_games
"https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
body: JSON.dump({
text: message,
username: "Discord announcement",
icon_emoji: ":mega:",
}),
headers: { "Content-Type" => "application/json" }
)
end
bot = Discordrb::Bot.new(token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
users = Hash.new
bot.voice_state_update do |event|
if event.channel.nil?
if !users.has_key?(event.user.name)
return
end
users.delete(event.user.name)
if users.length() == 0
notify_slack "No one is chatting on Discord"
end
else
if users.has_key?(event.user.name)
return
end
if users.length() == 0
notify_slack "Someone is chatting on <https://discord.gg/xxxxxxxxxxxxxxxxxxxxxxx|the Discord>"
end
users[event.user.name] = 1
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