Skip to content

Maximus7474/discord-js-template

This branch is 58 commits ahead of FissionFeline/discord-js-template:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ea5a720 · Mar 22, 2025
Dec 18, 2024
Dec 18, 2024
Mar 20, 2025
Sep 10, 2024
Jul 24, 2024
Dec 18, 2024
Mar 22, 2025
Sep 10, 2024
Mar 20, 2025

Repository files navigation

discord-js-template

Feature List & Documentation 1. SQLite Database handler (located in `./src/utils/database/`): - `executeStatement(sqlquery: string, params?: string[]): Promise` - execute an update query or an insert query - `executeTransaction({sqlquery: string, params?: string[]}[]): Promise` - execute multiple statements either update or insert - `executeQuery(sqlquery: string, params?: string[], action?: "get"|"all"): Promise` - execute a query to return one entry or all entries, will default to using `"get"` if not specified. - `"get"` will return a single line that satisfies the query and parameters - `"all"` will return all lines that satisfy the query and parameters
  1. Application commands (located in ./src/commands/):

    • You can set the command to be restricted to the main guild, requires that the MAIN_GUILD field be set in the .env
    • To define a new command you only need to create a new file, it's export has to be the following structure:
    guildOnly: boolean,
    // from discord.js
    register_command: SlashCommandBuilder,
    // Client & ChatInputCommandInteraction from discord.js
    execute: async function (client: Client, interaction: ChatInputCommandInteraction): void
  2. Event handlers (located in ./src/events/):

    • To define a new event handler you only need to create a new file, it's export has to be the following structure:
    // from discord.js
    event: Events enum,
    type: "once"|"on",
    // Client from discord.js, ... args relating to the event check discord.js documentation
    call: async function (client: Client, ...): void
  3. Static Message handler (located in ./src/staticMessages/):

    • To define a new static message you only need to create a new file, it's export has to be the following structure:
    customId: string[],
    // Client from discord.js
    setup: async function (client: Client) {},
    // Client & CommandInteraction from discord.js
    callback: async function (client: Client, interaction: CommandInteraction): void

Setup

Copy the .env.example file to .env

cp .env.example .env

Open it with your favorite editor, Nano, Vim or Emacs.

Replace the TOKEN in the .env file with your own Authentication Token given to you by Discord in their portal Replace the MAIN_GUIlD in the .env file with the discord ID of your main discord guild

Once your discord bot is generated and the token inserted, you will need to run the deployment command so that the slashcommands are all registered to Discords API. This is done via npm or pnpm depending on your prefference, running the deploy script:

npm run deploy
pnpm run deploy

DO NOT MAKE THE .env FILE PUBLIC

By default, .env is git ignored (meaning it is ignored by git). If you disable this, there can be huge security risks such as

  • Hackers being able to use your authentication token and using it for malicious purposes
  • Bad in general

If you do not touch the .gitignore then you should be fine. But be sure not to remove the .env part from the .gitignore.

Create new functions

When specifying a main guild in the .env (by using it's Discord ID) this give you the possibility of creating commands restricted to that one. To do so, make sure that the exported object that it contains the guildOnly key and set to true. If the key isn't set it'll default to a global command, if the MAIN_GUILD key isn't set in the .env it won't register them.

About

A discord js template that I use

Resources

Stars

Watchers

Forks

Languages

  • JavaScript 100.0%