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
herofunction/file (I believe you know the meaning of argument by now). - Use the
herofunction/file to send a message in discord.
- Your
testcommand will receive an argument, so for example, it would be orange (so you would send-test orange). - Your
testcommand 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,
argsis an array with additional words after your actual command (this is how yourargswould 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
0th part of the array (hence why I putargs[0]in the conditional statement) - I look for
orangeword in the first item of the array. - If its there, then your
herofunction would be called. - Notice that the I am passing the
messageproperty to it, that's because yourherofunction would need to use it to send messages in discord channel(s).
- Now to make this work, you would need to modify your
herofunction 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
herofunction fromtestfunction as you have seen in the previous section of the code. You need to put it (message) inherofunction 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.