Coder Social home page Coder Social logo

djs-marshal's Introduction

djs-marshal

A lightweight command handler for discord.js interactions

This package requires discord.js v13 or higher to be installed

This package is currently under construction, more features will be added regularly. The docs are also pretty barebones at the moment and will be improved soon.

Installation

# with npm
npm install djs-marshal --save
# with yarn
yarn add djs-marshal

# this package also requires discord.js
npm install discord.js --save

Quick Start

In your root file, preferably index.js/ts, initialize the bot like so

import Marshal from 'djs-marshal'
import { Intents } from "discord.js";
import path from 'path';

// you can pass in the token to make the client login automatically
const client = Marshal.initializeBot({
  intents: [Intents.FLAGS.GUILDS],
  token: 'your-token-here',
  // this is the folder path that contains your commands
  slashCommandsPath: path.join(__dirname, 'commands')
});

Now in your commands folder, you can start creating command files!

Here are some examples:

// ping.js|ts
import { SlashCommand } from "djs-marshal";

// a pretty basic command. command is a discord.js
// CommandInteraction and you can use its methods like
// reply, defer, editReply, etc.
export default {
  name: 'ping',
  description: 'Play ping-pong with me',
  execute (command) {
    command.reply('Pong!')
  }
} as SlashCommand;
// guildPing.js|ts
import { SlashCommand } from "djs-marshal";

// any command with a guildId specified is registered as
// as a guild command and will only work in that guild
export default {
  name: 'guildping',
  description: 'Play ping-pong with me in this server',
  guildId: '873232757508157470',
  execute (command) {
    command.reply('Peng!');
  }
} as SlashCommand;
// deferredPing.js|ts
import { SlashCommand } from "djs-marshal";

// you can pass in defer as true to defer the interaction beforehand
export default {
  name: 'slothping',
  description: 'piiiiiinnnnnng',
  // you can also use deferEphemeral to mark the reply ephemeral
  defer: true,
  execute (command) {
    setInterval(() =>{
      command.editReply('Pooooooonnnngg!');
    }, 3000)
  }
} as SlashCommand;

Contributing

Please read CONTRIBUTING.md for the guidelines to contribute to this project

djs-marshal's People

Contributors

deathvenom54 avatar

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.