Skip to content

A customizable Discord bot based on discord.js v14 with Typescript!

License

Notifications You must be signed in to change notification settings

IronBatman2715/DiscordTS-Bot

Repository files navigation

DiscordTS-Bot

A customizable Discord bot based on discord.js v14 with Typescript!


Setup

  1. Install the following software.
  1. Create your bot application on the Discord developer portal

    It is recommended to use separate discord bot applications for development and production. This is for security reasons and because it can be difficult to differentiate global commands from in development commands otherwise.

  2. Setup your database of choice.

    • MongoDB is the default. You can easily set up a free instance with MongoDB Atlas.

    • If you want to use a different database, see here for databases supported by Prisma. This will also require some changes to prisma/schema.prisma.

  3. Download this repository (clone/fork/raw download).

From here, follow the steps for your desired setup:

Development environment

  1. Rename sample.development.env to development.env and set the environment variables as defined in src/global.d.ts

    • DISCORD_TOKEN: Discord bot token (acquired in step 1).

    • DB_URL Database URL

    • CLIENT_ID Discord bot client ID (acquired in step 1).

    • TEST_GUILD_ID guild ID of the server you will use to test this bot.

      • Slash commands will immediately be updated for this server and this server only upon restarting the bot in developer mode.
    • DEV_IDS A list of developer discord user IDs (must set at least one)

      • IDs should be separated by ", ". Ex: DEV_IDS='DEV_ID1, DEV_ID2, DEV_ID3'.
  2. Run npm ci to do a clean install of dependencies and generate Prisma client files.

  3. Run npm run dev to start a developer environment instance!

    • Edit and save any of the files in the src directory (with the exception of prisma/schema.prisma) and the program will automatically restart to reflect the changes!

Production environment

  1. Rename sample.env to .env and set the environment variables as defined in src/global.d.ts

    • DISCORD_TOKEN: Discord bot token (acquired in step 1).

    • DB_URL Database URL

    • CLIENT_ID Discord bot client ID (acquired in step 1).

  2. Run npm ci to do a clean install of dependencies and generate Prisma client files.

  3. Run npm run build to compile the source code for production.

    • If you are tight on storage space, delete the node_modules folder after running npm run build. Then, run npm ci --production to install only the dependencies needed for production.
  4. Change the config.json file to your liking. See information about how you can change it here.

    This file is generated by the previous step.

  5. If this is the first time you have run the bot or you are updating the source code, run npm run commands:register to register all your commands to any and all servers this bot is in. You may need to run npm run commands:resetProd prior to npm run commands:register if some old commands are not being removed.

  6. Run npm start to run the bot!

  7. [Optional] Add PM2 or containerize with Docker. Then, deploy to a cloud service (Heroku, Linode, Vultr, etc.) or on your own hardware.

Configuration file properties

  • name: name of the bot (displayed in some commands).

  • activities: list of activities the bot will randomly cycle through as its current activity (Exs: "Watching The Fellowship of the Ring", "Listening to Never Gonna Give you Up", etc.).

    • type: integer that can only be one of the following values.

      0 = PLAYING

      1 = STREAMING

      2 = LISTENING

      3 = WATCHING

      4 = **NOT VALID, DO NOT USE**

      5 = COMPETING

    • name: string after the type.

References

I did not create the icons used. They are sourced from here under their license.