npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord.js-casanova

v0.0.10

Published

discord.js-casanova is a discord.js framework that sets up your bot as quickly as possible! all you have to do is write the commands and events! *There is a way to disable the command handler and event handler.*

Downloads

71

Readme

NOTE: If you're using typescript with this package and having problems or have any questions please join the support server

Features

Completely modular commands, and events.

- Reading files recursively from directories.
- Handle commands and events easily.

Command Features.

  • Cooldowns! (In seconds).
  • Utility Functions!
  • Aliases!
  • Client and Member permissions!
  • Guild, and owner only commands!
  • Nsfw commands!

Command Handler Feautres.

  • prefix - can be a string, an array, or a function!
  • defaultCooldown - The default cooldown for commands! optional.
  • ignoreCooldown - Let specific users bypass the cooldown on commands! optional.
  • strict - Whether or not to be strict on command execution optional | default=false.
  • Base Client, and Member permissions. - Check base permissions for each client and member. optional.

Command Handler Events.

  • cooldown - Emitted when a user is on cooldown.
  • commandUsed - Emitted when a user uses a command.
  • missingPermissions - Emitted when the member or client is missing permissions.
  • commandBlocked - emitted when a command is blocked due to nsfw | ownerOnly | guildOnly | disabled.
  • commandError - emitted when an error occurs within a command.

Event Handler Events.

  • eventError(event, errorMessage) - emitted when an error occurs within an event.

Command Handler Event paramaters

Note: command is the used command. message: is the Message object.

  • cooldown(message, command, timeLeft) note: timeLeft is in milliseconds.
  • commandUsed(message, command).
  • missingPermissions(message, command, missing, type) note: missing are the missing permissions and type is either client or member.
  • commandBlocked(message, command, reason) note: reason being "nsfw OR guildOnly OR ownerOnly OR disabled"
  • commandError(message, command, errorMessage)

Getting Started!

The Client

  // First we import the Client from discord.js-casanova.
  
  const { CasanovaClient } = require("discord.js-casanova");
  
  // Then we create our client!
  
  class Client extends CasanovaClient {
    // constructor
    constructor() {
        // super call
          super({
              // here are the Casanova Client options.
              token: "Your bot token here.",
              handlers: ["command", "event"], // this option just enables the command and event handlers if you want to use only the command handler you can just put command in the array.
              owners: [""] // The owner IDS NOTE: Required if you want to use the ownerOnly command option.
          }, {
               // Here goes your regular discord.js client options
            })
      }
       // This is a function to log the bot in.
      async start() {
        try {
            await this.build();
            return console.log(`${this.user.tag} is online!`);
          } catch (e) {
               console.error(e);
          }
      }
  }
  
  // Now that we've created our client let's log the bot in!
  
  const client = new Client();
  
  client.start();
  
  // Now you're bot is online!

Setting up the command handler.

Well now that we've created our client let's set up the command handler.

// First let's import The command handler from discord.js-casanova!

const { CasanovaClient, CommandHandler } = require("discord.js-casanova");

class Client extends CasanovaClient {
constructor() {
  super(
    {
      token: "Your bot token here.",
      handlers: ["command", "event"],
      owners: [""],
    },
    {}
  );

  // Then inside the clients constructor create a property and name it whatever you want in this example I'm naming it "commandHandler".
  this.commandHandler = new CommandHandler(this, {
    commandDirectory:
      "The command folder directory the base being the main directory.",
    prefix: (message) => {
      return "+"; // Notice this function MUST return a string!
    }, // here is your prefix note this can be a string, array, or a function
    baseClientPermissions: ["Base client permissions."],
    baseMemberPermissions: ["Base member permissions."],
    blockBots: true, // Whether or not to block bots.
    blockClient: true, // Whether or not to block the client.
    defaultCooldown: 3, // The default cooldown for commands.
    ignoreCooldown: [""], // Array of people who can ignore the cooldown.
    setCommandClient: true, // default to true || This is mostly for typescript users if you set this to false you won't be able to access the client via `this.client`!
    strict: true, // default to false. Whether to be strict about the command's execution.
  }, {}); // second paramater is "ops" it's an object that allows you to add whatever you want.
}

async start() {
  try {
    await this.build();
    return console.log(`${this.user.tag} is online!`);
  } catch (e) {
    console.error(e);
  }
}
}

Setting up the event handler!

// Now for the event handler we have to import it first!
const {
  CasanovaClient,
  CommandHandler,
  EventHandler,
} = require("discord.js-casanova");

class Client extends CasanovaClient {
  constructor() {
    super(
      {
        token: "Your bot token here.",
        handlers: ["command", "event"],
        owners: [""],
      },
      {}
    );

    this.commandHandler = new CommandHandler(this, {
      commandDirectory:
        "The command folder directory the base being the main directory.",
      prefix: (message) => {
        return "+";
      },
      baseClientPermissions: ["Base client permissions."],
      baseMemberPermissions: ["Base member permissions."],
      blockBots: true,
      blockClient: true,
      defaultCooldown: 3,
      ignoreCooldown: [""],
      setCommandClient: true,
      strict: true,
    }, {});

    // Then we make a property again call it whatever you want but i'm calling it eventHandler for this example.
    this.eventHandler = new EventHandler(this, {
      eventDirectory:
        "The event folder directory the base being the main directory.",
    }, {}); // second paramater is "opts" it's an object that allows you to add whatever you want.
  }

  async start() {
    try {
      await this.build();
      return console.log(`${this.user.tag} is online!`);
    } catch (e) {
      console.error(e);
    }
  }
}

Creating your first command!

Notice: This should be in each file in the commands directory.

// Now for your first command!

// first we've gotta import the command base!

const { CommandBase } = require("discord.js-casanova");

module.exports = class PingCommand extends CommandBase {
  constructor() {
    super({
      name: "ping", // the name of the command.
      aliases: ["p"], // The aliases for the command <optional>.
      category: "Utils", // Category. <optional>
      clientPermissions: ["client permissions"], // <optional>
      cooldown: 4, // 0 for no cooldown <>.
      description: "description", // <optional>
      guildOnly: true, // <optional> default=true
      memberPermissions: ["member permissions"], // <optional>
      nsfw: false, // <optional> default=false
      ownerOnly: false, // <optional> default=false
      usage: "usage", // <optional>
    }, {}); // second paramater is "opts" it's an object that allows you to add whatever you want.
  }

  // Now every command Has to have an execute function.
  execute(message, args) {
    console.log(args);
    console.log(message.content);
    console.log(this.client.user.tag); // `this.client` being your client.
  }
};

Creating your first event!

Notice: This should be in each file in the events directory.

// Now we gotta import the event base!
const { EventBase } = require("discord.js-casanova");

module.exports = class SomeEvent extends EventBase {
  constructor() {
    super({
      name: "Name of the event.",
      once: false, // <optional> Whether the event should be emitted once or not.
    });
  }

  // Every event has to have an execute function.
  execute(...parms) {
    console.log(this.client.user.tag);
  }
};

Problems / issues

If you ever run into any issue with this package please join our support server and feel free to ping me!

Contributing.

Pull requests are welcome by anybody.

bugs and reports can go in the issues section or in the support server.