Everything u need to know about SLASH COMMANDS! (the full guide) | discord.js v13 tutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to the second part of the slash commands tutorial so in this video i'll be teaching you the base idea on how to create your slash command and most probably i'll cover everything but yeah um let's get right into it so before we start i would like to teach you guys how to open discord.js documentation so um let me just all right open this okay so normally the link is discarded g you discord.js.org type it in and then you get these stocks but this is actually uh the version 12 because it is on the stable branch so all you need to do is just click on docs settings click on stable and just click on master and now you're on the development branch so now you can have access to the slash commands and yeah all right the next thing i want to teach you guys is the uh the default method i'll like talk more about that so let me just go to the events if you haven't watched the past video part one uh just click i just watched that video first or else you wouldn't understand anything about this all right so this is what we made in the past video so you can see i did a weight interaction.defer okay so this basically means that um a normal interaction okay let's just restart it from the start a normal interaction becomes unknown in three seconds so if you see an error something like unknown interaction it means that the the interaction has already been expired so basically um interaction of d4 basically gives us another 15 minutes to respond to this interaction we can make a edit reply we can make a follow-up so let me just show you guys what interactional developer is so let me just go to the slash command ping.js okay so i'm just going to remove this so you can see what interaction.differ actually is let me just remove that and save the file okay the bot is up okay so if i go here and i do slash test okay as you can see this youtube tutorials is thinking this is the uh deferred reply so let's say you don't want this to be um seen by anybody so you want the only the author who use this command only can see this so it's a very simple fix all you need to do is go to the uh interaction event interaction create also remember to change interaction to interaction to create i mean interaction create which is uh the newer version so uh you just want to come in defer in here if you want it to be only available for the author to look you just do appromo which is only alter and true if you save this and we go back into the discord if you go back into discord okay and we use slash test as you can see here only you can see this uh let me just try to zoom this in let me just close all this okay let me zoom this in so you can see it a little better let me just close this all right uh this is the readout permo and this is with apparel but there's a downside to both of these so basically when you follow up a message it's gonna inherit the uh a perma value so let me just give an example so interaction dot uh follow-up all right and then uh let me say content will be hello world uh if i can type hello world okay that works what whatever okay hello world so if i go back into discord i try to do slash test is going to say hello world in apparel all right we can't actually change this to uh like a perma files it wouldn't work it's just gonna inherit uh the properties from here all right the same thing goes with the apparel if you change it to false in here let's say you put it false in here okay and the follow-up okay this follow up over here it's also going to inherit the properties which is going to be available to the public so if i run slash test to do that again the bot is probably starting up okay as you can see here hello world is now available for the public all right the next thing i want to touch on is what if you don't want it to be you tutorials is thinking you want it to be a different kind of message it's a very easy way we can do this we can instead of putting in defer we simply change this into reply and then we can just pass in the content whatever we want we can see like um i am calculating or whatever you want okay we can just save this and we can just test this out let me just see if the bot is ready all right it's ready and if you try to do slash test as you can see here i'm calculating and hello world so let me just remove this so you can see that it clearly oops all right okay so if i go in here and i do slash test as you can see here okay i am calculating so this is basically the message for here this youtube tutorial is basically replaced with i am calculating all right so that is pretty straightforward and then the reason that we can't use reply in here so we can do instead of interaction of follow-up we can induce interaction.reply is because we already reply to the interaction over here same thing it goes to defer if you just differ in front over here you can't use reply at the back you only can use edit reply or follow up all right the next thing i would like to show you guys is how to use options in your commands so let me just go to recon dev and let me just use a previous slash command that i have so let's just say add bot so as you can see here there's three options over here prefix bot id as well as description all right so let me just get right into it so if i open the docs right now uh the documentation and we can just go into search bar aptly we're gonna search for application command data all right in here and there you can see that uh there are some options which is name uh description options all right so application command data is basically this thing over here this is what we're exporting uh excluding the run okay we're gonna export the name description and we can add options so options is basically this these are the options the prefix bot id description or our are all those are options so uh we can actually come here we can do options and then uh let me just open it docs again okay if i go into options okay there's a type a name a description required choices options okay i'm just this is very uh like most probably you won't use this but this is only for if you want to use sub commands which i'll cover later on on this video so let's just focus on one two three four four of these so we can do name so this is the name so let me just open this card again this is the name so we can just name this as uh let me just change this command as send message send message and then we can change the description to send message to a channel okay so um the name we're just gonna say uh what is the message and then type okay type there there is a few types that you can choose from um let me just go in here okay as you see your application command option type there's a sub command which i'll cover later on this is basically the same strings as you know strings integral numbers boolean true or false user is basically you can mention a user i will cover that also channel also i'm going to cover it later and then roll also you can mention the row all right so the thing we're going to use now is string let me just do string in here and then uh we can choose our options if you want it to be required or not required so we can just choose a required and i can just make it false for now all right so let me just add a comma in here and let's just start the bot up invalid form body oh okay so make sure you have a description in your options as well so just want to add description [Music] in here so let's say uh what is the message content let's save this up and let's just test this out all right let me just go back to the server and then we can just do test oh it's send message okay as you see here optional message optional can you stand a message with a optional oh i forgot to do something we actually need to get this message so very simple you can use the array restructuring method so cons array is equals to arcs equals to arcs all right so in our options section is basically going to follow the options order so if uh you want to get the first one so this the first one is going to be the message that we want to send and then we can just do interaction dot channel dot send and then we can just oh actually we can use oops what am i even doing interaction dot follow up and then content will be message okay hopefully that makes sense if you don't understand anything feel free to possible uh people in there will help you so let's just save this and let's just see if it actually works so send message and then we can just pass it a message like uh hey there or you can just use sub to recon okay as you can see here it says sub to recon okay so this is a very basic example so let's say you have a few things that you need to choose from so let's just get right into it um so here is where we use choices so for choices uh it's actually pretty simple as well choices okay and then there is a name and a value so let me just show you it's a um a an array and then the name will be what is displayed in the uh option section so let me just say you want to send a house address or we can just say country okay and then we can put in the value as uh uk or whatever it is all right and the next choice we can do something like uh h and then we what am i even doing name and then we can do h and then we can just position value and then you can pass it in um 17 whatever it is all right so the choices basically are in here so uh we can just go back into discord and just show me let me just show you what's going on send message and then um okay if i go in message you can see there's two options for me but if i click on country okay it's not gonna send country it's gonna send uk so the arguments um it's basically gonna take the value it's not gonna take the name so keep in mind so if i change the country to uh united united states and i save this okay and if i try to run this again send message and i can pass in country okay it's gonna say united states hopefully that makes sense until now um i'm just gonna get a little more a little more advanced so basically we're gonna create a command that we can send a message to whichever channel we want which with whatever message we want so basically we're just gonna choose a channel and we're going to choose a message so let me just remove this we're not going to use this anymore perfect so as you see here the first option is obviously going to be name which is going to be channel and then a description oops why did i do that description will be channeled to send two okay put it whatever description you want and then next will be required if this is actually required so we actually need a channel to send uh the message so it's gonna be true and then choices is we're not gonna use choices we're gonna use type okay so let me just open the documentation again uh where's the choices okay what am i even doing type its types okay so we're going to use the channel okay we're going to use channel and then we can just present a string make sure it's all capitals and we can use channel okay so this is for the channel next thing we're gonna do is we're gonna find uh we're gonna register our message so name let me just do message uh description we can just do a message content to send or wherever it is required true because we need a message to send type and then we can go back here we can use anytime we wanna in this case i'm gonna use a string okay okay in here now it's gonna be a little different so as you can see here the first one is the channel and then the second one is a string so i'm pretty sure this returns a channel id instead of the channel object or class so let me just do columns channel and then next one will be message okay make sure to follow its order so as you can see the first one is channel i put channel in here message message and then we can actually console log both of these out to console.log and then we can just do channel and then comma message okay so let's just test this command out and just see what it locks out uh send send message and then channel uh we're just gonna do we're just gonna use the command because why not the same channel you're just gonna use this channel and then message we're gonna just say hello world and then let's just see what it logs out okay as you can see your channel it actually passes the id so we need to get the id i mean we need to get the channel with the id and then we must send the the message inside the channel so it's actually pretty simple to do this uh all we need to do is cons channel equals to message.guild.channels the cache.get and you can pass in channel in here oops call to change this to channel to to send because we already defined channel in here all right so channels will stand it goes to messages will give the channels across the channel so this is basically the channel id in here and then we're actually gonna send the message in here by doing channel to send dot send and then just pass a message in here so let's just test this out let me just create a new channel uh channel okay this random channel over here move it up to commands okay so if you're trying to do send message and then channel i can use the this random channel over here and that message will be uh subscribe to recon okay um something else wrong uh mr channels oh it's not messaged or guilt it's actually interaction or guilt my bad interaction again the channels to hush again yep it's interaction of guilt all right so let's just attach this again uh same channel channel blah blah blah and then you subscribe to recon okay we actually need to send a follow-up message so let me just i'll show you guys how to do that later so as you can see here it actually stands subscribe to recon in this channel over here so uh we can just do you can use that actually you can use a dot then function okay and then we can just do interaction dot follow up and then uh we can just do content [Music] um send the message okay we can do that and then let's just send another message just to show that it actually works this channel and then we can just say it's random message over here okay as you can see here send the message and if i go to this channel i can see the message over here okay let's just implement the choices uh options again so i can show you guys how to use the choices options so in here we're just gonna do choices and then uh we can just say name if you want to choose itali and then a value will be itali is the winner and the next thing in here you're just going to do passing name england and then value will be england is the winner all right so um so basically now we can't choose our own message we only can use these two choices over here so let me just do send message channel will be the same channel over there and then as you can see here it's only giving us two options so let me just choose itali okay and as you can see here italy is the winner all right the next thing i want to talk about is sub commands so basically our sub commands is let me just show you with tank memer bot okay as you can see dang mimer has tons of sub commands so basically sub commands is a slash command but with two words so as you can see your slash image pet pad uh slash image magic so normally you only can have one word but with start commands you can have two words all right so let me show you how to use a how to make a slash a sub command so uh the first thing you want to do is you want to go into interaction create and then in here here's the uh part you want to change so instead of directly pushing it we're going to check if the rd uh it's actually existent so we can do the xl value that only will push and then the next thing uh is the x dot name so x dot name and we're gonna do rx.push and then we can do x the name all right perfect and then in ping um we can actually remove all of these because we're not going to use it anymore all right so we're just going to do options again and then uh it's going to give us a type okay so for now i mean for this we're going to use the sub command type so let me just copy this pass it in here name okay so basically name is what the sub command name is going to be so let me just show you with that mirror so basically this name is pet pet this name is trigger and this name is slap okay so in my case i'm just gonna say um [Music] euro winner the winner of euro all right and then um you can give it a description i mean that's required so description why you keep done what does it keep doing that okay this i need to type in myself okay description uh get the winner of euro 2020 okay and then yeah that should be it okay make sure to add a comma in here and then um if this command is run we're gonna set uh we're going to set a we're going to send the message so interaction will follow up content uh itali is dominar okay so um you make sure your name is also lowercase so just change this name to lowercase euro winner okay go back in here slash send command send message and then you're passing a channel what that's weird let me just create a new command um get okay let me just call get and do slash and as you can see here actually gives us the get euro winner so we actually can't use the get and then we can use other options we only can use sub commands because you can get euro winner and then uh you get the winner of euro 2020 so if you use this command here you say itali is the winner so let's say you want several um sub commands so if i use decliner once again as an example okay there's tons and tons of sub commands really simple we're just gonna duplicate this so we can just copy this and you can just paste it several times okay but we're going to change this name up here so we can just uh get um best and then we can get or we can actually get second place please other favorite okay and then we can get uh in here you can just get uh get favorite subject or whatever it is okay so let let me show you guys how to differentiate between the different sub commands so in here instead of directly sending a message we're going to check which sub command it's coming from so we can just do const same thing array and then here is going to be sub command and then uh equals to arcs okay so basically sub command in here if you use the euro winner the sub command is going to equals to your winner if you sub second place and then uh the sub command is going to equals to second place and then if you use favorite sub command is going to be equivalent to favorite all right so we're going to use a few l a few if statements so yeah let's get right into it so if subcommand is equals to euro winner we can just do return interaction [Music] now follow up content itali and then the next thing if actually you can just copy this it's going to be way faster okay if command is equals to a second place and then we can just say england in here and then lastly we're gonna do um same thing and then in here so if you're winner we're just gonna pass in favorite okay and then here we let me just do maths because i don't want to stir up any drama okay i'm just going to put in math okay so let's just test this out if i do slash get okay as you can see there is three slash uh three such commands you get euro winner is going to return itali get second place england and then lastly if i do get favorite it's gonna be maps okay you can use your slash commands however you want this is just a few examples teaching you guys how to use slash commands so this is yeah this is the basics of the slash commands video alright so if you have any more questions about slash commands feel free to join the support server links will be in the description if you want to watch more discord tutorials you should see a place that you can click on on the screen right now just click on that there's tons and tons of tutorials on that have a nice day see you again next video bye
Info
Channel: reconlx
Views: 13,115
Rating: undefined out of 5
Keywords:
Id: EN7LH89TUN4
Channel Id: undefined
Length: 24min 38sec (1478 seconds)
Published: Fri Jul 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.