Skip to content

My own implementation of discord.js v14 in TypeScript with additional extensions.

License

Notifications You must be signed in to change notification settings

hiraeeth/DiscordTS-Base

Repository files navigation

Discord v14 with TypeScript

My own implementation of discord.js v14 in TypeScript with additional extensions.

Features ✨ ‣

  • Command Handler
  • Event Handler
  • Route Handler (web-server)

Usage 📃 ‣

  • Edit .env.example with your unique data.
  • Install modules wtih npm install
  • Use one of the available commands:
npm run dev
npm run start
npm run build

Templates 🐱‍💻 ‣

  • Command

import { Client, CommandInteraction, SlashCommandBuilder } from "discord.js";

export const data = new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!");
export const cooldown = 5;
export const options = {
	command: {
		guild: ["*"],
	},
};

export const callback = async (client: Client, interaction: CommandInteraction) => {
	await interaction.reply("Pong!");
};
  • Event

import { Events, Client } from "discord.js";
import color from "@utils/colors";

export default {
	name: Events.ClientReady,
	once: true,
	callback: async function (client: Client, event: any) {
		console.log(`${color.fg.cyan}App ${color.reset}${color.fg.cyan}${event.user.username}${color.reset} is online.`);
	},
};
  • Route

import { Client } from "discord.js";
import { Request, Response } from "express";

const { GUILD_ID } = process.env;

export default {
	path: "/api/test",
	method: "GET",
	callback: async function (client: Client, req: Request, res: Response) {
		const guild = await client.guilds.fetch(String(GUILD_ID));
		const channel = await guild.channels.fetch(String("1253847724894457996"));

		if (channel && channel.isTextBased()) {
			await channel.send("Hello!");
			console.log(`Message sent to channel ${channel.name}`);
		} else {
			console.log("The specified channel is not a text channel.");
		}

		return res.json({
			message: `Message sent to channel: ${channel ? channel.name : "unknown"}`,
		});
	},
};

Extensions ➕ ‣

  • colors.ts (@utils/colors)

import color from "@utils/colors"
console.log(`${color.fg.red}Hello in red ${color.reset}.`);
  • logger.ts (@utils/logger)

import logger from "@utils/logger"
logger.log("...")
logger.warn("...")
logger.debug("...")
logger.error("...")