Files
website/guide-en

Introduction

Welcome to the Sern's official guide. This guide will go through all the core features of the framework.
💖 Thank you for choosing Sern to be your framework!

Disclaimers

Alright, making a bot is cool and all, but there are some prerequisites to it. To create a bot with Ser, you should have a fairly decent grasp of JavaScript and discord.js itself. While you can make a bot with very little JavaScript and programming knowledge, trying to do so without understanding the language first will only hinder you. You may get stuck on many uncomplicated issues, struggle with solutions to incredibly easy problems, and all-in-all end up frustrated. Sounds pretty annoying.

If you don't know JavaScript but would like to learn about it, here are a few links to help get you started:

  • JavaScript.info, a modern javascript tutorial
  • Codecademy's interactive JavaScript course
  • Nodeschool, for both JavaScript and Node.js lessons
  • MDN's JavaScript guide and full documentation
  • Google, your best friend

Take your pick, learn some JavaScript, and once you feel like you're confident enough to make a bot, come back and get started! Teaching the discord.js library and/or Javascript/Typescript is out of scope of this project, so this guide assumes you already know these elements.

  • Sern is only available in discord.js@dev at the moment. There are plans to roll out a version of Sern in discord.js@13.xx.xx in the future.

You will learn

  • Sern's goal
  • How to use sern with the CLI
  • Your first command
  • The Context class

Working with plugins

  • Plugins

    • Command Plugins
    • Event Plugins
  • The SernEmitter class

Good to know

  • Your sern.config.json
  • Your first event
  • Setting up event listeners

Goal

Sern strives to be minimalist, but with all batteries included. Meaning, this framework provides the necessary tools to start up a bot in minutes, and leaves plenty room space to customize your experience and create an amazing project. It should include all the tools for any bot at any scale.

CLI

Setting up the CLI is easy.

  • To start a brand new project, run :
sern init (-y)

Include the -y flag if you want to set up defaults. The default langauge is Typescript

sern plugins

This will display a menu selection of all installable plugins.
Note: You must have a sern.config.json to use this command. If you want to view plugins, visit the repository linked above.

  • To install extra utilities into your project
sern extra

First Command

We will dissect a basic command. If you installed a new project via the cli, This is the ping command located in src/commands folder.

Typescript

import { commandModule, CommandType } from '@sern/handler';

export default commandModule({
	type: CommandType.Both,
	plugins: [],
	description: 'A ping command',
	//alias : [],
	execute: async (ctx, args) => {
		await ctx.reply({ content: 'Pong 🏓' });
	},
});

Javascript

const { CommandType, commandModule } = require('@sern/handler');

exports.default = commandModule({
	type: CommandType.Both,
	plugins: [],
	description: 'A ping command',
	//alias : [],
	execute: async (ctx, args) => {
		await ctx.reply('Pong 🏓');
	},
})

Essential properties of a command

  • module.type (Required)
    • The type of your module. For example, a command listening to messages would have the type CommandType.Text
  • module.execute (Required)
    • This function is called when the command is triggered. Do your logic here!
  • module.name (Optional)
    • Give your command a name. (defaults to its filename)
  • module.description (Optional)
    • Give your command a description. (defaults to ..)
  • module.plugins (Optional)
    • A list of plugins that will modify and change the behavior of your command.

Types of command modules

Every command module type is part of an enum. This field allows type inference for the rest of a module's fields.
All available command types :

CommandType.Text = A Text Command
CommandType.Slash = A Slash Command
CommandType.Both = A Command supporting either text or slash
CommandType.Modal = A Command listening to Modal interactions
CommandType.MenuSelect = A Command listening to select menu interactions
CommandType.MenuUser = A Command listening to context menu user interactions
CommandType.MenuMsg  = A Command listening to context menu message interactions
CommandType.Button = A Command listening to button interactions

So, lets say you want to make a command module that listens to modals.
Note: Keep in mind you'll need to send a modal with a custom id dm-me. This example below is the response to a modal being sent.

Typescript:

import { commandModule, CommandType } from '@sern/handler';
export default commandModule({
        name: 'dm-me',
        type: CommandType.Modal,
        async execute (modal) {
            const value = modal.fields.getTextInputValue('message');
            modal.client.users.fetch('182326315813306368').then( u =>
                u.send(value + ` from ${modal.user}`)
            );
            modal.reply( { ephemeral:true, content: 'Sent' })
        }
});

Javascript:

const { CommandType, commandModule } = require('@sern/handler');
exports.default = commandModule({
        name: 'dm-me',
        type: CommandType.Modal,
        async execute (modal) {
            const value = modal.fields.getTextInputValue('message');
            modal.client.users.fetch('182326315813306368').then( u =>
                u.send(value + ` from ${modal.user}`)
            );
            modal.reply( { ephemeral:true, content: 'Sent' })
        }
});