forked from rikai/Showbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
showbot_discord.rb
32 lines (24 loc) · 1.6 KB
/
showbot_discord.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require File.join(File.dirname(__FILE__), 'environment')
require 'discordrb'
require 'rest-client'
# This statement creates a bot with the specified token and application ID. After this line, you can add events to the
# created bot, and eventually run it.
#
# If you don't yet have a token and application ID to put in your .env, you will need to create a bot account here:
# https://discordapp.com/developers/applications/me
# If you're wondering about what redirect URIs and RPC origins, you can ignore those for now. If that doesn't satisfy
# you, look here: https://github.com/meew0/discordrb/wiki/Redirect-URIs-and-RPC-origins
# After creating the bot, simply copy the token (*not* the OAuth2 secret) and the client ID and place it into the
# your .env file under "DISCORD_TOKEN" and "DISCORD_CLIENT_ID".
bot = Discordrb::Bot.new token: ENV['DISCORD_TOKEN'], client_id: ENV['DISCORD_CLIENT_ID']
# Here we output the invite URL to the console so the bot account can be invited to the channel. This only has to be
# done once, afterwards, you can remove this part if you want
puts "This bot's invite URL is #{bot.invite_url}."
puts 'Click on it to invite it to your server.'
# This is a simple example of adding the '!bacon' command from IRC to discord.
bot.message(with_text: "!bacon") do |event|
event.respond "*Gives #{event.user.name} a strip of delicious bacon!*"
end
# This method call has to be put at the end of your script, it is what makes the bot actually connect to Discord. If you
# leave it out (try it!) the script will simply stop and the bot will not appear online.
bot.run