/yui

πŸ‘Ύ Almost like a daughter, it's a general purpose bot, called Yui I'm developing for discord with discord.js library, the name is inspired by the character Yui from the anime Sword Art Online, which at first is an A.I.

Primary LanguageJavaScript

Yui

VersΓ£o em portuguΓͺs

Almost like a daughter, it's a general purpose bot, called Yui I'm developing for discord with discord.js library, the name is inspired by the character Yui from the anime Sword Art Online, which at first is an A.I.


πŸ€” How to use in my server?

  • Add the bot, just click in this LINK
    • You must be an administrator on some server
  • Read the Docs of commands HERE
  • Enjoy 😁

🧩 Running locally

Before all you must to be added the bot in your server, to do this follow the link

// Clone de repository
$ git clone https://github.com/miguelrisquelme/yui.git

// Install the dependencies
$ npm i

// Create and configure the file .env, follow the example on .env.example
~/.env

// Start the aplication
$ npm run dev

❌ Error Handling

For the error consoles to work, the folder structure has to be standardized, just follow these instructions:

  • The command name must be the same as its folder name.

    /commands/${nameCommand}

    module.exports = {
      name: `${nameCommand}`,
      description: "Description Command",
      execute,
    };
  • The name of the functions must be the same as the arguments passed after the command

    • > time ${args}
    • /commands/time/functions/${args}.js

Example Output:

      ❌ TypeError: message.channel.sen is not a function
      🦊 Input: '> time hours'
      ✨ Command: time
      πŸ”₯ Function: hours
      πŸ§… Possible Path: /commands/time/hours.js

The code of catch Error:

const error = require("../utils/handlers/errors/errors.handler");
...

catch (err) {
  const args = message.content.slice(prefix.length).trim().split(/ +/);
  console.error(`
      ❌ ${err.toString()}
      🦊 Input: '${message.content}'
      ✨ Command: ${args[0]}
      πŸ”₯ Function: ${args[1]}
      πŸ§… Possible Path: /commands/${args[0]}/${args[1]}.js
    `);
  console.error(err);
  error.handler(err, message);
}

🧬 Application flow

Directories

/commands

  • Directory where all bot commands are found
  • Each command is in a folder with its name
  • Inside each folder has
    • main.js - Command settings
    • /functions - Inside this folder are the subcommands so to speak

Code example

// Imports

const execute = (message, args) => {
  try {
    // The code to execute
  } catch (error) {
    console.error(error);
  }
};

module.exports = {
  name: "Command's name",
  description: "Description's command",
  execute,
};

/events

  • Directory where all bot events are found
  • Everything that will be executed as an action is here

/handlers

  • Where will the data be manipulated
  • Handlers are created to manipulate data types
    • Events
    • Errors
    • Commands

Important Files

index.js

  • Anonymous function
  • List the commands
  • Execute the handlers by sending the events directory

commands.handler.js

  • List the commands
  • Add them to the client which is the BOT instance

events.handler.js

  • Handle the events
  • Speak when the bot has fully started
  • Listen to the event message

error.handler.js

  • Handle errors
  • Say the types of errors

message.js

  • Check who is calling the command, if it is the OWNER_ID it will assign the name defined in the .env file
  • Handles the triggered event
  • Do the checks
  • Execute the command

ready.js

  • Shows how many servers the bot is connected to
  • Says the application is already running




πŸ“š References