New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ledis

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ledis

a decorator library on discord.js like discord.ts or nest.js

  • 1.0.3
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

ledis

a decorator library on discord.js like discord.ts or nest.js

Index

Introduction

it's just a simple with typescript decorators for increase developer experience with discord.js

Installation

npm i ledis

Usage

  import { 
    bootstrap,
    App,
    Client,
    Command,
    CommandError,
    CommandNotFound,
    Arg,
    ErrorArg,
    Once,
    DiscordClient
  } from 'ledis';

  const token = 'Your token';

  @App({
    prefix: '!',
  })
  class Application {
    @Once('ready')
    public readyHandler(@Client() client: DiscordClient) {
      console.log(`Logged in as ${client?.user?.tag}!`);
    }
    
    @Command('hi :id')
    public hi(@Arg('id') id: string){
     return `hi ${id}`;
    }

    @CommandError()
    public commandError(@ErrorArg() error: Error) {
      console.error(error);
    }

    @CommandNotFound()
    public commandNotFound() {
      return 'command not found!';
    }
  }

  const main = () => bootstrap(Application).login(token);

  main();

Api

Decorators

@App(ApplicationMeta)

Define class as root application

@App({
  prefix: string // prefix for commands
  imports: Class[] // classes with commands
})
class Application {}
@Command(pattern: string)

Define method as command handler

class Commands {
  @Command('hi :id')
  public hi(
    @Arg('id') id: string;
  ){
    return `hi ${id}!`;
  }
}
@ComandError()

Define method as command error handler

class Commands {
  @CommandError()
  public commandErrorHandler(
    @ErrorArg() error: Error
  ){
    console.log(error);
  }
}
@CommandNotFound()

Define method as command not found handelr

class Commands {
  @CommandNotFound()
  public commandNotFoundHandler(
    @Message() message: DiscordMessage
  ){
    console.log(message.content);
  }
}
@Gateway(handler: (context, next) => void)

Define gateway (middleware) for command handler

class Commands {
  @Gateway((context, next) => {
    if (context.message.content !== '!hi') return;
    next();
  })
  @Command('hi')
  public hi(){
    return 'hi!'
  }
}
@On(eventName: string)

Define on discord.js handler

class Commands {
  @On('message')
  public messageHandler(
    @Arguments() [message]: ArgumentsOf<"message">
  ){
    console.log(message);
  }
}
@Once(eventName: string)

Define Once discord.js handler

class Commands {
  @Once('ready')
  public readyHandler(
    @Client() client: DiscordClient
   ){
    console.log(`Logged in as ${client?.user?.tag}!`);
  }
}
@Arg(argName: string)

Define parameter as command argument

class Commands {
  @Command('hi :id')
  public hi(
    @Arg('id') id: string
  ){
    return `hi ${id}!`;
  }
}
@Arguments()

Define parameter as discord.js on/once handler arguments

class Commands {
  @On('message')
  public messageHandler(
    @Arguments() [message]: ArgumentsOf<"message">
  ){
    console.log(message);
  }
}
@Client()

Define parameter as discord.js client

class Commands {
  @Once('ready')
  public readyHandler(
    @Client() client: DiscordClient
   ){
    console.log(`Logged in as ${client?.user?.tag}!`);
  }
}
@ErrorArg()

Define parameter as command error

class Commands {
  @CommandError()
  public commandErrorHandler(
    @ErrorArg() error: Error
  ){
    console.log(error);
  }
}
@Message()

Define parameter as discord.js message

class Commands {
  @Command('hi :id')
  public hi(
    @Arg('id') id: string
    @Message() message: DiscordMessage
  ){
    message.reply(`hi ${id}!`);
  }
}

Bootstrap

bootstrap(App: Class, discordClientOptions?: DiscordClientOptions) => DiscordClient

Function for bootstrap your Application

const main = () => bootstrap(Application).login(token);

main();

Keywords

FAQs

Package last updated on 12 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc