İçeriğe geç
sern

First Command

Bu içerik henüz dilinizde mevcut değil.

Introduction

In this guide, we’ll walk you through creating your first command module.

If you installed a new project via the CLI, your file should be here:

  • Dizinsrc/commands/
    • ping.ts (right here, probably)
src/commands/ping.js
1
const { CommandType, commandModule } = require("@sern/handler");
2
3
export default commandModule({
4
type: CommandType.Both,
5
plugins: [],
6
description: "A ping command",
7
// alias : [],
8
execute: async (ctx, args) => {
9
await ctx.reply("Pong 🏓");
10
},
11
});

To view what each of these properties mean in depth, visit the docs for CommandType.

Command Module Types

Every command module type is part of an enum. This field allows type inference for the rest of a module’s fields.

All the command types can be found in the CommandType enum!

Example Modal Command

So, lets say you want to make a command module that listens to modals.

1
const { CommandType, commandModule } = require("@sern/handler");
2
3
exports.default = commandModule({
4
name: "dm-me",
5
type: CommandType.Modal,
6
async execute(modal) {
7
const value = modal.fields.getTextInputValue("message");
8
modal.client.users
9
.fetch("182326315813306368")
10
.then((u) => u.send(value + ` from ${modal.user}`));
11
modal.reply({ ephemeral: true, content: "Sent" });
12
},
13
});

Commands are straight forward. Keep in mind, the only required fields for command modules are the type and execute function.

Context Class

The provided Context class helps with modules of CommandType.Both (A mixture of slash / legacy commands).

The Context class is passed into modules with type:

  • CommandType.Both
  • CommandType.Slash
  • CommandType.Text

This data structure helps interop between legacy commands and slash commands with ease.