Running the bot locally - chicklightning/tcg-pocket-trading-bot GitHub Wiki

Now it's time for us to download code from our Node.js package dependencies, populate the database, and run our bot for the first time!

Install node_modules

This step downloads all the code we need to run the bot from our package dependencies.

  1. Navigate to the project's root directory in File Explorer
  2. Right-click somewhere inside the folder (not on a specific file or subfolder) and select "Open in Terminal"
  3. Type node -v and hit "Enter" in the Command terminal that appears to verify you've installed Node.js correctly
    • If you don't see something like v22.14.0, go back to the instructions for installing Node.js and make sure you've restarted your computer since installation
  4. Type npm install and hit "Enter"

Create database tables and scrape cards

Creating database tables will allow our code to write records to those tables for users and trades. Scraping the cards makes sure we have our database prepopulated with cards users can add to their lists to trade with.

  1. In the same terminal, type sequelize db:migrate and hit "Enter"
    • You should see the script create tables for "Cards", "Users", "Trades", and "UserCards"
    • If this step fails, go back to the instructions for setting up your Postgres database and make sure you've done the steps correctly, such as naming your database the correct name
  2. Type npm run get-cards and hit "Enter"

NOTE: When new cards become available to trade, the script will be updated and pushed to the repo. You'll need to fetch the latest changes from the repository and run this script again. This will clear all of the cards in your database and recreate the entries (to support a possible case in the future where certain sets are no longer tradeable). You can keep your bot running while you do this, and run this command in a new Command terminal without interrupting the bot.

Register bot commands

You now need to register the bot's slash commands with Discord. After running this script, it can take up to an hour for you to see your slash commands appear in servers where your bot is, or in private messages to your bot.

  1. In the same terminal, type npm run deploy-commands and hit "Enter"
    • You should see a message at the end like "[LOG] Successfully reloaded ## application (/) commands."
    • If this step fails, go back to the instructions for setting up your Discord environment variables to make sure your bot can connect to Discord servers properly

Run the bot

You're now ready to run the bot!

  1. In the same terminal, type npm run local and hit "Enter"
    • You should see some text, then a message at the end like "[LOG] Ready! Logged in as YOURBOTNAME."
  2. Keep this terminal open until you are ready to shut off the bot

You can shut off the bot by pressing Ctrl + C, then typing "y" to end the process, or it will shut off automatically when your computer shuts off.

Your bot is now ready to receive commands and respond to users. Congrats! 🎊 If this guide helped you and you're running your own bot instance, I'd love to know about it and hear how it's going.