mirror of
https://github.com/sern-handler/handler
synced 2026-06-16 04:42:16 +00:00
94070d99e8aa689361ed62e00ba7a38cb3fb5d1c
* fix npm script for workflows * filter lazy modules * lift inline function for readability * perf: use one instance of operator instead of creating instances * chore: move fmt closer to call site * refactor: inline function lifting and readability * add import payload type * refactor: remove redundant pipe for single function operators * refactor: clearer naming for resultResolver * refactor: no unused variable warning for updateAlive * style: pretty * refactor: remove redundant getter * style: pretty * fix: typescript needs explicit definition for defineAllFields * add LazyPaths map * chore: update tsup and typescript * chore: revert lazy module work and work on decoupling core * fix npm script for workflows * chore: fix typings * refactor: inline function `defineAllFields` * docs: add @since annotation * style: prettier * docs: add since annotations * fix: typings * chore: update dependencies * chore: remove unused import * style: pretty * merge on home pc * refactor: use dependencies less --------- Co-authored-by: jacoobes <jacobnguyend@gmail.com>
Handlers. Redefined.
A complete, customizable, typesafe, & reactive framework for discord bots
Why?
- Most handlers don't support discord.js 14.7+
- Customizable, composable commands
- Plug and play or customize to your liking
- Embraces reactive programming for consistent and reliable backend
- Customizable logger, error handling, and more
- Active development and growing community
👀 Quick Look
- Support for discord.js v14 and all interactions
- Hybrid commands
- Lightweight and customizable
- ESM, CommonJS and TypeScript support
- A powerful CLI and awesome community-made 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
- Community Bot, the community bot for our discord server.
- Vinci, the bot for Mara Turing.
- Bask, Listen your favorite artists on Discord.
- ava, A discord bot that plays KNGI and Gensokyo Radio.
- Murayama, :pepega:
- Protector (WIP), Just a simple bot to help enhance a private minecraft server.
💻 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.
Languages
TypeScript
100%
