Command and event handling

Warning

This page is still a work in progress.

To use the discm handler, make two directories, one for commands and one for events.

Note

We recommend using the names commands and events, however you can use whatever names you want.

📦your-ts-project
┣ 📂commands
┃ ┗ 📜ping.ts
┣ 📂events
┃ ┗ 📜ready.ts
┣ ...
    
📦your-js-project
┣ 📂commands
┃ ┗ 📜ping.js
┣ 📂events
┃ ┗ 📜ready.js
┣ ...
    

Commands

Each file in the commands directory represents a command.

Discm will use the file name for the command name.

Each file should export an instance of the DiscmCommand class.

// filename: commands/ping.ts
import { DiscmCommand } from "discm.js";

export default new DiscmCommand({
    ...
});
// filename: commands/ping.js
const { DiscmCommand } = require("discm.js");

module.exports = new DiscmCommand({
    ...
});

The following properties must be defined:

  • type: whether this is a slash or text command.
  • description: the description of this command.
  • run: the callback for this command.

The rest of the properties are optional.

Events

Similarly, each file in the events folder represents an event.

However, discm does not use the file name to determine the event, instead a name property has to be passed.

Each file should export an instance of the DiscmEvent class.

// filename: events/ready.ts
import { DiscmEvent } from "discm.js";

export default new DiscmEvent({
    name: "ready",
    ...
});
// filename: events/ready.js
const { DiscmEvent } = require("discm.js");

module.exports = new DiscmEvent({
    name: "ready",
    ...
});

Linking to the Client

The DiscmClient class extends discord.js’s Client class.

Discord.js’s ClientOptions is still required, but you can also supply discm’s AdditionalClientOptions.

The dirs property is required, and its properties commands and events are also required, this is how you like your directories to your client.

// filename: index.ts
import { DiscmClient } from 'discm.js';

const client = new DiscmClient({
    // From Discord.JS `ClientOptions`
    intents: ['Guilds'],

    // From discm.js `AdditionalClientOptions`
    dirs: {
        commands: `${__dirname}/commands`,
        events: `${__dirname}/events`
    }
});
// filename: index.js
const { DiscmClient } = require('discm.js'_;

const client = new DiscmClient({
    // From Discord.JS `ClientOptions`
    intents: ['Guilds'],

    // From discm.js `AdditionalClientOptions`
    dirs: {
        commands: `${__dirname}/commands`,
        events: `${__dirname}/events`
    }
});