Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Self hosting

xVaql edited this page May 5, 2019 · 32 revisions

This section will explain you how to host the bot yourself.

Table of Contents

Disclaimer

Be aware that you will need some experience with MySQL and your provided hosting operating system to be able to complete this process. You are responsible for any security issues or data leaks and you are not allowed to abuse the users logging time in any way. I am only providing you the code to log users' playtime, you are responsible for the data and privacy of your users. You are also not allowed to make this bot public or uploading my bot to any Discord bots spreading website. It is meant for private use only, if you would like to manage your own data.

Downloading

  1. If not already installed, install Git on your computer
  2. Open your (git) command line, and enter the directory you would like to install the bot in (most commonly using cd (folder name))
  3. Run the command git clone https://github.com/xVaql/TimePlayed.git
Now you've downloaded the bot code. You will however need a few more dependencies to get the bot started.

Downloading dependencies

  1. If not already installed, install Node.JS on your computer
  2. Open the command line and enter the directory the bot is installed in (dir should be named TimePlayed) and run the following command: npm install discord.js mysql fast-levenshtein
That's it for installing the dependencies. Now you'll have to create keys.json.

Creating keys.json

  1. Open your file explorer and enter the directory the bot is installed in
  2. Create a file named keys.json
  3. Edit the file using your favorite text editor
  4. Copy and paste the following text into your file:
    
    {
        "beta": false,
        "selfHost": true,
        "botToken": "(bot-token)",
        "mysqlhost": "localhost",
        "mysqlpasswd": "(database-password)",
        "mysqlusername": "root"
    }
    
  5. Go to Discord Developers, log in to your Discord account and create a new app
  6. In the app, go to the bot page and create a bot user for your application
  7. Uncheck the Public Bot option (self hosting is meant for private use only, you may not host the bot publicly)
  8. At the bot page, click on Click to Reveal Token and copy the token
  9. In keys.json, replace (bot-token) with your bot's token
That's it for now, the replacement of the variables will be explained later.

Setting up your database

  1. If not already installed, install MySQL on your computer (if on Linux, you can run sudo apt-get install mysql-server to install MySQL)
  2. Follow the setup process, make sure to choose a strong password, most of the default settings will be fine
  3. Make sure the database is running, if the command in step 4 doesn't work run sudo service mysqld start or sudo /etc/init.d/mysql start.
  4. Open the MySQL command line using mysql -u root -p, and enter the root password of your database you just set.
  5. Run the following command: CREATE DATABASE timeplayed;
    Make sure to add the semicolon at the end of the command, otherwise the command won't run
  6. Close the MySQL command line (by pressing CTRL + C or by running exit), enter the TimePlayed directory, and run the following command: mysqldump -u root -p timeplayed < structure.sql and enter your root password you have set while setting up MySQL
  7. Go back to editing your keys.json and replace (database-password) with the root password of your MySQL database
That's it for setting up the database, now you can start and invite your bot

Starting/Inviting the bot

  1. Go to the command line and enter the bot's directory
  2. Run the following command to start the bot: node bot.js. This is your startup script, whenever you restart your computer you will have to run this command again to start the bot
  3. Now we're going to invite the bot
  4. Go back to Discord Developers, click on your app and copy your bot's client ID
  5. Replace (CLIENT_ID) with the ID you just copied in the following link: https://discordapp.com/oauth2/authorize?client_id=(CLIENT_ID)&scope=bot&permissions=268708928
  6. Copy and paste the link into your browser and invite your bot

That should be it! If everything went right, you should now be able to run TimePlayed commands in your server, and enjoy premium features. If you experienced any trouble during this tuturial, please let me know in my support server and I will help you whenever I can.