Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

moedevs/discord-ahagon

Repository files navigation

CircleCI

discord-ahagon

A zero bloat discord.js command framework. Not classy, but functional

Unlike almost every other command framework, discord-ahagon does not rely on the verbose class syntax or this to implement commands. Allowing you to compose and reuse similar traits of commands and use concise arrow functions as well as giving you the ability to hook into different parts of the command execution process.

Warning: This library is still a work in progress, anything can change at any time

Getting started

Adding a command handler

// src/index.js

const { createHandler } = require("ahagon");

const handler = createHandler({
  commandsDirectory: `${__dirname}/commands`,
  prefix: "!"
});

Adding commands

// src/commands/util.js

const ping = {
  name: ["ping", "p"],
  run: ctx => ctx.message.reply("Pong!")
}

const avatar = {
  name: "avatar",
  run: ({ message }) => message.channel.send(message.author.avatarURL)
}

module.exports = { ping, avatar };

Examples

Important: These are currently planned features and are not all implemented yet

An extensive ban command

const ban = {
  name: ["ban", "🔨", "bean"],
  description: "bans a naughty boye with a reason",
  category: "moderation",
  userPermissions: ["BAN_MEMBERS"],
  clientPermissions: ["BAN_MEMBERS"],
  args: [{
    name: "target",
    description: "Ban target",
    type: "member",
    checks: [{
      check: (ctx, member) => member.bannable,
      onFail: (ctx, member) => ctx.message.channel.send(`I cannot ban ${member.user.username}!`)
    }, {
      check: (ctx) => ctx.database.lookup(ctx.message.author.id).then(member => member.isModerator),
      onFail: (ctx) => ctx.message.channel.send(`You are not authorized to do this`)
    }],
  }, {
    name: "reason",
    description: "Optional ban reason",
    type: "text",
    optional: true
  }],
  effect: (ctx, args) => {
    const start = new Date();
    console.log(`${ctx.message.member} used ban`);
    return (bannedMember) => {
      const time = new Date() - start;
      console.log(`Banned ${bannedMember.user.username} in ${time}ms.`);
      analyticsLibrary.send(time, { command: ctx.command.name });
    }
  },
  run: (ctx, args) => args.target.ban(args.reason)
}

module.exports = { ban };

You can export the commands however you like, in an array, an object or as default

"Don't call me by my last name... I tell you every time"

Made with <3 by the New Game community