Giter Site home page Giter Site logo

discordjs-decorators's Introduction

DiscordJS Decorators

DiscordJS decorators for better structure

NPM NPM

Installation

  1. Install DiscordJS (not next version!)
    yarn add discord.js
  2. Install DiscordJS-Decorators
    yarn add @idkncc/discordjs-decorators
  3. Add to tsconfig.json
    "experimentalDecorators": true
  4. Ready to use

Simplest Example

// index.ts
import {EventLoader, importGlob} from "@idkncc/discordjs-decorators";
import {Client, Events} from "discord.js";

require("dotenv").config()

const client = new Client({intents: ["Guilds"]})

client.once(Events.ClientReady, c => {
	console.log(`Bot is ready! Logged in as ${c.user.tag}`)

	new EventLoader()
		// import whole folder
		.add(importGlob("./events/**/*.ts"))

		// constants for command registering
		.env(process.env.NODE_ENV !== "production", process.env.CLIENT_ID, process.env.GUILD_ID)

		// and finally load everything
		.load(client)
})


client.login(process.env.TOKEN)
// /events/event.ts
import {Events} from "discord.js"
import {Event} from "@idkncc/discordjs-decorators"

export class ExampleEventImportedOne {
	// regular event
	@Event(Events.MessageCreate)
	messageCreate(d) {
		console.log("Someone said")
	}

	// register slashcommand
	@SlashCommand.Name("warn")
	@SlashCommand.Description("Warns user")
	@SlashCommand.UserOption((opt) => opt
		.setName("user")
		.setDescription("User, who will get warned")
		.setRequired(true)
	)
	@SlashCommand.StringOption((opt) => opt
		.setName("reason")
		.setDescription("Reason to warn")
	)
	testCommand(test: ChatInputCommandInteraction) {
		// do smth
	}
}

Other example you can find in example/ folder

TODO

  • Validators (very useful but not now :( )
  • More decorators for @SlashCommand
  • Middlewares

discordjs-decorators's People

Contributors

mon4ik avatar

Stargazers

lonely avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.