Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eds-fw/framework

Simply TypeScript framework for your discord.js bots
https://github.com/eds-fw/framework

discord discord-bot discord-js framework javascript nodejs typescript

Last synced: 4 months ago
JSON representation

Simply TypeScript framework for your discord.js bots

Awesome Lists containing this project

README

        





Simply TypeScript framework for your discord.js bots

[![CodeFactor](https://www.codefactor.io/repository/github/eds-fw/framework/badge/main)](https://www.codefactor.io/repository/github/eds-fw/framework/overview/main)


# Features
- Intuitive and does not complicate the development process
- Contains type declarations (.d.ts)
- Fully configurable
- Built-in `/help` command
- Lazy constructors (`createSlashCommand()`, `createButton()` and more)
- Smart Fetches: get from cache or fetch (`sfMember(context, userId)` and more)
- Simply 'Map'-based storage: `get()`, `set()`, `save()` and more
- Quick message panels for advanced for data input (`InteractivePanel`)
- Utils: `getAvatar()`, `quickEmbed()`, `optionsWithDefaultValue()` and `expandDirs()`

# Requirements
- [NodeJS](https://nodejs.org/en) `v18` or newer

# Setup
1. Install EDS via npm:
```bat
npm i @eds-fw/framework
```

2. Create `tsconfig.json` file:
```json
{
"extends": "./node_modules/@eds-fw/framework/tsconfig.base.json",
"exclude": [
"node_modules/",
"logs/",
"vault.json",
"dist/",
"assets/"
],
"compilerOptions": {
"rootDit": "src",
"outDir": "dist"
}
}
```

3. Create your first bot using EDS:
```ts
// src/index.ts
//'runtime' is a 'global' object equivalent
import { eds } from "@eds-fw/framework";
import { ApplicationCommandType } from "discord.js";
import { token } from "../vault.json" with { "type": "json" };
const config: eds.ConfigExemplar = {
token,
intents: "all",
commandsPath: "./commands/",
slashOnly: true, //default value
includeBuiltinCommands: {
help: true, //default value
},
colors: {
default: 0xffffff, //'0x' + HEX color without '#'
info: 0x00FFEA,
},
};

const bot = eds.createBot(config);
eds.createSlashCommand({
name: "cake",
description: "Give me a cake!",
nsfw: false,
type: ApplicationCommandType.ChatInput,
defaultMemberPermissions: null,
dmPermission: false,
});
eds.startBot();

export default bot;
```

4. Create your first `/cake` command:
```ts
// src/commands/cake.ts
import { eds } from "@eds-fw/framework";
import { ComponentType, ButtonStyle } from "discord.js";

//eds components are resistant to bot restarts
eds.createButton({
custom_id: "get cake"
}, async context => { //"get cake" button code
await context.quickReply(
true, //epemeral?
undefined, //title
"# :cake:" //description
);
})

export default {
async run(context)
{
await context.reply(
true, //ephemeral?
"aloha hawaii", //embed title (optional if has desc)
`<@${context.user.id}>, do you want a cake?`, //embed desc (optional if has title)
"info", //?embed color name (set in config)
[{ //?djs components
type: ComponentType.ActionRow,
components: [{
type: ComponentType.Button,
style: ButtonStyle.Secondary, //gray
custom_id: "get cake",
label: "Get cake"
}]
}]
);
},

//command options
info: {
name: "cake",
type: "slash",

//for auto-help:
desc: "Give me a cake!",
category: "General",
usage: '',
hidden: true,
}
} satisfies eds.CommandFile<"slash">;
```

5. A) Create `start.bat` file (WINDOWS ONLY) for easily compile & launch your bot:
```batch
rem start.bat
@npx tsc
@node dist/index.js
@pause
rem "@pause" keeps window open after bot crash
```
5. B) Create `start.sh` file for easily compile & launch your bot:
```sh
# start.sh
npx tsc
node dist/index.js
read -p "" #keeps window open after bot crash
```

6. Execute (open) `start.bat` or `start.sh` file. Voila! It's alive!

# API
- *module* `@eds-fw/utils`
- *module* `@eds-fw/storage`
- *module* `@eds-fw/fetch`
- `createBot (config: ConfigExemplar): KnownRuntimeProperties` *(lazyConstructor)*
- `createButton (options: ButtonOptions, code: ButtonCode): void` *(lazyConstructor)*
>- runtime: `componentManager`
- `createMenu (options: MenuOptions, code: MenuUserCode | MenuStringCode): void` *(lazyConstructor)*
>- runtime: `componentManager`
- `createModal (options: ModalOptions, code: ModalCode): void` *(lazyConstructor)*
>- runtime: `componentManager`
- `createSlashCommand (options: SpplicationCommandData): void` *(lazyConstructor)*
>- runtime: `slashCommandsManager`
- *async* `sfUser (mng_or_ctx: AnyContext | UserManager | undefined, id: Snowflake | undefined): Promise`
- *async* `sfMember (mng_or_ctx: AnyContext | GuildMemberManager | undefined, id: Snowflake | undefined): Promise`
- *async* `sfChannel (mng_or_ctx: AnyContext | GuildChannelManager | undefined, id: Snowflake | undefined): Promise`
- *async* `sfGuild (mng_or_ctx: AnyContext | GuildManager | undefined, id: Snowflake | undefined): Promise`
- *async* `sfRole (mng_or_ctx: AnyContext | RoleManager | undefined, id: Snowflake | undefined): Promise`
- *async* `sfMessage (mng_or_ctx: AnyContext | MessageManager | undefined, id: Snowflake | undefined): Promise`
- `getAvatar (user: | | undefined | null): string`
- `quickEmbed (title?: string, description?: string, type: string = "default", components?: BaseMessageOptions["components"], customEmbed?: JSONEncodable | APIEmbed): BaseMessageOptions`
- `optionsWithDefaultValue (options: SelectMenuComponentOptionData[], defaultVal: string | null): SelectMenuComponentOptionData[]`
- *async* `startBot (): Promise`
>- runtime: `slashCommandsManager, client, config`
- *anonimous class* `runtimeStorage` *(runtime)*
>- `[key: string]: any`
>- `getAll (...keys: (keyof T)): T`
>- `get (key: string): V`
>- `setAll (values: T): T`
>- `set (key: K, value: V): { [X in K]: V }`
- *class* `Client` *extends djs.Client*
>- *constructor* `(options: Options)`
>- *async* `init (): Promise`
- *class* `Handler`
>- runtime: `config, loader, client, contextFactory`
>- *constructor* `new ()`
- *class* `InteractivePanel `
>- *static* `register (messageConstructor: InteractivePanel.ConstructMessageFn, msgId: string): void`
>- *static* `getMenu(msgId: string): InteractivePanel | undefined`
>- *static* `renderValues(keysAndValues: [string, string | undefined, string?][]): string`
>- `data: Partial`
>- `render (): MessageCreateOptions & InteractionUpdateOptions & InteractionReplyOptions `
>- `deleteInstance (): void`
>- *private* *constructor* `()`
- *class* `Loader`
>- *field* `commandHelp: AutoCommandHelp`
>- *constructor* `new (path: string, noLog?: boolean, ignorePrefixes?: string[], builtinCommands?: ConfigExemplar.includeBuiltinCommands)`
>- `clearMaps (): void`
>- *async* `load (): Promise`
>- *iternal* *async* `loadBuiltin (): Promise`
>- *iternal* *get* `getCallMap: Map`
>- *iternal* *get* `getSlashCallMap: Map`
>- *iternal* *get* `getAlwaysCallMap: string[]`
>- *iternal* *get* `getHelpInfoMap: Map`
- *class* `SlashCommandsManager`
>- runtime: `client`
>- `create (options: djs.ApplicationCommandData): void`
>- `save (): void`
- *type* `SupportedInteractions`
- *type* `CommandContext `
- *type* `AnyContext`
- *type* `InteractionContext `
- *type* `SlashCommandContext`
- *type* `TextCommandContext`
- *type* `CommandFile`
- *type* `CommandHelpInfo`
- *type* `CommandInfo`
- *type* `ConfigExemplar`
- *type* `KnownRuntimeProperties`
- *iternal* *async* `expandDirs (path: string): Promise`
- *iternal* *class* `AutoCommandHelp`
>- runtime: `config`
>- *field* `pages: Map`
>- *field* `commandTypes: Map`
>- *field* `descriptions: Map`
>- *field* `templates: {...}`
>- *field* `_fullCommandList: string`
>- *constructor* `new ()`
>- `getCommandList (roles: string[]): string`
>- `getCommandNames (roles: string[]): string[]`
>- `getBakedCommandNames (roles: string[]): string[]`
>- `clear (): void`
>- *iternal* `reg (file: CommandFile as const): void`
>- *iternal* *field* `_publicCommands: string`
>- *iternal* *field* `_fullCommandList: string`
- *iternal* *class* `ContextFactory`
>- runtime: `config`
>- *constructor* `new ()`
>- `createTextContext (message: djs.Message): CommandContext`
>- `createSlashContext (interaction: djs.ChatInputCommandInteraction): CommandContext`
- *iternal* *class* `ComponentsManager`
>- *constructor* `()` *empty*
>- `clearMaps (): void`
>- `createButton (options: ButtonOptions, code: ButtonCode): void`
>- `createMenu (options: MenuOptions, code: MenuUserCode | MenuStringCode): void`
>- `createModal (options: ModalOptions, code: ModalCode): void`
>- *iternal* *get* `getButtonsMap: Map>`
>- *iternal* *get* `getMenusMap: Map>`
>- *iternal* *get* `getModalsMap: Map>`

# [Source (git)](https://github.com/eds-fw/framework)
# [Issues (git)](https://github.com/eds-fw/framework/issues)