Skip to content

Commit cffd26a

Browse files
committed
Add getting started guide.
1 parent 492dd59 commit cffd26a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

guides/getting-started/readme.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Getting Started
2+
3+
This guide explains how to create a bot for Discord using the `async-discord` gem.
4+
5+
## Installation
6+
7+
First, create a project with a gemfile, and add the `async-discord` gem to it:
8+
9+
```bash
10+
$ bundle add async-discord
11+
```
12+
13+
## Creating a Bot
14+
15+
You will need to follow the [developer documentation](https://discord.com/developers/docs/intro) to create a bot and obtain a token. Once you have a token, you can create a bot like this:
16+
17+
```ruby
18+
require 'async/discord'
19+
20+
TOKEN = 'your-bot-token'
21+
22+
Async::Discord::Client.open do |client|
23+
client = client.authenticated(bot: TOKEN)
24+
25+
client.gateway.connect do |connection|
26+
identity = connection.identify(token: TOKEN)
27+
28+
connection.listen do |payload|
29+
case payload[:t]
30+
when "MESSAGE_CREATE"
31+
Console.info(self, "Received message!", payload: payload)
32+
end
33+
end
34+
end
35+
end
36+
```
37+
38+
This code will connect to the Discord gateway and listen for messages. When a message is received, it will log the payload to the console. You must make sure your bot is set up with the correct permissions to receive messages.

0 commit comments

Comments
 (0)