/[sudobot]/branches/6.x/docs/getting-started.md
ViewVC logotype

Contents of /branches/6.x/docs/getting-started.md

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: text/markdown
File size: 8723 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 # Getting Started
2
3 Thanks for choosing SudoBot! In this article you'll learn how to set up a custom instance of SudoBot and configure it so that it does exactly what you want.
4
5 {% hint style="info" %}
6 If you don't want to set the bot up yourself and want a pre-hosted solution for free, you can contact [@rakinar2](https://discord.com/users/774553653394538506) at Discord. Your Discord server should have at least 50 members to be eligible.
7 {% endhint %}
8
9 ## Requirements
10
11 These are the requirements to host SudoBot:
12
13 * A Discord API Application token (Go to [Discord Developer Portal](https://discord.com/developers/applications) to obtain a token)
14 * [Node.js](https://nodejs.org) version 18 or higher
15 * A PostgreSQL database (If you're looking for a free PostgreSQL hosting service, check out [Neon](https://neon.tech))
16
17 Additionally, you can also set these up if you want to use them:
18
19 * Cat and dog API Token (for fetching cat and dog images using `cat` and `dog` commands, the tokens can be obtained at [thecatapi.com](https://thecatapi.com) and [thedogapi.com](https://thedogapi.com))
20 * Pixabay API Token to use the `pixabay` command (can be obtained [here](https://pixabay.com/api/docs/))
21 * A Discord Webhook URL for sending error reports
22
23 ## Cloning the project and setting up
24
25 First of all, clone the repository using [git](https://git-scm.com) or download the [latest release](https://github.com/onesoft-sudo/sudobot/releases/latest) and extract it.
26
27 To clone the repository, run this command:
28
29 ```
30 git clone https://github.com/onesoft-sudo/sudobot
31 ```
32
33 After this command completes, go inside of the directory. (`sudobot/` if you cloned it using the above command)
34
35 Then, install the dependencies using the following command:
36
37 ```
38 npm install -D
39 ```
40
41 Generate the JSON config schema files using the following command:
42
43 ```
44 npx ts-node scripts/generate-config-schema.ts
45 ```
46
47 ## The environment variables
48
49 Create a file named `.env` inside of the root project directory. This file will contain some secret information that the bot needs, to work. (e.g. bot token)
50
51 Then you need to add a few variables to `.env` file:
52
53 ```
54 # This is your bot's token.
55 TOKEN=
56
57 # This is the home server, where the bot will search for emojis.
58 HOME_GUILD_ID=
59
60 # The client ID of your bot application.
61 CLIENT_ID=
62
63 # Database URL
64 DB_URL=
65 ```
66
67 Here:
68
69 * `TOKEN` is your bot token. Make sure to put the correct token here, otherwise the bot won't be able to log in to Discord. The bot token can be obtained from [https://discord.com/developers/applications](https://discord.com/developers/applications).
70 * `HOME_GUILD_ID` is the main server ID of the bot. The bot expects that it will always stay in that server, and it will search for the emojis there. You can download the emojis and use them freely. To download, go to [the downloads list](https://www.onesoftnet.eu.org/downloads/sudo/emojis/).
71 * `CLIENT_ID` is the client ID of your bot application. You can obtain the client ID for your bot at [https://discord.com/developers/applications](https://discord.com/developers/applications).
72 * `DB_URL` is the database URL. We'll be talking about this just in a moment. You can [jump](getting-started.md#setting-up-a-database-for-the-bot) into that section right now if you want.
73
74 A few more environment variables can be specified:
75
76 * `DEBUG`: Used by the [Prisma](https://prisma.io/) ORM. This enables extra debug logging, aka Verbose Mode.
77 * `SUDO_ENV` and `NODE_ENV`: If one of these is set to `dev`, then the bot will enter Verbose Mode, and log everything that it does or happens. This is useful if you want to debug the bot or troubleshoot something.
78 * `CAT_API_TOKEN`: The Cat API token to use when fetching cat images, using `cat` command.
79 * `DOG_API_TOKEN`: The Dog API token to use when fetching dog images, using `dog` command.
80
81 ## Setting up a Database for the bot
82
83 As we've said [before](getting-started.md#configuration-and-the-environment-variables), `DB_URL` is the environment variable that you need to put in `.env` and the value of this variable should be the database URL. SudoBot at the moment, only supports **PostgreSQL**.
84
85 {% hint style="danger" %}
86 As of November 28, 2023, we no longer officially support MySQL as a database for being used with SudoBot. Please migrate to PostgreSQL.
87 {% endhint %}
88
89 {% hint style="info" %}
90 If you want a free PostgreSQL hosting service, check out [Neon](https://neon.tech). It's easy to set up, and completely free of cost.
91 {% endhint %}
92
93 Your database URL should look like this if you're using PostgreSQL:
94
95 ```
96 postgresql://username:password@hostname:port/dbname
97 ```
98
99 * `username` is your database username (usually this is `postgres`)
100 * `password` is your database password
101 * `hostname` is your database hostname
102 * `port` is your database port (usually this is `5432`)
103 * `dbname` is your database name (usually this is`postgres`)
104
105 After you have set the database URL inside `.env`, you can run the following command:
106
107 ```
108 npx prisma db push
109 ```
110
111 This will create the necessary tables for you inside the database.
112
113 ## Configuration
114
115 Now it's time to configure the bot. Now, SudoBot comes with the config files bundled already, but you should edit them.
116
117 **Step 1.** Open up `config/config.json` and you have two options:
118
119 Remove everything inside of the file, and just put an empty object `{}` inside of that file and save it if you don't want to configure anything and just want the default settings. Or,
120
121 Manually set the settings inside of the file. If you're following along this documentation and have run the script `generate-config-schema.ts` (previously specified [here](getting-started.md#cloning-the-project-and-setting-up)), then when you edit the file, you can remove everything inside of the file, and put the following JSON object inside of that file:
122
123 ```
124 {
125 "$schema": "./schema/config.json",
126 "guild_id": {
127
128 }
129 }
130 ```
131
132 Replace `guild_id` with your main guild ID, where you want to use the bot. If you want to use the bot in multiple servers, specify them here, as the keys of the root object.
133
134 If you're using an IDE or editor like [VS Code](https://code.visualstudio.com/) or [WebStorm](https://www.jetbrains.com/webstorm/), you can hit Ctrl + Space (or Cmd + Space if you're on a Mac) to get auto completion and see available options. The IDE/editor will highlight errors inside of your config file if you have any.
135
136 **Step 2.** Open up `config/system.json` file and similarly here you'll get autocompletion. But you don't need to delete everything here, just change the `system_admins` property, which is an array of user IDs. Just add your User ID into the array. System Admins are those who have full access to the bot and can control everything. They are able to run commands like `-eval`.
137
138 ## Registering Application Commands
139
140 If you want to use the application slash commands and context menu commands of SudoBot, you have to register it to the API first. To do that, simply run:
141
142 ```
143 npx ts-node scripts/deploy-commands.ts
144 ```
145
146 Pass the `--guild` option to register guild commands instead of global commands, and `--clear` to clear all the registered slash commands in the API.
147
148 ## Building the bot
149
150 Now that we have configured the bot and specified every setting, we can go ahead and invoke the TypeScript compiler (`tsc`) to build the bot and generate compiled JavaScript files that the NodeJS interpreter can run. To compile the bot, simply run:
151
152 ```
153 npm run build
154 ```
155
156 ## Starting the bot
157
158 Now it's time to start the bot. Run the following command to start the bot:
159
160 ```
161 npm start
162 ```
163
164 And if everything was configured correctly, the bot will log in successfully to Discord. Congratulations, you've set up your own instance of SudoBot!
165
166 ## Emojis
167
168 The bot uses some custom emojis and it will try to find those emojis in the Home Guild (The main server, which is configured in `HOME_GUILD_ID` environment variable).
169
170 The emojs are freely available for download at the [download site](https://www.onesoftnet.eu.org/downloads/sudo/emojis/). The bot uses some other emojis as well, if you want you can download them from [emoji.gg](https://emoji.gg).
171
172 If you don't add these emojis, the bot may send messages that look weird or too simple.
173
174 ## Help & Support
175
176 In case if you're facing issues, feel free to open an issue at [GitHub](https://github.com/onesoft-sudo/sudobot/issues). Or you can contact the Author of the bot in the following ways:
177
178 * Email: [[email protected]](mailto:[email protected])
179 * Discord: [@rakinar2](https://discord.com/users/774553653394538506)
180 * Discord Servers: [OSN's server](https://discord.gg/JJDy9SHzGv)
181
182 Give the repository a star to show your support! We'll be really thankful if you do.

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26