Now that you have created hero file with hero function inside it, let me tell you the main goal of all this:
- Its for you to understand how arguments work.
- Its for you to understand how to make the help command you were talking about.
- 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:
- Set an argument to trigger your
hero
function/file (I believe you know the meaning of argument by now). - 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:
- As you have known by now,
args
is an array with additional words after your actual command (this is how yourargs
would look when you use, for example,-test orange apple
:['orange', 'apple']
. - In your case, this is how your args would look like:
['orange']
. - Since its an array, I have to read the first item of the array.
- Arrays in JS is zero indexed, meaning to read the first item, I have to reference
0
th part of the array (hence why I putargs[0]
in the conditional statement) - I look for
orange
word in the first item of the array. - If its there, then your
hero
function would be called. - Notice that the I am passing the
message
property to it, that's because yourhero
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.
- You are sending the message property to the
hero
function fromtest
function as you have seen in the previous section of the code. You need to put it (message) inhero
function in order to use it (message) in the function. - Then, you use it to send a message in discord.
- If all went well, your bot should send
Hello, I am testing this command
.