Code Monkey home page Code Monkey logo

discord-fp's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.