You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+66-30Lines changed: 66 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,37 @@
5
5
6
6
## Getting Started
7
7
8
-
To work on this project please create an account on Cloudflare and Discord.
9
-
Also, create a personal discord server.
10
-
Copy the guild id of your server and save it in a .env file as `DISCORD_GUILD_ID`
11
-
12
-
To get the server ID for the first parameter, open Discord, go to Settings > Advanced and enable developer mode.
13
-
Then, right-click on the server title and select "Copy ID" to get the guild ID.
14
-
8
+
To contribute to this project, you have to set up few things first.
9
+
10
+
- Create an account on Cloudfare Workers and Discord if you don't already have one
11
+
- Create a personal discord server
12
+
- Fork and clone this repo (this is optional; if you are a member of RDS community, you don't have to fork)
13
+
- Install volta - this will check if you have the right node version or not
14
+
- Create a .env file in the root directory of the project
15
+
16
+
Next, you need to gather few details that will be crucial for setting up your local environment. The IDs that you will gather in the next steps, will be stored as secret keys on the Cloudfare workers platform, where the application will be hosted.
17
+
18
+
- To get the guild ID of your server :
19
+
- Open your discord server
20
+
- Click on the server name in the top-left corner
21
+
- Click on Server Settings
22
+
- Click on the Widget tab in the side panel
23
+
- Copy/paste the Server ID in the .env file as `DISCORD_GUILD_ID`
- copy/paste the Application ID in the .env file as `DISCORD_APPLICATION_ID`
28
+
- copy/paste the Public Key in the .env file as `DISCORD_PUBLIC_KEY`
17
29
18
-
Gather the following details from the Developer portal and save it in a .env file.
30
+
Next, you need to create your own bot. The idea here is that you will have your own bot that can be used to run all commands in your private server. You can add new features and test it there to make sure everything works as expected, before deploying the code on production.
19
31
20
-
```
21
-
DISCORD_TOKEN: Available in bot panel of your discord bot after clicking reset token button.
22
-
DISCORD_APPLICATION_ID: Available in general panel of your discord bot.
23
-
DISCORD_PUBLIC_KEY: Available in general panel of your discord bot.
24
-
```
32
+
- To create a bot, go to the Bot panel and click on 'Add Bot'
33
+
- Next, copy the token from the dashboard there and save it in the .env file as `DISCORD_TOKEN `.
34
+
- Next, you have to generate a set of RSA keys 2048 bit in size. We will use them as `BOT_PRIVATE_KEY` and `BOT_PUBLIC_KEY`.
25
35
26
-
Please set Following permissions for your bot:
36
+
- You can read more about RSA keys [here](https://www.namecheap.com/support/knowledgebase/article.aspx/798/69/what-is-an-rsa-key-used-for/)
37
+
- All you need to know for now is that the private and public keys are used when authenticating using JWT.
38
+
- You can generate your own keys for local development [here](https://cryptotools.net/rsagen)
27
39
28
40
- Navigate to OAuth2 > URL Generator
29
41
- In scopes select `bot` and `applications.commands`
@@ -39,35 +51,59 @@ Please set Following permissions for your bot:
39
51
- Mention Everyone
40
52
- Use slash commands
41
53
42
-
After providing all the permissions you will get an url at the bottom of the page use that to invite the bot to your server.
54
+
After providing all the permissions, a URL will be generated below.
43
55
44
-
Open the Url you get and invite the bot to your test server.
56
+
- Copy/paste this URL in a new browser window
57
+
- Select your private server from the dropdown and authorize
58
+
- This will invite the bot to your private discord server
45
59
46
60
## Setting Up Local Development
47
61
48
-
- Clone the Repository to your machine
49
-
- Now, get the .env file created above in the project folder
50
62
- run `npm install`
51
-
- Now, run the command `npm run register`
63
+
- Now, run the command `npm run register` - this will register all the commands to your discord bot.
52
64
53
-
This will register all the commands to your discord bot.
65
+
Next you will have to set up the wrangler cli, so that you can connect to your cloudflare workers account.
54
66
55
-
Now let's link our local development server to our bot.
67
+
- run `npx wrangler login` -> You will be prompted to authenticate your account, after which you will see a 'successfully logged in' message in your terminal
68
+
- For a sanity check, run `npx wrangler whoami` -> You will then see your account name and account id in the terminal
56
69
57
-
- After all the commands are installed we need to save few secrets in wrangler cli.
58
-
- run command `wrangler secret put DISCORD_TOKEN` and then enter the value of your token.
59
-
- run command `wrangler secret put DISCORD_PUBLIC_KEY` and enter the public key.
60
-
- Now, start the local server with the command `npm start`
61
-
- Once the wrangler starts make sure it is running on port `8787`
62
-
- Once the server starts on desired port open another terminal and type in the command `npm run ngrok`
63
-
- The above command will give you a `https` link copy that.
70
+
- Run the command `npx wrangler publish`
71
+
- Go to Your cloudflare `dashboard > workers > discord-slash-commands > settings > variables > edit Variables`
72
+
- Now add following variables to your environment:
73
+
74
+
-`BOT_PRIVATE_KEY`
75
+
-`DISCORD_GUILD_ID`
76
+
-`DISCORD_PUBLIC_KEY`
77
+
-`DISCORD_TOKEN`
78
+
79
+
- Now, start the local server with the command `npm start`- make sure it is running on port `8787`
80
+
- Open another terminal and type in the command `npm run ngrok`.
81
+
-`ngrok` creates a secure tunnel that allows a local server to connect to external clients. It provides a URL that can be used to connect to a local server, just like if it were a public server hosted somewhere. For eg: Say you're running your app on `http://127.0.0.1:5501/` i.e localhost port 5501. Any external applications cannot connect to this server by default, but `ngrok` will give you a `http(s)` URL that any other client can use to connect to this server.
82
+
- You will see 2 URLs generated, copy the `https` URL (eg: https://765m-321-132-44-44-44.ngrok.io)
64
83
- Now, go to [Discord Developer Portal](https://discord.com/developers/applications) and select your bot
65
-
- In general information panel you will find a space for `INTERACTIONS ENDPOINT URL`
66
-
- Enter the copied link here and hit save.
84
+
- In the General Information, paste the link in the `INTERACTIONS ENDPOINT URL` field.
67
85
68
86
To verify if your bot is working:
69
87
70
88
- Go to the server where your bot was invited
71
89
- run a /hello command and the bot should reply with `Hello <Your_username>`
72
90
91
+
Now add the public key in `rds-backend`
92
+
93
+
- Go to `local.js` in config
94
+
- Create following there
95
+
96
+
```
97
+
botToken:{
98
+
botPublicKey:<Public key generated in the format similar to development.js>
99
+
}
100
+
```
101
+
102
+
- Start the rds backend
103
+
- Open a new terminal and run the following command `npx ngrok http <backend-port>`
104
+
105
+
- Go to `constants.js` in discord-slash-commands
106
+
- Go to `src/constants/urls.ts`
107
+
- Change the `RDS_BASE_DEVELOPMENT_API_URL` to the `ngrok https` URL generated for rds backend
108
+
73
109
Now you are ready to contribute to the Repository.
0 commit comments