Manual Install Guide Contribute Questions Support it on Patreon
In partnership with: discords.com
+ Invite

TriviaBot is open-source and can be downloaded for free. This guide shows you how to install TriviaBot on a Windows or Linux system. Note that installing TriviaBot using this method is completely optional for most cases. For general use, you can simply invite TriviaBot to your server directly.

If you enjoy using TriviaBot as a free and open source application, please consider supporting it on patreon.

Star

Download TriviaBot for Windows Download TriviaBot for Linux

Table of Contents

1. How to Install - Windows
1.1: Creating the bot account
1.2: Setting up the bot
1.3: Run the bot!
2. How to Install - Linux
2.0.1: Raspberry Pi/Raspbian OS
2.1: Creating the bot account
2.2: Setting up the bot
2.3: Run the bot!
3. Usage Instructions
3.1: Configuration
3.1.1: Game Configuration
3.1.2: Global Configuration
3.1.3: Maintenance Configuration
3.1.4: Changing Configuration Using Commands
4. How to Set Up Custom Questions
4.1. Custom Question Limitations
4.2. Optional Configurations for Custom Questions
4.2.1: How to Add Additional Answer Info (Answer Extensions)
4.2.2: How to Add Images to Questions and Answers
5. How to Set Up TriviaBot as a Service on Linux
6. Common Console Messages
6.1: "Got slash command attempt while commands are disabled."

How to Install - Windows

Creating the bot account

  1. Log in to the Discord Developer Portal and click "New application". Name the bot anything you like and click Create. Copy or write down the application ID as you will need it for later.
  2. On the left hand side, click "Bot". Now click the "Add Bot" button to create your bot. Here you can set an avatar for your bot if desired.
  3. Under "Token" click the link that says "click to reveal". This is the password for your bot's account. You'll need this and the Client ID number later. Copy them both somewhere safe or keep the tab open.
  4. Paste the URL listed below into your browser and replace "CLIENT_ID" with your application ID number from earlier. Hit enter and select the desired Discord server. Once this is done, the bot will show up in your server!
https://discord.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot%20applications.commands

Setting up the bot

  1. Download the TriviaBot program and extract it somewhere on your system.
  2. Install Node.js (Current, not LTS) from this website.
  3. Once Node.js is finished installing, run install.bat in the bot's folder. This will automatically install the required modules for the bot.
  4. Right click the config.example.json file, click "rename", and rename this file to config.json.
  5. Right click your new config.json file and click "Edit", or open the file in your preferred text editor.
  6. Find "your_token_here" and replace it with the Discord token from earlier.

Run the bot!

Once you complete all of this, you will be able to run the bot by opening run.bat. If you've done all of this correctly, you will see the following in the terminal: TriviaBot connected to 1 Discord Server.

Note that if you close this terminal the bot will be disconnected. In Windows, the bot can be run in the background with no terminal by opening run_silent.vbs.

You may want to create a shortcut to run.bat or run_silent.vbs in your Startup folder:

C:\Users\[YOURNAME]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

How to Install - Linux

Raspberry Pi/Raspbian OS

TriviaBot can be run from a Raspberry Pi device by installing Node.js.

First, follow the Node.js install instructions found here under "Debian and Ubuntu based Linux distributions". Once this is done, you can proceed with the instructions below. You may need access to a desktop computer in order to create the bot account.

Creating the bot account

  1. Log in to the Discord Developer Portal and click "New application". Name the bot anything you like and click Create. Copy or write down the application ID as you will need it for later.
  2. On the left hand side, click "Bot". Now click the "Add Bot" button to create your bot. Here you can set an avatar for your bot if desired.
  3. Under "Token" click the link that says "click to reveal". This is the password for your bot's account. You'll need this and the Client ID number later. Copy them both somewhere safe or keep the tab open.
  4. Paste the URL listed below into your browser and replace "CLIENT_ID" with your application ID number from earlier. Hit enter and select the desired Discord server. Once this is done, the bot will show up in your server!
https://discord.com/oauth2/authorize?client_id=CLIENT_ID&scope=bot%20applications.commands

Setting up the bot

  1. Open a terminal on your system.
  2. (Skip this step if installing to a Raspberry Pi device.) Install the current version of Node.js and NPM (16.6 is required at minimum). Install build tools if instructed. How to install via package manager.
  3. Type curl -L http://lakeys.net/triviabot/dl/triviabot.tar.gz > triviabot.tar.gz to download the bot's files to an archive named triviabot.tar.gz.
  4. Type tar -xzf triviabot.tar.gz to extract the archive. This will create a directory named "TriviaBot". Navigate to the directory with cd TriviaBot.
  5. Type sudo chmod +x run.sh. This gives you permission to execute run.sh. (If this does not work, try chmod +x run.sh)
  6. Type npm install to install the required packages for the bot to run.
  7. Rename the config.example.json file to config.json.
  8. Open config.json in a text editor.
  9. Replace "your_token_here" with the Discord bot token from earlier.

Run the bot!

