-
Notifications
You must be signed in to change notification settings - Fork 16
Installation
If you want to run the bot directly on your device:
- Node, For the latest version of the bot v16.9.0+ of Node is required, but I have confirmed the latest LTS versions (20.12.2 and 18.5.0) also work.
Otherwise, if you want to run the bot as a Docker container instead:
- Docker Desktop, while Docker Desktop is not strictly necessary to run the code as a container, it is the most straightforward method and the rest of this guide will assume you will have it
Go to Discord developer dashboard, login with your discord account, and create a new application
Most of the basic info you fill in there will only show up in the portal for your own administration, and doesn't really have to do with the working of the bot itself. After you've done that you can go to the Bot tab on the left and click 'Add Bot'. You can give it a name and a picture, which is how it will show up in Discord itself. More importantly under the name on the Bot tab, you'll find the token, copy that and save it somewhere where you can refer to it later.
NOTE: on this page you also need to enable Message Content Intent, underneath the Privileged Gateway Intents header. If this is not enabled the bot will not be able to function!
If you haven't downloaded the code from github yet, do so now. In the root of the project (on the same level as the 'bot.ts' file), create a new file with the filename 'auth.json'. Put the following into that file:
{ "token": "[YOUR TOKEN HERE]" }
Replace the [YOUR TOKEN HERE] with the token you copied from the discord developer dashboard and save the file.
Note: do not remove the "" around the token!
Go back to the Discord developer dashboard, go to the application you made, and click on the OAuth2 tab on the left. On that page, you'll want to check the box 'bot' under 'scopes' and 'Send messages' under 'bot permissions', and after clicking those you should see a url generated at the bottom of the 'scope' box. if you go to that url, you'll get redirected to a discord screen where you can invite your bot to a server you have the rights to.
This is where the guide splits up between running the code directly on your device, or using Docker Desktop.
Go to the root of your project in a commandline (same level where the 'bot.ts' file resides).
Run the command npm i
to install the dependencies for the project.
Then run the command npm run start
to compile the typescript (.ts) files to javascript (.js) files, and the bot will start running immediately!
Alternatively, you can run the command npm run build
to only compile the files and not start running yet.
Both of these commands will put the compiled files in the /build directory under the project root.
Make sure Docker Desktop is running, and open a commandline in the root of your project (same level where the 'bot.ts' file resides).
Run the command docker compose up
to start building the Docker container running the bot.
The container (and image) should now show up in the Docker Desktop application, with a name like mtg-spoilers-discord-bot-mtgbot, and the bot should automatically be running!
NOTE: You can stop, pause and start the bot's container (or the entirety of Docker Engine) from the Docker Desktop application if necessary.
From now on, whenever Docker Desktop is started, it will automatically restart the bot's container as well; if you want to stop this from happening, you can open another commandline in the root of the project, and run the command docker compose down
, removing the container from the Docker Engine, but the image will still be there if you want to start/stop the container manually.
You can use the '!ping' command in your Discord server to check if the bot is running correctly, if it responds it's working correctly. Make sure the channel you're typing commands in is visible to the bot, you can double check in Discord this by making sure it shows up on the user list to the right, if not you might need to adjust some roles on your server!