Project

discorb

0.0
The project is in a healthy, maintained state
discorb is a Discord API wrapper for Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies

Runtime

~> 1.30.1
~> 0.56.5
 Project Readme

discorb

Document Gem Gem Discord GitHub

discorb is a Discord API wrapper for Ruby.

Installation

Add this line to your application's Gemfile:

gem 'discorb'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install discorb

Usage

Ping & Pong

require "discorb"

client = Discorb::Client.new

client.once :standby do
  puts "Logged in as #{client.user}"
end

client.on :message do |message|
  next if message.author.bot?
  next unless message.content == "ping"

  message.channel.post("Pong!")
end

client.run(ENV["DISCORD_BOT_TOKEN"])

Quiz Game

require "discorb"

client = Discorb::Client.new

client.once :standby do
  puts "Logged in as #{client.user}"
end

client.on :message do |message|
  next if message.author.bot?
  next unless message.content == "!quiz"

  operator = [:+, :-, :*].sample
  num1 = rand(1..10)
  num2 = rand(1..10)

  val = num1.send(operator, num2)
  message.channel.post("Quiz: `#{num1} #{operator} #{num2}`")
  begin
    msg = client.event_lock(:message, 30) { |m|
      m.content == val.to_s && m.channel == message.channel
    }.wait
  rescue Discorb::TimeoutError
    message.channel.post("No one answered...")
  else
    msg.reply("Correct!")
  end
end

client.run(ENV["DISCORD_BOT_TOKEN"])

Slash Commands

require "discorb"

client = Discorb::Client.new

client.slash("hello", "Greet for you") do |interaction|
  interaction.post("Hello!", ephemeral: true)
end

client.run(ENV["DISCORD_BOT_TOKEN"])

Note: You must run discorb setup before using slash commands.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/discorb-lib/discorb.

License

The gem is available as open source under the terms of the MIT License.