When creating plugins, you should avoid using Deno or Node specific features to make your plugin compatible with both the JSR and NPM package.

CLI Command

Terminal
blitz plugin

You will then be asked questions to help Blitz create the config file for you.

Questions

Name
string
required

The name of your plugin

Description
string
required

A short description of what your plugin does

Version
number
required

The name of your plugin

Files

Structure

Your plugin should have a similar structure to this.

File Structure
├── /commands
├── /events
└── blitz.config.yaml

Uses

/commands

Holds the commands for your plugin.

/events

Holds the events for your plugin.

blitz.config.yaml
required

Holds the manifest data and config for your plugin.

blitz.config.yaml

The blitz.config.yaml file contains all the metadata for your plugin. You can also add config valuese to this to allow users to customize your plugin.

Example blitz.config.yaml

blitz.config.yaml
name: my_plugin
description: My totally cool plugin
version: 1.0.0

Manifest Values

name
string
required

The name of your plugin

description
string
required

A short description of what your plugin does

version
number
required

The version of your plugin

Adding Config

You can add config values inside of your plugins blitz.config.yaml file which will be passed into your plugins commands and events.

blitz.config.yaml
name: my_plugin
description: My totally cool plugin
version: 1.0.0

config:
    cool_message: "This is a cool message"

This basic example of a blitz.config.yaml file contains a config key called cool_message. In any of the plugins commands or events you can access this.

Event.ts
console.log(config.cool_message)

This would log This is a cool message.

Commands

All commands for a plugin must go inside of the /commands folder in the root of the plugin.

Commands are built using the discord.js SlashCommandBuilder class.

Example Command

ping.ts
import { SlashCommandBuilder } from "npm:discord.js";

export default {
  data: new SlashCommandBuilder()
    .setName("ping")
    .setDescription("Pong!"),
  action: async (client, interaction) => {
    await interaction.reply({ content: `Pong!` });
  },
};

Notice the import from npm:discord.js? This is a specific deno import which allows us to use discord.js within deno.

Example Command (Config)

greet.ts
import { SlashCommandBuilder } from "npm:discord.js";

export default {
  data: new SlashCommandBuilder()
    .setName("greet")
    .setDescription("Greet someone"),
  action: async (client, interaction, config) => {
    await interaction.reply({ content: `${config.greetMsg}` });
  },
};

For this command to work you would have to add greetMsg to your blitz.config.yaml file.

blitz.config.yaml
name: my_plugin
description: My totally cool plugin
version: 1.0.0

config:
    greetMsg: "Welcome to the server!"

Events

All events for a plugin must go inside of the /events folder in the root of the plugin.

Example Event

ready.ts
export default {
  event: "ready",
  once: true,
  action: async (client) => {
    console.log(`${client.user.username} is online!`);
  },
};

Example Event (Config)

message.ts
export default {
  event: "messageCreate",
  once: true,
  action: async (client, config, message) => {
    message.reply(`${config.message}`);
  },
};

For this event to work you would have to add message to your blitz.config.yaml file.

blitz.config.yaml
name: my_plugin
description: My totally cool plugin
version: 1.0.0

config:
    message: "I replied to a message!"

Test Plugin

You can test a plugin locally with one command.

CLI Command

Terminal
blitz test <token>

CLI Params

token
string
required

Your bots token to test the plugin on