Skip to content

molo-7/djs-ts-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Djs Typescript Starter Code

latest version 14.0.3

Prerequisites

Node.js: Node.js 16.6.x or newer is required.

Events

Creating new event

create /events/ready.ts

// imports
import Client from "../libs/client";
import Event from "../structures/Event";
import { Events } from "discord.js";

export default class Ready implements Event {
  client: Client;
  name = Events.ClientReady; // event name
  once = true; // true if you want to handle this event once

  constructor(client: Client) {
    this.client = client;
  }

  // execution funtion
  execute = (...args: any[]) => {
    console.log(`🚀 ${this.client.user.tag} is online`);
  };
}

you can create event listeners as many as you want for a single event

And if you need you can define and use your custom events

example

import Client from "../libs/client";
import Event, { CustomEvents } from "../structures/Event";
import { TextChannel } from "discord.js";

export default class SongRequest implements Event {
  client: Client;
  name = CustomEvents.SongRequest;

  constructor(client: Client) {
    this.client = client;
  }

  execute = (songname: string, channel: TextChannel) => {
        channel.send(`new requested song: \`${songname}\` `)
    }
  };
}
export enum CustomEvents {
  SongRequest = "songRequest",
}

Slash Commands

Creating new command

create /commands/ping.ts

import Client from "../libs/client";
import Command from "../structures/Command";
import { CommandInteraction } from "discord.js";

export default class Ping extends Command {
  constructor(client: Client) {
    super();
    this.client = client;

    // command builder
    this.setName("ping").setDescription("tests bot's ping");
  }

  // execution funtion
  execute = (interaction: CommandInteraction) => interaction.reply("Pong");
}

use djs SlashCommandBuilder inside the constructor or just set properties directly to the class

example

export default class Ping extends Command {
  name = "ping";
  description = "tests bot's ping";

  constructor(client: Client) {
    super();
    this.client = client;
  }

  // execution funtion
  execute = (interaction: CommandInteraction) => interaction.reply("Pong");
}

create events and commands on any nesting level

.env

TOKEN=YOUR-DISCORD-BOT-TOKEN

About

discord.js bot with typescript template

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published