Skeleton for a discord.js v13 bot written in TS with Slash Command support.

Overview

Discord.js v13 Bot Skeleton/Core

This repository is a template for creating a Discord bot using Discord.js v13 with Slash Command support.

This project is for people familiar with TypeScript and Discord.js. Do NOT use if you are unfamiliar with either. No Discord.js/TypeScript support will be given!


Table of Contents

  1. Create a project
    1. With GitHub
    2. Without GitHub
      1. Using Git CLI
      2. By Downloading
  2. Creating Slash Commands
  3. Deploying/Registering Slash Commands
  4. Creating Events
  5. Access the Client object
  6. Utils
    1. Logging
    2. Embeds
    3. Config
  7. Config File

Creating a project with github.

If you plan on using github in your project, simply click the Use this template button to get started.

Creating a project without github.

Choose one of the following:

Clone the repository using the Git CLI

  1. Open a terminal in the folder you want to create the project in and run git clone https://github.com/ItzDerock/discord.js-typescript-bot-core.git .

Clone the repository without Git

  1. Click the Code ▼ button on the top of this page and choose Download ZIP
  2. Open the zip archive using whatever you want (Windows File Explorer, Winrar, 7z, etc).
  3. Drag and drop all the files in discord.js-typescript-bot-core-main folder into your project root.

Creating slash commands.

To create a slash command using this package, go into ./src/commands/ Copy and paste the example.ts file.

Changing the command name/description.

  1. Change super("example", "An example command.");. The first argument is the command name, and the second is a command description.
  2. A third optional paramemeter can be supplied with the following options:
Key Description Default
requiredPermissions An array of PermissionResolvables that contains the required permissions to use this command undefined

Adding command options.

  1. Add a function to the class called build that takes in one argument (client) and returns either SlashCommandBuilder from @discordjs/builders or RESTPostAPIApplicationCommandsJSONBody from discord-api-types.

Example command with a boolean and string option.

import SlashCommand from "../structures/Command";
import { Client, CommandInteraction } from "discord.js";
import { primaryEmbed } from "../utils/embeds";
import { SlashCommandBuilder } from "@discordjs/builders";
import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types";

export default class ExampleCommand extends SlashCommand {
    constructor() {
        super("example", "An example command.");
    }

    exec(interaction: CommandInteraction) {
        const boolean = interaction.options.getBoolean('boolean');
        const string = interaction.options.getString('string');

        interaction.reply({
            embeds: [
                primaryEmbed('', `boolean: ${boolean}\nstring: ${string}`)
            ]
        });
    }

    build(client: Client<boolean>): SlashCommandBuilder | RESTPostAPIApplicationCommandsJSONBody {
        return new SlashCommandBuilder()
            .addBooleanOption(boolean => boolean.setName('boolean').setDescription('test boolean option').setRequired(true))
            .addStringOption(string => string.setName('string').setDescription('test string option').setRequired(true))
            .toJSON();

    }
}

Register slash commands.

When you create a slash command, the bot will not automatically create it.

To deploy all new slash commands, run npm start deploy or node . deploy (if built and you are in ./dist)

To deploy only certain commands, or to edit existing commands, run npm start edit [command 1 name] [command 2 name] [...].

Register events.

To register an event,

  1. Create an .ts file in ./src/events. You can look at ready.ts or commands.ts for a base.
  2. Export a class that extends Event found in ./src/structures/Event.ts.
  3. In the constructor() run super("Event friendly name (for logging)", "eventName in client.on") (for example, super("Slash commands", "interactionCreate"))
  4. Create a function exec that takes the arguments provided by the event.

Example Event:

import { GuildMember } from 'discord.js';
import Event from '../structures/Event';
import { primaryEmbed } from '../utils/embeds';

export default class ReadyEvent extends Event {
    constructor() { super('Member Welcomes', 'guildMemberAdd'); };

    async exec(member: GuildMember) {
        const welcome = member.guild.channels.resolve('a cool channel');
        if(!welcome || !welcome.isText()) return;
        welcome.send({
            embeds: [
                primaryEmbed("New Member!", `Welcome <@${member.id}> to ${member.guild.name}!`)
            ]
        })
    }
}

Accessing the Client

Simply import ./src/index.ts. Client is not the default export, so you will need to extract the client property. (ex: import { client } from "..";).

Util functions

Logging (./src/utils/logger.ts)

Exports a createLogger function that allows you to create a logger named the first parameter.

Logs are saved in ./logs/ and each unique logger name has their own file. The logger is a combination of bunyan and bunyan-format.

To disable logging, set the NO_LOG_DIR env var to something that is not null/falsy

Embed Utils (./src/utils/embeds.ts)

Exports primaryEmbed and errorEmbed functions to quickly create an embed that matches the color scheme used in other embeds. Functions take in two parameters: title, description.

Config Loader (./src/utils/config.ts)

This bot uses a yml config type, and node.js does not support importing .yml files. To access the config, run the default exported function from ./src/utils/config.ts

In this file you can also change the type definition for the config.

Config

The config is a yml file that will be loaded from the current working directory.

Inside the config, you set your bot token with the token option.

You can also change the global embed style under embeds.primary and embeds.error. You can set stuff like footer.text to set a global footer.

