Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
laptopwiki:guides:discord:stickybot [29/06/2024 15:17] – created - external edit 127.0.0.1 | laptopwiki:guides:discord:stickybot [18/07/2024 21:11] (current) – [Run stickybot in the background] dustojnikhummer | ||
---|---|---|---|
Line 4: | Line 4: | ||
{{: | {{: | ||
Built by: [[https:// | Built by: [[https:// | ||
- | If you have any issues with this guide or feedback please contact [[https:// | + | If you have any issues with this guide or feedback please contact [[https:// |
\\ | \\ | ||
This guide assumes you are working without a GUI, most likely connected over SSH. If you are working with a Linux Desktop environment some of these steps can be done that way, like unzipping the archive. | This guide assumes you are working without a GUI, most likely connected over SSH. If you are working with a Linux Desktop environment some of these steps can be done that way, like unzipping the archive. | ||
Line 10: | Line 10: | ||
===== Requirements ===== | ===== Requirements ===== | ||
- | * A Linux webhost | + | * A Linux webhost |
- | * npm (sudo apt install npm)\\ | + | * npm |
- | * npm dotenv (npm install dotenv) | + | * npm dotenv (npm install dotenv) |
- | * nodejs | + | * nodejs |
- | * wget \\ | + | * wget |
- | * unzip \\ | + | * unzip |
- | * Discord developer account | + | * Discord developer account |
* Linux Terminal | * Linux Terminal | ||
- | * Basic knowledge of nano/micro text editors | + | * Basic knowledge of nano/micro text editors |
===== Download ===== | ===== Download ===== | ||
- | Download here: [[https:// | + | Download here: [[https:// |
- | Unzip the archive and copy its contents to your Linux server. | + | Unzip the archive and copy its contents to your Linux server. Alternatively, |
- | Alternatively, | + | |
< | < | ||
- | wget https:// | + | |
+ | wget https:// | ||
</ | </ | ||
Line 33: | Line 33: | ||
Then unzip the archive with: | Then unzip the archive with: | ||
- | < | + | < |
+ | unzip ./ | ||
</ | </ | ||
Line 39: | Line 40: | ||
If you want to move the folder somewhere else (or what to rename the folder) make sure to move the entire folder, not all of its contents. Linux' | If you want to move the folder somewhere else (or what to rename the folder) make sure to move the entire folder, not all of its contents. Linux' | ||
- | < | + | < |
+ | mv ./ | ||
</ | </ | ||
Line 45: | Line 47: | ||
===== Bot Setup - Discord ===== | ===== Bot Setup - Discord ===== | ||
- | - Open the [[https:// | + | - Open the [[https:// |
- | - In the top right create a New Application and give it a name. \\ | + | - In the top right create a New Application and give it a name. |
- | - In the left panel select the Bot section. On the right click Add Bot. \\ | + | - In the left panel select the Bot section. On the right click Add Bot. |
- | - Click the Reset Token button. Copy that token and do not lose it. Also make sure nobody else has that token. | + | - Click the Reset Token button. Copy that token and do not lose it. Also make sure nobody else has that token. |
- | - In the left panel select OAuth2-URL Generator and select the bot scope. Below that a permission list will appear. | + | - In the left panel select OAuth2-URL Generator and select the bot scope. Below that a permission list will appear. |
- | - Select the permissions you want. Read Message History, Manage Messages, Send Messages at least. Add more if you want. \\ | + | - Select the permissions you want. Read Message History, Manage Messages, Send Messages at least. Add more if you want. |
{{: | {{: | ||
- | * Below that will be a generated invite link for your bot. Use that link to invite the bot to the server you want to use it in. \\ | + | * Below that will be a generated invite link for your bot. Use that link to invite the bot to the server you want to use it in. |
- | {{: | + | {{: |
* Now you should see your bot in your server. You might need to invite it to some channels manually. | * Now you should see your bot in your server. You might need to invite it to some channels manually. | ||
- | {{: | + | {{: |
===== Bot Setup - Host ===== | ===== Bot Setup - Host ===== | ||
- | In the bot folder should be an .env file. | + | In the bot folder should be an .env file. If there isn't, create it: |
- | If there isn't, create it: | + | |
< | < | ||
+ | |||
touch .env | touch .env | ||
Line 73: | Line 75: | ||
Open it in Nano text editor: | Open it in Nano text editor: | ||
- | < | + | < |
+ | nano .env | ||
</ | </ | ||
Line 79: | Line 82: | ||
The file should contain the following content (DO NOT USE CTRL+V in nano, type it manually): | The file should contain the following content (DO NOT USE CTRL+V in nano, type it manually): | ||
- | < | + | < |
+ | DISCORD_BOT_TOKEN= | ||
</ | </ | ||
Line 85: | Line 89: | ||
Now add the token you generated in a previous section on this line, so it looks like the following example: | Now add the token you generated in a previous section on this line, so it looks like the following example: | ||
- | < | + | < |
+ | DISCORD_BOT_TOKEN=MTAxMjYzMjA3NzM2RESTOFTHETOKEN | ||
</ | </ | ||
- | Press Ctrl+O and Enter to save changes and Ctrl+X to exit Nano. \\ | + | Press Ctrl+O and Enter to save changes and Ctrl+X to exit Nano. |
===== Installation ===== | ===== Installation ===== | ||
- | Enter the bot folder | + | Enter the bot folder |
- | Now install dependencies for the bot: | + | |
+ | < | ||
+ | cd / | ||
- | < | + | </ |
- | You will most likely get a message talking about vulnerabilities. | + | Now install dependencies for the bot: |
- | You can fix that with: | + | |
- | < | + | Fedora/ |
+ | < | ||
+ | |||
+ | Debian/ | ||
+ | < | ||
+ | |||
+ | Install NPM dependencies | ||
+ | < | ||
+ | npm install | ||
+ | </ | ||
+ | |||
+ | You will most likely get a message talking about vulnerabilities. You can fix that with: | ||
+ | |||
+ | < | ||
+ | npm audit fix | ||
npm fund | npm fund | ||
</ | </ | ||
+ | Install dotenv | ||
+ | < | ||
Now run the bot with: | Now run the bot with: | ||
- | < | + | < |
+ | npm start | ||
</ | </ | ||
Line 115: | Line 137: | ||
If you get the following error, it probably means your bot token is incorrect: | If you get the following error, it probably means your bot token is incorrect: | ||
- | < | + | < |
+ | (node: | ||
at / | at / | ||
at processTicksAndRejections (internal/ | at processTicksAndRejections (internal/ | ||
Line 122: | Line 145: | ||
</ | </ | ||
- | Check your .env file and make sure the correct token is in the file. \\ \\ **Now you should see your bot online in your server and ready to send messages!** | + | Check your .env file and make sure the correct token is in the file. \\ \\ **Now you should see your bot online in your server and ready to send messages!** \\ {{: |
===== Messages.json ===== | ===== Messages.json ===== | ||
Line 128: | Line 151: | ||
In the bot folder is a file messages.json. The bot takes messages from this file and prints them into a Discord message. These messages can be edited while the bot is running. \\ \\ Copy the following template to your messages.json: | In the bot folder is a file messages.json. The bot takes messages from this file and prints them into a Discord message. These messages can be edited while the bot is running. \\ \\ Copy the following template to your messages.json: | ||
- | < | + | < |
+ | { | ||
" | " | ||
" | " | ||
Line 135: | Line 159: | ||
</ | </ | ||
- | The number on the first line is the channel ID. You can get it by activating developer mode in the Discord Client, right clicking on a channel and selecting Copy ID. \\ You can find that toggle in Discord Settings - Advanced - Developer Mode | + | The number on the first line is the channel ID. You can get it by activating developer mode in the Discord Client, right clicking on a channel and selecting Copy ID. \\ You can find that toggle in Discord Settings - Advanced - Developer Mode |
After the channel ID comes the text. This can have basic formatting like bold and code block: | After the channel ID comes the text. This can have basic formatting like bold and code block: | ||
- | < | + | < |
+ | { | ||
" | " | ||
" | " | ||
Line 146: | Line 171: | ||
</ | </ | ||
- | {{: | + | {{: |
- | < | + | < |
+ | { | ||
" | " | ||
" | " | ||
Line 159: | Line 185: | ||
Do not add , to the very last line, that won't work. | Do not add , to the very last line, that won't work. | ||
- | ===== Run stickybot in the background ===== | + | ===== Run stickybot in the background |
- | Unless you want to keep the SSH connection active all the time to keep the bot running you will need to run it in the background. To do that we will use a Linux terminal application called [[https:// | + | Unless you want to keep the SSH connection active all the time to keep the bot running you will need to run it in the background. To do that we will use a Linux terminal application called [[https:// |
+ | \\ | ||
+ | To install it run: | ||
< | < | ||
+ | |||
sudo apt install screen | sudo apt install screen | ||
Line 169: | Line 198: | ||
Then create a session with: | Then create a session with: | ||
- | < | + | < |
+ | screen -S stickybot | ||
</ | </ | ||
Line 175: | Line 205: | ||
Now you are in a Screen session. Now you can start the bot: | Now you are in a Screen session. Now you can start the bot: | ||
- | < | + | < |
+ | npm start | ||
</ | </ | ||
- | To properly exit it press CTRL+A and then D. | + | To properly exit it press CTRL+A and then D. To get back into the session (or Attach it) use: |
- | To get back into the session (or Attach it) use: | + | |
- | < | + | < |
+ | screen -r session-name | ||
</ | </ | ||
Line 190: | Line 221: | ||
Create a session: | Create a session: | ||
- | < | + | < |
+ | screen -S stickybot | ||
</ | </ | ||
Line 196: | Line 228: | ||
List all sessions: | List all sessions: | ||
- | < | + | < |
+ | screen -ls | ||
</ | </ | ||
Line 202: | Line 235: | ||
Kill a particular session : | Kill a particular session : | ||
- | < | + | < |
+ | screen -XS sessionid/ | ||
</ | </ | ||
Line 208: | Line 242: | ||
Kill all Screen sessions: | Kill all Screen sessions: | ||
- | < | + | < |
+ | pkill screen | ||
</ | </ | ||
===== Running Stickybot as a systemd service ===== | ===== Running Stickybot as a systemd service ===== | ||
- | [[: | + | |
+ | [[: | ||
— // | — // | ||