Bot Documentation

Learn How the crew bot works

Overview

The Echo Crew Bot is a personalized Discord bot developed using Discord.js and Node.js. It was developed to have personalized commands pertaining to the Crew rather than to the general public. See below for a list of commands.

Bot Commands

Bot API

This Discord bot is always reading the messages sent on the server. It is simply checking if the message starts with the percentage symbol and if the remaining string fits its command list. I am open to suggestions on improving the efficiency of the code. Below will feature some snippets of code to provide a general idea of how the bot operates.

Case Sensitivity

To remove case sensitivity, the bot will set all incoming messages to uppercase regardless of the original state. We will also split the command name from the prefix.

 let args = message.content.substring(prefix.length).split(" ");
 args[0] = args[0].toUpperCase();

Listening for a Command

Since all commands start with the percentage symbol, we can set an if statement that will execute if the message starts with it.

    if(message.content.startsWith('%'))
    {
        switch(args[0])
        {}
    }

Creating Commands

Once the command has been activated using the percentage sign, we will then list commands using a switch statement and a case name. In this example the command name is Website and it creates a new Discord.MessageEmbed object which has its own attributes such as description, title, and url.

    case "WEBSITE":
        const newEmbed4 = new Discord.MessageEmbed();
        newEmbed4.setTitle("Echo Crew Website");
        newEmbed4.setDescription("The Crew's Website");
        newEmbed4.setURL('https://j4ninja.github.io/Echo-Crew-Website/');
        message.channel.send(newEmbed4);
        break;

Random Number Generator

Randomizer type commands grab a random element from a fixed array filled with data. The RNG is simulated using Math.random() which returns a number between zero and one. We will then multiply it by the array's length and then round down to remove the decimal.

 var games = ["League of Legends", "Hollow Knight","Divinity", "Devil May Cry"];
 message.channel.send(games[Math.floor(Math.random()*games.length)]);

Playing Audio in Voice Channels

First we check that the user is actually in a voice channel upon initiating the command. Then we grab the voice channel ID. Then the bot will join that channel and play the mp3 file stored in an audio folder and leave when the audio is finished.

 if(message.member.voice.channel) {
    voiceChannel = message.member.voice.channel;
    voiceChannel.join().then(connection =>{
    dispatcher = connection.play('./audio/GHETTO.mp3');
    dispatcher.on('finish', finish => {voiceChannel.leave()});
 });

Trigger Words

Instead of checking for the percentage symbol at the beginning of the message, we will search through the entire message and see if it contains the trigger word.

 if(message2.includes("LOLI") )
 {
    message.channel.send("", {files: ["./images/FBI.gif"]});
 }