Introduction
sern operates with modules . At its core, modules are simple objects which contain properties type
,execute
, and plugins
(code ran before execute
).
Modules
We’ll walk you through creating your first command module.
If you installed a new project via the CLI, your file should be here:
Application Commands
Includes CommandType.Slash
, CommandType.Both
, CommandType.CtxUser
, CommandType.CtxMsg
import { commandModule, CommandType } from " @sern/handler " ;
export default commandModule ({
description: " A ping command " ,
execute : async ( ctx , sdt ) => { // ctx is Context, sdt is SDT type
await ctx . reply ( " Pong 🏓 " );
import { commandModule, CommandType } from " @sern/handler " ;
export default commandModule ({
type: CommandType . CtxMsg ,
execute : async ( ctx ) => {
await ctx . reply ( " Hello. " );
Tip
You’ll need to publish these modules. Don’t worry, we’ve already got that covered here .
You may not see your command instantly in Discord, if so, try refreshing.
Components
So, lets say you want to make a command module that listens to buttons , or ANY component (modals, select menus).
import { CommandType, commandModule } from " @sern/handler " ;
import { ButtonStyle, ActionRowBuilder, ButtonBuilder } from ' discord.js ' ;
export default commandModule ({
description: " A ping command " ,
execute : async ( ctx , sdt ) => {
const editButton = new ButtonBuilder ( {
style: ButtonStyle . Primary ,
components: [ new ActionRowBuilder () . addComponents ( editButton )]
import { CommandType, commandModule } from " @sern/handler " ;
export default commandModule ({
type: CommandType . Button ,
Dynamic Component Parameters
Components can carry metadata. This comes in handy when handling multiple components of the same purpose. This is good for passing small, string based data across components.
import { CommandType, commandModule } from " @sern/handler " ;
import { ButtonStyle, ActionRowBuilder, ButtonBuilder } from ' discord.js ' ;
export default commandModule ({
description: " A ping command " ,
execute : async ( ctx , sdt ) => {
const editButton = new ButtonBuilder ( {
customId: " btn/1061421834341462036 " ,
style: ButtonStyle . Primary ,
components: [ new ActionRowBuilder () . addComponents ( editButton )]
import { CommandType, commandModule } from " @sern/handler " ;
export default commandModule ({
type: CommandType . Button ,
execute : ( ibtn , sdt ) => {
ibtn . reply ( ' clicked with ' + sdt . params )
Event Modules
We are now moving to event modules, which listens to the vast streams of data provided by
sern
, EventType.Sern
discord.js
, EventType.Discord
yourself
, EventType.External
If you haven’t already, add the events
directory to your config
export const events = " ./dist/events " ;
Listening to Discord Events
import { eventModule, EventType } from " @sern/handler " ;
export default eventModule ({
execute : async ( message ) => {
console . log ( ` ${ message . user } said ` , message . content )