Skip to content

Instantly share code, notes, and snippets.

@Muntasir2001
Last active May 31, 2022 21:26
Show Gist options
  • Save Muntasir2001/92b7ee4ca98a88750dee4ccdc6113fd8 to your computer and use it in GitHub Desktop.
Save Muntasir2001/92b7ee4ca98a88750dee4ccdc6113fd8 to your computer and use it in GitHub Desktop.
Args explanation for Oranginio

Now that you have created hero file with hero function inside it, let me tell you the main goal of all this:

  1. Its for you to understand how arguments work.
  2. Its for you to understand how to make the help command you were talking about.
  3. Its for you to understand how importing and exporting in JS work and the meaning of it.

What we are trying to achieve here is:

  1. Set an argument to trigger your hero function/file (I believe you know the meaning of argument by now).
  2. Use the hero function/file to send a message in discord.
  • Your test command will receive an argument, so for example, it would be orange (so you would send -test orange).
  • Your test command file/function should listen for this argument (orange), to do that, you need to use if else statement. So your if statement would look something like this:
if (args[0] === 'orange') {
  hero(message);
}

What is happening here? Well let me explain:

  1. As you have known by now, args is an array with additional words after your actual command (this is how your args would look when you use, for example, -test orange apple: ['orange', 'apple'].
  2. In your case, this is how your args would look like: ['orange'].
  3. Since its an array, I have to read the first item of the array.
  4. Arrays in JS is zero indexed, meaning to read the first item, I have to reference 0th part of the array (hence why I put args[0] in the conditional statement)
  5. I look for orange word in the first item of the array.
  6. If its there, then your hero function would be called.
  7. Notice that the I am passing the message property to it, that's because your hero function would need to use it to send messages in discord channel(s).
  • Now to make this work, you would need to modify your hero function a bit. This is what you would need to do:
function hero(message) {
  message.channel.send('Hello, I am testing this command');
}

Do I need to explain this as well? Just kidding I will.

  1. You are sending the message property to the hero function from test function as you have seen in the previous section of the code. You need to put it (message) in hero function in order to use it (message) in the function.
  2. Then, you use it to send a message in discord.
  3. If all went well, your bot should send Hello, I am testing this command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment