1.4.2 • Published 3 years ago

simple-eris-command v1.4.2

Weekly downloads
3
License
ISC
Repository
-
Last release
3 years ago

simple-eris-command


A module that'll make things way easier when creating a Discord bot with the Eris library.

Creating a bot


You firstly have to create an index file where you will have to require and then instance the Client class. Once instanced the Client class, you have to specify your token, your commands folder path and events. Events path is mandatory to specify. Additionally, this framework also supports subdirectories in case you may want to have your commands in different folders as categories, as well as the events.

Say I've got my main file called index.js. It'd look like so...

index.js

const {Client} = require("simple-eris-command"); // Require Client class

new Client({
   token: "" , // Your bot token.
   eventsPath: "./events", // Your events folder path
   commandsPath: "./commands" // Your commands folder path (optional).
});
//That's it!

Or...

const {Client} = require("simple-eris-command"); // Require Client class

class MyClient extends Client {
   constructor() {
      super({
         token: "", // Your bot token.
         eventsPath: "./events", // Your events folder path
         commandsPath: "./commands" // Your commands folder path (?:optional).
      });
   }
}

const myClient = new MyClient(); 
// As you want!

Your first command


Once you've specified your commands folder path, the only left thing to do is creating them. simple-eris-command makes commands creation a lot easier and much cleaner. Also allows you to create them with special features.

Before anything, at the top of your file, you are going to need to require CommandStructure class.

const {CommandStructure} = require("simple-eris-command");

Commands have to be exported with module.exports.

class MyCommand extends CommandStructure {
   constructor(client) {
      super(client, {
         name: "mycommand",
         aliases: ["ok", "t"],
         category: "idk",
         description: "any command"
      });
   }
}

Run method


Next thing you'll need is the run method. This method has to go below the constructor.

class MyCommand extends CommandStructure {
   constructor(client) {
      super(client, {
         name: "mycommand",
         aliases: ["ok", "t"],
         category: "idk",
         description: "any command"
      });
   }
   run(message) {
      return message.channel.createMessage("Hello.");
   }
}
module.exports = MyCommand;
MemberType
namestring
autoAliases?boolean
aliases?string[]
categorystring
descriptionstring
subcommands?Subcommands[]
format?string
details?string
examples?string[]
ownerOnly?boolean
clientPermissions?string[]
userPermissions?string[]
nsfw?boolean
cooldown?number
enabled?boolean
hidden?boolean
supportServerOnly?boolean
guildOwnerOnly?boolean

Events


Say you want to know whenever your bot was successfully connected to the Discord websocket. For this, you'd need a event. Specifically ready event.

Before anything, at the top of your file, you are going to need to require EventStructure class.

const {EventStructure} = require("simple-eris-command");

Events have to be exported with module.exports, too.

class ReadyEvent extends EventStructure {
   constructor(client) {
      super(client, {
         name: "ready"
      });
   }
}

Run method


Events need the run method. As the commands' this method has to go below the constructor.

class ReadyEvent extends EventStructure {
   constructor(client) {
      super(client, {
         name: "ready"
      });
   }
   run() {
      console.log(`logged in as ${this.client.user.username}#${this.client.user.discriminator}.`);
   }
}
module.exports = ReadyEvent;
MemberType
namestring
enabledboolean

messageCreate event example


"CoMmAnDs wOnT wOrK!1!1!!!"

This is a little example on what the messageCreate event looks like, or how I'd do it. This event will run whenever a message is received.

So you've got your file called messageCreate.js it'd like so...

// messageCreate.js
const {EventStructure} = require("simple-eris-command");

class MessageCreate extends EventStructure {
   constructor(client) {
      super(client, {
         name: "messageCreate"
      })
   }
   async run(message) {
      if (message.author.bot) return; // Ignore other bots and itself.
      const prefix = "?" // This is your prefix which your commands are gonna respond by.
      if (!message.content.startsWith(prefix)) return; // Ignore any message that does not start with your prefix.
      const args = message.content.slice(prefix.length).trim().split(/ +/g);
      const command = args.shift().toLowerCase();
      const clientCommand = this.client.commands.get(command) || this.client.commands.aliases.get(command);
      if (!clientCommand) return;
      if (clientCommand.supportServerOnly && message.channel.guild.id !== "Your guild ID") return; // If a command that's supportServerOnly is used in a guild isn't yours, do not run the command.
      if (clientCommand.guildOwnerOnly && message.member.user.id !== message.channel.guild.ownerID) return; // If you only want the guild owner to be able to use a command.
      if (clientCommand.clientPermissions && message.channel.guild && clientCommand.clientPermissions.find(p => !message.channel.guild.members.get(this.client.user.id).permission.has(p))) return // If the command requires permissions for the client and it does not have them, do not run the command.
      if (clientCommand.userPermissions && message.channel.guild && clientCommand.userPermissions.find(p => !message.member.permission.has(p))) return; // If the command requires permissions for the user and they do not have them, do not run the command.
      if (clientCommand.nsfw && !message.channel.nsfw) return; // If the command must be used in a nsfw channel and the channel isn't an nsfw one, do not run the command.
      if (clientCommand.ownerOnly && message.author.id !== "Your ID") return; // If the command is ownerOnly and the message author's ID is not yours, do not run the command. You can also make an array of ids so that you can have other owners.
      try { // run it if exists.
         await clientCommand.run(message, args);
      } catch (err) {
         console.log(err);
      }
   }
}

Need help? Issue report? Don't understand it?

Join our Discord server or contact me directly pxvh#3764

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago