rubycord
An implementation of the Discord API using Ruby.
Fork of the Discordrb project starting from this release
Quick links to sections
- Introduction
- Dependencies
- Installation
- Usage
- Webhooks Client
- Support
- Development, Contributing
- License
See also: Documentation, Tutorials
Introduction
rubycord
aims to meet the following design goals:
- Full coverage of the public bot API.
- Expressive, high level abstractions for rapid development of common applications.
- Friendly to Ruby beginners and beginners of open source contribution.
If you enjoy using the library, consider getting involved with the community to help us improve and meet these goals!
You should consider using rubycord
if:
- You need a bot - and fast - for small or medium sized communities, and don't want to be bogged down with "low level" details. Getting started takes minutes, and utilities like a command parser and tools for modularization make it simple to quickly add or change your bots functionality.
- You like or want to learn Ruby, or want to contribute to a Ruby project. A lot of our users are new to Ruby, and eventually make their first open source contributions with us. We have an active Discord channel with experienced members who will happily help you get involved, either as a user or contributor.
- You want to experiment with Discord's API or prototype concepts for Discord bots without too much commitment.
You should consider other libraries if:
- You need to scale to large volumes of servers (>2,500) with lots of members. It's still possible, but it can be difficult to scale Ruby processes, and it requires more in depth knowledge to do so well. Especially if you already have a bot that is on a large amount of servers, porting to Ruby is unlikely to improve your performance in most cases.
- You want full control over the library that you're using. While we expose some "lower level" interfaces, they are unstable, and only exist to serve the more powerful abstractions in the library.
Dependencies
- Ruby >= 3.1.3 supported
- An installed build system for native extensions (on Windows, make sure you download the "Ruby+Devkit" version of RubyInstaller)
Voice dependencies
This section only applies to you if you want to use voice functionality.
- libsodium
- A compiled libopus distribution for your system, anywhere the script can find it. See here for installation instructions.
- FFmpeg installed and in your PATH
Installation
With Bundler
Using Bundler, you can add rubycord to your Gemfile:
gem "rubycord"
And then install via bundle install
.
If you want to run the latest code instead, use this gem line instead:
gem "rubycord", github: "dakurei-gems/rubycord", branch: "main"
⚠️ Note that main may contain breaking changes or other unstable code !
Run the ping example to verify that the installation works (make sure to replace the token and client ID in there with your bots'!):
To run the bot while using bundler:
bundle exec ruby ping.rb
With Gem
Alternatively, while Bundler is the recommended option, you can also install rubycord without it.
Linux / macOS
gem install rubycord
Windows
Make sure you have the DevKit installed! See the Dependencies section)
gem install rubycord --platform=ruby
To run the bot:
ruby ping.rb
Installation Troubleshooting
See https://github.com/dakurei-gems/rubycord/wiki/FAQ#installation for a list of common problems and solutions when installing rubycord
.
Usage
You can make a simple bot like this:
require "rubycord"
bot = Rubycord::Bot.new token: '<token here>'
bot.message(with_text: "Ping!") do |event|
event.respond "Pong!"
end
bot.run
This bot responds to every "Ping!" with a "Pong!".
You can find examples of projects that use rubycord by searching for the rubycord topic on GitHub.
If you've made an open source project on GitHub that uses rubycord, consider adding the rubycord
topic to your repo!
Webhooks Client
Also included is a webhooks client, which can be used as a separate gem rubycord-webhooks
. This special client can be used to form requests to Discord webhook URLs in a high-level manner.
Usage
require "rubycord/webhooks"
WEBHOOK_URL = "<webhook url here>".freeze
client = Rubycord::Webhooks::Client.new(url: WEBHOOK_URL)
client.execute do |builder|
builder.content = "Hello world!"
builder.add_embed do |embed|
embed.title = "Embed title"
embed.description = "Embed description"
embed.timestamp = Time.now
end
end
Note: The rubycord
gem relies on rubycord-webhooks
. If you already have rubycord
installed, require 'rubycord/webhooks'
will include all of the Webhooks
features as well.
Support
If you need help or have a question, you can:
- Open an issue. Be sure to read the issue template, and provide as much detail as you can.
Contributing
Thank you for your interest in contributing! Bug reports and pull requests are welcome on GitHub at https://github.com/dakurei-gems/rubycord.
Be sure to use the search function in our documentation or on GitHub, to see if there are any duplicate issues/PRs before anything else
Development setup
This section is for developing rubycord itself! If you just want to make a bot, see the Installation section.
After checking out the repo, run bin/setup
to install dependencies. You can then run tests via bundle exec rspec spec
. Make sure to run standard also: bundle exec standardrb
. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
License
The gem is available as open source under the terms of the MIT License.