Release 1.2.0
Bu içerik henüz dilinizde mevcut değil.
Class-based modules
Today we’re announcing the ability to create class based modules! To get started, install
npm install @sern/handler@latestpnpm add @sern/handler@latestyarn add @sern/handler@latestbun add @sern/handler@latestQuick List of changes!
Class based modules
Incorporate class based modules into your project instead of the traditional commandModule or eventModule
Extend the new CommandExecutable or EventExecutable
1import {2 CommandType,3 CommandExecutable,4 type Args,5 type Context,6} from "@sern/handler";7import { publish } from "../plugins/publish.js";8import { serendipityOnly } from "../plugins/serendipityOnly.js";9
10export default class extends CommandExecutable<CommandType.Both> {11 type = CommandType.Both as const;12 description = "What is the meaning of life?";13 override onEvent = [serendipityOnly()];14 override plugins = [publish()];15 execute = async (ctx: Context, args: Args) => {16 await ctx.reply("42");17 };18}1import { CommandType, EventExecutable, type EventType } from "@sern/handler";2import type { GuildMember } from "discord.js";3
4export default class extends EventExecutable<EventType.Discord> {5 type = EventType.Discord as const;6 execute = (member: GuildMember) => {7 console.log(member);8 };9}Now, you might ask why this feature was added.
Simply put, to give flexibility to the developers.
I believe that you should build your own structures however you might like and customize to your liking.
In addition, decorators now unofficially work with modules!
Feel free to use TypeScript experimental decorators to augment and customize your classes.
Deprecation Warnings
The next update will bring sern v2 with some important features. Here are some things to watch out for.
- Wrapper#client will be deprecated
- Wrapper#sernEmitter will be deprecated
- a SernEmitter will be automatically created once Sern#init is called
- The option to pass in a function or array for Wrapper#events will be deprecated. Only strings are accepted.
Sern#addExternalwill be deprecated in favor of a better way.
Dependencies Update
- TypeScript has been updated to 4.8.3
- Discord.js has been upgraded to 14.5