GithubHelp home page GithubHelp logo

piharpi / discordrb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from discordrb/discordrb

0.0 2.0 0.0 9.04 MB

Discord API for Ruby

Home Page: https://discord.gg/cyK3Hjm

License: MIT License

Ruby 99.93% Shell 0.07%

discordrb's Introduction

Gem Gem Build Status Inline docs Code Climate Test Coverage Join Discord

discordrb

An implementation of the Discord API using Ruby.

Quick links to sections

See also: Documentation, Tutorials

Dependencies

  • Ruby >= 2.4 supported
  • An installed build system for native extensions (on Windows, make sure you download the "Ruby+Devkit" version of RubyInstaller)

Note: RubyInstaller for Ruby versions 2.4+ will install the DevKit as the last step of the installation.

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

In addition to this, if you're on Windows and want to use voice functionality, your installed Ruby version needs to be 32 bit, as otherwise Opus won't work.

Installation

With Bundler

Using Bundler, you can add discordrb to your Gemfile:

gem 'discordrb'

And then install via bundle install.

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 discordrb without it.

Linux / macOS

gem install discordrb

Windows

Make sure you have the DevKit installed! See the Dependencies section)

gem install discordrb --platform=ruby

To run the bot:

ruby ping.rb

Troubleshooting

If you get an error like this when installing the gem:

ERROR:  Error installing discordrb:
        The 'websocket-driver' native gem requires installed build tools.

You're missing the development kit required to build native extensions.

RubyInstaller for ruby 2.4.3-2 and above

RubyInstaller after version 2.3.3 now includes the development kit in the installer. If you do not have the development kit and have installed ruby using RubyInstaller, open a command prompt with administrator privileges and run:

ridk install

Select option 3, and then run

ridk enable

To enable the changes

If Ruby complains about ffi_c not being able to be found:

For example

C:/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ffi_c (LoadError)

Your ffi setup is screwed up, first run gem uninstall ffi (uninstall all versions if it asks you, say yes to any unmet dependencies), then run gem install ffi --platform=ruby to fix it. If it says something about build tools, follow the steps in the first troubleshooting section.

If you're having trouble getting voice playback to work:

Look here: https://github.com/meew0/discordrb/wiki/Voice-sending#troubleshooting

Usage

You can make a simple bot like this:

require 'discordrb'

bot = Discordrb::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!".

See additional examples here.

You can find examples of projects that use discordrb by searching for the discordrb topic on GitHub.

If you've made an open source project on GitHub that uses discordrb, consider adding the discordrb topic to your repo!

Webhooks Client

Also included is a webhooks client, which can be used as a separate gem discordrb-webhooks. This special client can be used to form requests to Discord webhook URLs in a high-level manner.

Usage

require 'discordrb/webhooks'

WEBHOOK_URL = 'https://discordapp.com/api/webhooks/424070213278105610/yByxDncRvHi02mhKQheviQI2erKkfRRwFcEp0MMBfib1ds6ZHN13xhPZNS2-fJo_ApSw'.freeze

client = Discordrb::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 discordrb gem relies on discordrb-webhooks. If you already have discordrb installed, require 'discordrb/webhooks' will include all of the Webhooks features as well.

Support

You can find me (@meew0, ID 66237334693085184) on the unofficial Discord API server - if you have a question, just ask there, I or somebody else will probably answer you: https://discord.gg/3Trm6FW

Development

This section is for developing discordrb 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 rubocop also: bundle exec rubocop. 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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/meew0/discordrb.

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.