Once you complete all of this, you will be able to run the bot by executing run.sh (Navigate to the bot's directory and enter ./run.sh). If you've done all of this correctly, you will see the following: TriviaBot connected to 1 Discord Server.

Usage Instructions

Configuration

The bot can be configured by editing config.json. See below for documentation on the config options.

Game Configuration

Global Configuration

Maintenance Configuration

A lot of the options in this section are deprecated and/or unused. Here are the ones that are still in use:

Changing Configuration Using Commands

Setting the config-commands-enabled option to true enables the admin "trivia config" and "trivia reset" admin commands.

trivia config <option> <value> <channel (optional)>

The "trivia config" command can be used to change values in config. Values can be surrounded with quotes when necessary, for example to reset the prefix to "trivia " (trivia config prefix "trivia "). Options can be removed by typing "trivia config null".

Beware that this will change line spacing of the config file; it is recommended that you create a backup.

The "trivia reset" command restarts the bot to apply config changes. All options currently require a restart before they take effect.

Specifying a channel will cause the config to only take effect in that channel. Channel-based options are stored in Options/{channelid}_config.json in the bot's folder.

Setting Up Custom Questions

One of the perks of self-hosting TriviaBot is that you can add your own questions! Here's how:
  1. Open your config.json and look for "databaseURL". Replace https://opentdb.com with file://./Questions. You can use a different file path if desired.
  2. Enter the questions folder. Inside, you'll find a sample database. The sample database shows you how to format your questions and categories.
  3. In order to use these files, you will need to rename them to remove .example.. Rename categories.example.yml to categories.yml, questions_0.example.yml to questions_0.yml, etc.
  4. Open the categories.yml file in a text editor. Here, you can add, delete, and edit categories as needed. When creating a new category, make sure you have a matching file for it, named questions_ID.yml.
  5. Now edit the question files for your new categories. The included files, named "questions_0.yml", "questions_1.yml", and "questions_2.yml" all contain sample questions.
  6. Replace the example quetions as needed and, following the same format, add your own.
  7. If you want to have the questions from the Open Trivia Database along with your custom questions, enter the bot's config.json file and change "database-merge" to true.
  8. Now start the bot and test your questions! Typing "trivia help" and "trivia categories" will show you how many questions you have added.

Custom Question Limitations

Custom questions have a few restrictions:

Optional Configurations for Custom Questions

How to Add Additional Answer Info (Answer Extensions)

You can add an additional comment or clarification to your custom questions by adding the answer_extension field to your question. Any text you enter in this field will display with the answer at the end of round.

Your answer extensions can include links.

Example formatting for answer extensions:

# Category 0 - Science --- questions: - question: "Compared to Earth, what is the approximate force of gravity on the moon?"   difficulty: "medium"   correct_answer: "One sixth"   incorrect_answers:   - "One half"   - "One eighth"   - "The same"   answer_extension: "The force of gravity on the moon is 1.62 m/s². compared to Earth's 9.807 m/s²." - question: "Buzz Aldrin was the first man to step on the moon."   difficulty: "medium"   correct_answer: "False"   incorrect_answers:   - "True"   answer_extension: "Neil Armstrong became the first human to step on the moon on July 20, 1969."

How to Add Images to Questions and Answers

You can specify an image to display on either the question, answer, or both, using the corresponding fields: question_image and answer_image

Each image must be posted with a link. If an invalid link is specified, your image will not appear.

Example formatting for images:

# Category 0 - Science --- questions: - question: "Compared to Earth, what is the approximate force of gravity on the moon?"   difficulty: "medium"   correct_answer: "One sixth"   incorrect_answers:   - "One half"   - "One eighth"   - "The same"   question_image: "https://lakeys.net/triviabot/sample_images/moon.jpg"   answer_image: "https://lakeys.net/triviabot/sample_images/aldrin-descending-lm.jpg" - question: "Buzz Aldrin was the first man to step on the moon."   difficulty: "medium"   correct_answer: "False"   incorrect_answers:   - "True"   question_image: "https://lakeys.net/triviabot/sample_images/buzz-aldrin-and-the-us-flag-on-the-moon.jpg"   answer_image: "https://lakeys.net/triviabot/sample_images/armstrong-on-moon.jpg"

How to Set Up TriviaBot as a Service on Linux

Once you have the bot set up on linux, you may find it more convenient to run the bot as a service.

Before starting, make sure the bot is not already running.

  1. Create and open the file /etc/systemd/system/triviabot.service. Make sure to open it with sudo/admin permissions or the file will not be writable.
  2. Fill it with the following text, and replace the items in {brackets} with the relevant information below:
    [Service] ExecStart=/usr/bin/npm start WorkingDirectory={File Path} Restart=always StandardOutput=syslog StandardError=syslog SyslogIdentifier=triviabot User={Username} [Install] WantedBy=multi-user.target

    • {File Path} - The path to the directory that the bot is in. Example: `/home/{Username}/TriviaBot`
    • {Username} The name of the user the bot will run on. WARNING: To ensure security of your system, it is strongly recommended that you DO NOT use root.

  3. Save the file and use the command systemctl enable triviabot, then systemctl start triviabot. This will start the bot.
  4. Wait a few seconds, then type systemctl status triviabot to see if the bot started successfully. If an error displays, double-check to make sure that both the bot and the triviabot.service file are configured correctly. Be sure to type systemctl daemon-reload after making any corrections to triviabot.service.

You can now use the following commands to manage the bot: sytstemctl stop triviabot, sytstemctl start triviabot, sytstemctl restart triviabot, and sytstemctl status triviabot. Use sudo with these commands to avoid re-entering the password each time.

Common Console Messages

"Got slash command attempt while commands are disabled."

If slash commands were recently disabled, the commands may still be registered with Discord. This leaves commands that users see when typing '/', but can't actually be run. Try typing clearcommands and clearglobalcommands in the console to fix this.

Commands may not disappear right away when cleared depending on how long it takes Discord to process them.

When this happens, the command will not run and the user will receive the following message: "This bot is using text commands instead of slash commands. Try trivia help, etc. instead."