You might also like...

SlashCommands-Bot - An advanced discord bot, with Slash Commands !

SlashCommands Bot Github post is a discord bot handler with slashcommands in v13 How to install ? You need to have Node.JS 16+ git clone https://githu

Nov 16, 2022

Skeleton of a discord.js bot

BotSkelet Skelet of a discord.js bot Tired of making the whole "base" of your discord bot? Never been easier! The following versions was used to test

Aug 23, 2022

A skeleton JS discord bot.

Discord-Bot-Skeleton A skeleton JS discord bot. PLEASE NOTE THIS IS A WIP If you need any questions answered or have issues with this bot go ahead and

Aug 15, 2022

v13 butonlu + mongodb'li register botudur. Sadece Merakımdan V13 uğraştım, devamı geleceğini düşünmüyorum. İstek üzerine yapılmıştır

v13 butonlu + mongodb'li register botudur. Sadece Merakımdan V13 uğraştım, devamı geleceğini düşünmüyorum. İstek üzerine yapılmıştır

Testleri yapılmıştır. Hiçbir hatası bulunmamaktadır. Starlarınızı bekliyorum. Yapmanız gereken adımlar settings.json dosyasının içindeki idleri doldur

Dec 20, 2022

🟢 OneForAll Support Bot - Is a support bot for the discord server of OFA!

🟢 OneForAll Support Bot - Is a support bot for the discord server of OFA! Setup You can setup OneForAll Support Bot by simply opening your terminal/c

Oct 15, 2022

OptiBOT - My discord.js V13 discord bot.

OptiBOT Just a discord.js v13 bot for my discord server. if you plan to use this bot for your server, dont. This i made this bot just for learning js

Jan 3, 2022

Discord.js bot v13. Russian bot

Nutella-bot Discord.js bot v13. Russian bot Бот создан в России, он набирал популярность среди многих серверов. Завоевал 42 тысячи пользователей, и бы

Jun 5, 2022

Discord-Bot - You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have published on my youtube channel.

Discord-Bot You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have publishe

Jan 3, 2023

Yet another advanced djs slash command handler made by dano with ❤️

Yet another advanced djs slash command handler made by dano with ❤️

Advanced djs slash command handler Yet another advanced djs slash command handler made by dano with ❤️ Ultimate, Efficient, Slash command handler for

Nov 7, 2022
Owner
Derock
Node.js backend developer that does a lot of discord bot work.
Derock
Erela.js & Discord.js@v13 (SLASH COMMAND!)

?? READ THIS NEED USE WITH PREFIX? HERE: >> NanoSpace ?? Short Feature Music System Playlists System Premium System Setup Request System Multi Languag

Nanotect. 44 Jan 1, 2023
JavaScript / TypeScript templates for Discord.js v13, Slash Commands only!

discord.js-v13-template Slash Command Template Command Handler Events Handler Commands Example JavaScript Template TypeScript Template I will be const

null 10 Nov 15, 2022
Discord.js V13 Slash Commands, Events , Button Handler

Discord-js-v13-handler An advanced discord.js v13 command/events handler. Environment Variables To run this project, you will need to add the followin

Chethan Yadav 14 Oct 14, 2022
Discord.js Music Bot with buttons and slash support!

Music Bot Vote for us! (Please) How to use? Download the repo, create a .env file, and add your token into it. You need to change guildOnly to your gu

Garlic Team 59 Nov 24, 2022
About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this command handler.

discordJS-V14 About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this

Umut Bayraktar 36 Dec 28, 2022
An Easy to use and advanced working multiguild Waitingroom Bot written in discord.js v13 without any extra modules.

Multiguild-Waitingroom-v13 An Easy to use and advanced working multiguild Waitingroom Bot written in discord.js v13 without any extra modules. It is m

Tomato6966 17 Dec 11, 2022
Easy-to-use , actively maintained discord bot written in dJS V13 with customizable features

Multi-purpose discord bot Found a bug? Notes There are some modules missing, you can still start the bot but there are some things within the source t

locus 7 Nov 28, 2022
Discord.js V14 Slash-Command and Context-Menu Handler. Most efficient and advanced Handler out there!

Base discord.js v14 Command Handler Written by Tomato6966 Made for Deezcord Features ✔ Slash Commands ✔ Sub-Slash Commands ✔ Group-Sub-Slash Commands

Tomato6966 9 Dec 21, 2022
V13 kullanılarak yapılmış slash destekli guard botu. Basit bir şekilde yapılıp geliştirmesi size bırakılmıştır.

V13 Slash Guard V13 kullanılarak yapılmış slash destekli guard botu. Basit bir şekilde yapılıp geliştirmesi size bırakılmıştır. Config dosyasını doldu

Aris Lesnar 29 Dec 10, 2022
Um bot discord usando Discord.js v14 (slash commands)

ANTES DE TUDO LEMBRE-SE: COPIAR CÓDIGOS NÃO É PROGRAMAR! USE APENAS PARA FINS EDUCATIVOS E QUE APRENDA COM ESSE REPOSITÓRIO!!! Descrição Fiz esse repo

Yurii 8 Dec 20, 2022