1.6.1 • Published 1 year ago

@matteopolak/framecord v1.6.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Framecord 🤖

Build Status Docs Status NPM Package Status

framecord is a modular and extensible framework for creating Discord bots, created with discord.js.

Documentation

Check out the documentation at matteopolak.com/docs/framecord.

"Hello, world!"

The setup below will do the following: 1. Create a slash command called /helloworld that outputs the message Hello {user}! 2. Print I just logged in as {username}! to the console when the ready event is fired

src/index.ts

import { join } from 'node:path';

import { IntentsBitField } from 'discord.js';
import { Client, Command } from '@matteopolak/framecord';

const client = new Client({
  intents: [
    IntentsBitField.Flags.Guilds
  ]
});

// Client#compileCommandDirectory takes an *absolute path* to the
// command directory, and will construct a tree of commands.
//
// Commands in nested folders will be grouped under the command by the
// same name as the folder (which *must* exist)
//
// By default, commands are added relative to the root command node,
// but you can provide the subcommand Collection of any command to start
// there instead.
await client.compileCommandDirectory(join(__dirname, 'commands'));

// Client#init must complete (i.e. await it) *before* the client is logged in.
await client.init();

client.login(process.env.TOKEN);

src/commands/helloworld.ts

import {
  Command,
  CommandOptions,
  CommandResponse,
  CommandSource,
  EventHandler
} from '@matteopolak/framecord';

// *Must* be a default export in order to work properly when
// adding an entire command directory
export default class HelloWorld extends Command {
  // *Must* be an asynchronous function
  public async run(source: CommandSource): CommandResponse {
    return `Hello, ${source.user.username}!`;
  }

  // The @EventHandler decorator is used to define when
  // a method should be treated as an event listener
  //
  // It currently only has the `once` option, which (when true)
  // will stop listening to the event after it is fired once
  @EventHandler({ once: true })
  public async ready() {
    // `client` is a reference to the Client
    console.log(`I just logged in as ${this.client.user.username}!`);
  }
}
1.6.1

1 year ago

1.6.0

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.12

2 years ago

1.4.11

2 years ago

1.4.10

2 years ago

1.4.9

2 years ago

1.4.8

2 years ago

1.4.7

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.18

2 years ago

1.3.17

2 years ago

1.3.16

2 years ago

1.3.15

2 years ago

1.3.14

2 years ago

1.3.13

2 years ago

1.3.12

2 years ago

1.3.11

2 years ago

1.3.10

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago