laptopwiki:guides:discord:stickybot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
laptopwiki:guides:discord:stickybot [30/12/2022 08:18] dustojnikhummerlaptopwiki:guides:discord:stickybot [14/01/2023 15:13] (current) – [Running Stickybot as a systemd service] dustojnikhummer
Line 1: Line 1:
 ====== Stickybot ====== ====== Stickybot ======
 +
 Stickybot, sometimes known as Imaginifer, is the bot we use to send automatic announcement messages that are always at the bottom of a channel.\\ Stickybot, sometimes known as Imaginifer, is the bot we use to send automatic announcement messages that are always at the bottom of a channel.\\
-{{:laptopwiki:guides:discord:stickybot_example.png?600|}}+{{:laptopwiki:guides:discord:stickybot_example.png?700}}\\
 Built by: [[https://discord.gg/HSdMQtaPEa|Spooker#0378]]\\ Built by: [[https://discord.gg/HSdMQtaPEa|Spooker#0378]]\\
 If you have any issues with this guide or feedback please contact [[https://discord.gg/HSdMQtaPEa|dustojnikhummerCZ#6262]] \\ If you have any issues with this guide or feedback please contact [[https://discord.gg/HSdMQtaPEa|dustojnikhummerCZ#6262]] \\
 \\ \\
 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.
 +
 ===== Requirements ===== ===== Requirements =====
-  * A Linux webhost (in the case of this guide Debian/Ubuntu Server)\\ + 
-  * npm\\ +  * A Linux webhost (in the case of this guide Debian/Ubuntu Server) \\ 
-  * nodejs \\ +  * npm (sudo apt install npm)\\ 
-  * wget \\  +  * npm dotenv (npm install dotenv) \\ 
-  * unzip \\ +  * nodejs  \\ 
-  * Discord developer account\\+  * wget  \\ 
 +  * unzip  \\ 
 +  * 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://cdn.laptopwiki.eu/internal/bots/sticky-message.zip|CDN]]\\+ 
 +Download here: [[https://cdn.laptopwiki.eu/public/bots/stickybot.zip|CDN]] \\
  
 Unzip the archive and copy its contents to your Linux server. Unzip the archive and copy its contents to your Linux server.
 Alternatively, run: Alternatively, run:
-<code>wget https://cdn.laptopwiki.eu/internal/bots/sticky-message.zip </code>+<code> 
 +wget https://cdn.laptopwiki.eu/internal/bots/sticky-message.zip 
 + 
 +</code> 
 Then unzip the archive with: Then unzip the archive with:
-<code>unzip ./sticky-message.zip -d ./sticky-message</code> + 
-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's mv ./* does not move files hidden files (file starting with a .) and you might forget your .env file (which is very important).\\ +<code>unzip ./sticky-message.zip -d ./sticky-message 
-\\ + 
-For example, you can move/rename the folder with the following command: +</code> 
-<code>mv ./sticky-message ./imaginifer</code>+ 
 +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's mv ./* does not move files hidden files (file starting with a .) and you might forget your .env file (which is very important). \\  \\ For example, you can move/rename the folder with the following command: 
 + 
 +<code>mv ./sticky-message ./imaginifer 
 + 
 +</code>
  
 ===== Bot Setup - Discord ===== ===== Bot Setup - Discord =====
-  - Open the [[https://discord.com/developers/applications|Discord Developer Portal]]\\ + 
-  - In the top right create a New Application and give it a name. \\ +  - Open the [[https://discord.com/developers/applications|Discord Developer Portal]] \\ 
-  - In the left panel select the Bot section. On the right click Add Bot. \\ +  - In the top right create a New Application and give it a name.  \\ 
-  - 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 the Bot section. On the right click Add Bot.  \\ 
-  - In the left panel select OAuth2-URL Generator and select the bot scope. Below that a permission list will appear.\\ +  - Click the Reset Token button. Copy that token and do not lose it. Also make sure nobody else has that token.  \\ 
-  - Select the permissions you want. Read Message History, Manage Messages, Send Messages at least. Add more if you want. \\ +  - In the left panel select OAuth2-URL Generator and select the bot scope. Below that a permission list will appear. \\ 
-{{media:public:bots:stickybot:stickybot_setup_scopes.png +  - Select the permissions you want. Read Message History, Manage Messages, Send Messages at least. Add more if you want.  \\ 
-?200|}}\\ + 
-  * 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.\\ +{{:laptopwiki:guides:discord:stickybot_setup_scopes.png?300}} 
-{{media:public:bots:stickybot:stickybot_server_invite.png + 
-?200|}}\\+  * 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. \\ 
 + 
 +{{:laptopwiki:guides:discord:stickybot_server_invite.png?200}} \\ 
   * 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.
-{{media:public:bots:stickybot:stickybot_bot_offline.png?200|}}\\+ 
 +{{:laptopwiki:guides:discord:stickybot_bot_offline.png?200}} \\
  
 ===== 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:
 <code> <code>
 touch .env touch .env
 +
 </code> </code>
 +
 Open it in Nano text editor: Open it in Nano text editor:
-<code> + 
-nano .env+<code>nano .env 
 </code> </code>
 +
 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):
-<code>DISCORD_BOT_TOKEN=</code>+ 
 +<code>DISCORD_BOT_TOKEN= 
 + 
 +</code> 
 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:
-<code>DISCORD_BOT_TOKEN=MTAxMjYzMjA3NzM2RESTOFTHETOKEN</code> 
-Press Ctrl+O and Enter to save changes and Ctrl+X to exit Nano. \\ 
  
 +<code>DISCORD_BOT_TOKEN=MTAxMjYzMjA3NzM2RESTOFTHETOKEN
 +
 +</code>
 +
 +Press Ctrl+O and Enter to save changes and Ctrl+X to exit Nano.  \\
  
 ===== Installation ===== ===== Installation =====
-Now install dependencies for the bot:+ 
 +Enter the bot folder <code> cd /path/to/unpackaged/ </code> 
 +Now install dependencies for the bot:  
 + 
 <code>npm install</code> <code>npm install</code>
-You will most likely get a message talking about vulnerabilities. + 
 +You will most likely get a message talking about vulnerabilities.
 You can fix that with: You can fix that with:
 +
 <code>npm audit fix <code>npm audit fix
-npm fund</code>+npm fund 
 + 
 +</code> 
 Now run the bot with: Now run the bot with:
-<code>npm start</code>+ 
 +<code>npm start 
 + 
 +</code> 
 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:
-<code> + 
-(node:133979) UnhandledPromiseRejectionWarning: ReferenceError: c is not defined+<code>(node:133979) UnhandledPromiseRejectionWarning: ReferenceError: c is not defined
     at /path/to/stickybot/src/main.js:10:15     at /path/to/stickybot/src/main.js:10:15
     at processTicksAndRejections (internal/process/task_queues.js:97:5)     at processTicksAndRejections (internal/process/task_queues.js:97:5)
     at async  /path/to/stickybot/src/src/main.js:9:2     at async  /path/to/stickybot/src/src/main.js:9:2
 +
 </code> </code>
-Check your .env file and make sure the correct token is in the file.\\ + 
-\\ +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!**   \\ {{:laptopwiki:guides:discord:stickybot_bot_online.png?200}} 
-**Now you should see your bot online in your server and ready to send messages!** \\ +
-{{media:public:bots:stickybot:stickybot_bot_online.png?200|}}+
 ===== Messages.json ===== ===== 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.\\ + 
-\\ +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: 
-Copy the following template to your messages.json: + 
-<code> +<code>{
-{+
     "928291939244195882": "This is a text field",     "928291939244195882": "This is a text field",
     "comment": "Test channel"     "comment": "Test channel"
 } }
 +
 </code> </code>
-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:
-<code> + 
-+<code>
-    "928291939244195882": "```This is a text field```",+    "928291939244195882": "`This is a text field`",
     "comment": "Test channel"     "comment": "Test channel"
 } }
-</code> {{media:public:bots:stickybot:stickybot_codeblock.png?200|}} \\ + 
-\\ +</code> 
-The comment line is just for you to say what channel belongs that message to. \\ + 
-\\ +{{:laptopwiki:guides:discord:stickybot_codeblock.png?200}} \\  \\ The comment line is just for you to say what channel belongs that message to.  \\  \\ If you want to add another message to a different channel just replicate this syntax, but add a , at the end of a line: 
-If you want to add another message to a different channel just replicate this syntax, but add a , at the end of a line: + 
-<code> +<code>
-+    "928291939244195882": "`This is a text field`",
-    "928291939244195882": "```This is a text field```",+
     "comment": "Test channel",     "comment": "Test channel",
-    "928291939244195883": "```This is a text field 2```",+    "928291939244195883": "`This is a text field 2`",
     "comment": "Test channel 2"     "comment": "Test channel 2"
 } }
  
 </code> </code>
- 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://www.gnu.org/software/screen/|Screen]] \\ +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://www.gnu.org/software/screen/|Screen]]  \\   \\  To install it run:
-\\ +
-To install it run:+
 <code> <code>
 sudo apt install screen sudo apt install screen
 +
 </code> </code>
 +
 Then create a session with: Then create a session with:
-<code> + 
-screen -S stickybot+<code>screen -S stickybot 
 </code> </code>
 +
 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:
-<code> + 
-npm start+<code>npm start 
 </code> </code>
 +
 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:
-<code> + 
-screen -r session-name+<code>screen -r session-name 
 </code> </code>
 +
 === Basic GNU Screen commands === === Basic GNU Screen commands ===
 +
 Create a session: Create a session:
-<code> + 
-screen -S stickybot+<code>screen -S stickybot 
 </code> </code>
 +
 List all sessions: List all sessions:
-<code> + 
-screen -ls+<code>screen -ls 
 </code> </code>
 +
 Kill a particular session : Kill a particular session :
-<code> + 
-screen -XS sessionid/name quit+<code>screen -XS sessionid/name quit 
 </code> </code>
 +
 Kill all Screen sessions: Kill all Screen sessions:
-<code> + 
-pkill screen+<code>pkill screen 
 </code> </code>
  
-===== Running Stickybot as a systemd service===== +===== Running Stickybot as a systemd service ===== 
-Once I figure this out the guide will be +[[:laptopwiki:guides:os:linux:npmsystemdservice| Running "npm start" App As a Systemd Service]] 
 + 
 +— //[[:laptopwiki:staff:index|dustojnikhummer]] 2022/12/30 08:01//
  
-[[laptopwiki:guides:linux:npmsystemdservice|]] 
  
- --- //[[laptopwiki:staff:index|dustojnikhummer]] 2022/12/30 08:01// 
  • laptopwiki/guides/discord/stickybot.1672384680.txt.gz
  • Last modified: 30/12/2022 08:18
  • by dustojnikhummer