trueharuu / handler

A complete, customizable, typesafe, & reactive framework for discord bots

Home Page:https://sern.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handlers. Redefined.

A complete, customizable, typesafe, & reactive framework for discord bots

NPM version NPM downloads License MIT docs.rs Lines of code

Why?

  • For you. A framework that's tailored to your exact needs.
  • Lightweight. Does a lot while being small.
  • Latest features. Support for discord.js v14 and all of its interactions.
  • Hybrid, customizable and composable commands. Create them just how you like.
  • Start quickly. Plug and play or customize to your liking.
  • Embraces reactive programming. For consistent and reliable backend.
  • Switch and customize how errors are handled, logging, and more.
  • Use it with TypeScript or JavaScript. CommonJS and ESM supported.
  • Active and growing community, always here to help. Join us
  • Unleash its full potential with a powerful CLI and awesome plugins.

πŸ“œ Installation

npm install @sern/handler
yarn add @sern/handler
pnpm add @sern/handler

πŸ‘Ά Basic Usage

ping.ts
export default commandModule({
  type: CommandType.Slash,
  //Installed plugin to publish to discord api and allow access to owners only.
  plugins: [publish(), ownerOnly()],
  description: 'A ping pong command',
  execute(ctx) {
    ctx.reply('Hello owner of the bot');
  }
});
modal.ts
export default commandModule({
    type: CommandType.Modal,
    //Installed a plugin to make sure modal fields pass a validation.
    plugins : [
        assertFields({
            fields: { 
                name: /^([^0-9]*)$/ 
            },
            failure: (errors, modal) => modal.reply('your submission did not pass the validations')
        })
    ],
    execute : (modal) => {
        modal.reply('thanks for the submission!');
    }
})
index.ts
import { Client, GatewayIntentBits } from 'discord.js';
import { Sern, single, type Dependencies } from '@sern/handler';

//client has been declared previously

interface MyDependencies extends Dependencies {
    '@sern/client': Singleton<Client>;
}
export const useContainer = Sern.makeDependencies<MyDependencies>({
    build: root => root
        .add({ '@sern/client': single(() => client)  })
});

//View docs for all options
Sern.init({
	defaultPrefix: '!', // removing defaultPrefix will shut down text commands
	commands: 'src/commands',
	// events: 'src/events' (optional),
	containerConfig : {
	    get: useContainer
	}
});

client.login("YOUR_BOT_TOKEN_HERE");

πŸ€– Bots Using sern

πŸ’» CLI

It is highly encouraged to use the command line interface for your project. Don't forget to view it.

πŸ”— Links

πŸ‘‹ Contribute

  • Read our contribution guidelines carefully
  • Pull up on issues and report bugs
  • All kinds of contributions are welcomed.

About

A complete, customizable, typesafe, & reactive framework for discord bots

https://sern.dev

License:MIT License


Languages

Language:TypeScript 83.1%Language:JavaScript 16.9%