Skip to content

fuma-nama/discord-fp

Repository files navigation

logo

Discord-FP

A Beautiful Application Command Framework For Discordeno & Discord.js

Features

  • Type-safe
  • Light-weight
  • High performance
  • Auto-complete & Middlewares
  • File-system Based
  • Beautiful code with Functional Programming
  • Support both Discordeno and Discord.js
  • Compatible with ESM and CommonJS

Install

Discordeno

Refer to here for Documentation of Discord-FP for discordeno

npm install @discord-fp/discordeno

Discord.js

npm install @discord-fp/djs

Note
Example below uses commonjs + typescript + import alias
you may convert it into normal common js syntax yourself

Slash command in the Best way

Stop writing lots of interaction.options.get("name") just for getting the value of an option

Let us handle everything!

import { options } from "@discord-fp/djs";
import { command } from "@/utils/dfp";

export default command.slash({
    description: "Say Hello to you",
    options: {
        name: options.string({
            description: "Your name",
        }),
    },
    execute: async ({ event, options }) => {
        await event.reply(`Hello, ${options.name}`);
    },
});

Find your Command Instantly

Tired of finding your command all the place? All commands are file-system based!

Search file by name, you are able to find your command instantly

For slash command: test hello

commands/test/_meta.ts

import { command } from "@/utils/dfp";

export default command.group({
    description: "Your Command Group description",
});

commands/test/hello.ts

import { command } from "@/utils/dfp";

export default command.slash({
    //...
});

Powerful & Beautiful

Not just slash commands, you are able to create context menu commands with few lines of code

commands/Delete Message.ts

import { command } from "@/utils/dfp";

export default command.message({
    async execute({ event }) {
        await event.reply("I don't wanna delete message!");
    },
});

Middleware

Wanted to run something before executing a command?

With middleware, you can control how an event handler being fired, or pass context to the handler

utils/dfp.ts

import { initDiscordFP } from "@discord-fp/djs";

export const dfp = initDiscordFP();
export const command = dfp.command;

//Don't return anything to prevent calling the handler
export const protectedCommand = command.middleware(({ event, next }) => {
    return next({
        ctx: {
            message: "hello world",
        },
        event,
    });
});

commands/your-command.ts

import { protectedCommand } from "@/utils/dfp";

export default protectedCommand.slash({ ... })

Everything is Type-safe + Null-safe

From config, middleware context, to options values, It's all type-safe!

export default command.slash({
    description: "Say Hello to you",
    options: {
        enabled: options.boolean({
            description: "Enabled",
            required: false,
        }),
        number: options.number({
            description: "Example number",
            required: true,
        }),
    },
    //...
});

Take a look at options:

(parameter) options: {
    enabled: boolean | null;
    number: number;
}

Getting Started

Try our template which includes everything you need

Discord.js Discordeno
Docs Docs

ESM Usage

ESM has been supported since v0.2.1

Note
If you have any problems with relative path, you may pass an absolute path instead

Common js

const { ... } = require("@discord-fp/djs");

ESM

import { ... } from "@discord-fp/djs";

Any issues?

Feel free to open an issue!
Give this repo a star if you loved this library