Slash Commands Handler | Discord.JS V13 | S3 / #6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a couple of you guys have been asking me for a discord the uh support server so i'm gonna link this discord server this is my commented server uh in the description please be respectful in here guys because this is not made for this yes it's my own community so if you join it in the discord.js support channel here you can ask me if you ask me in any channel else other than this i won't be responding to you yo what is up guys and welcome to this episode of how to create your slash command handler in this episode i'm gonna be transitioning our old command handler that we created in the second episode of the story series and i'm gonna be transitioning all of the commands that we created previously like the avatar command the user info and the ping command to work with this slash command handler so if you only want to slash command hunter just follow along until i create it and i will tell you when to stop but if you also want if you did follow along this storage list and you created the commands that we created in our previous episode then i encourage you to watch how to transition your commands to work with the slash command handler because we're just going to be deleting all of the message commands because this is the old this code we're going to be transferring to the new discord so before i do anything guys uh this could this or js sorry version 13 won't work with the old node model so what you need to do is actually download the latest version of node.js to be able to work with slash commands and all of the discords in your futures you click on this basically you don't need to remove or delete the old node.js program from your pc you just basically click on next next next and it will delete the old one and will install the current version so now that this is out of the way and i also have to tell you that the slash commands won't register if you didn't invite your boat with the application.commands scope so if you haven't done that while you're inviting your boat you should kick it and reinvite it again with the applications dot commands scope the both and the administrator and before you follow along this story i need to make sure that you guys are on the right page all right so now if we go to our visual city code and if you go to our index.js file we're going to be changing a couple of stuff so the first thing i'm going to be changing is actually the the names of the files of the handlers from command hunter i'm going to change it to be only commands from events i'm going to event center i'm going to i'm going to name it to be events same thing we need to edit it over here in our index.js file and this is important because otherwise the handlers won't run right now this is out of the way we're gonna remove our client.cooldowns collection remove it because we won't be needing the cooldowns all right so also now we're gonna be actually copying the required discord.js all right we're going to be pasting over here based on it over here we can obviously add the equals we're going to remove this discord and we're going to remove the entrance and we're going to exchange it with the client all right and now that the intense here we're gonna remove this array all right and instead of the array we're gonna add the actual numbers and the numbers let me shake what they actually were so i'm not mistaken give me a second so the numbers are going to be 3 2 7 6 7 3 2 7 6 7 which is gonna allow us to use all of this words intense to our boat so we don't have to clog up your index with all of the indents that you need i'm going to leave the calculator in the description so you can if you want to uh to only have a select number of intents you can use that calculator all right so now we're going to remove the discord dots because we won't need that because we already clarified what the client is actually is and then under that line we're going to create a new line we're going to type model.exports and we're going to export all right other than that this is how your endings.js file should look like if you were following along our series if it's not you can just make your changes on your own discord server layout all right now that is done we go to our events uh folder we're gonna remove the message folder because we won't be needing that all right and then uh we go to our commands we can remove the emitters we can remove the motivation and this is the only commands that we're gonna be transitioning to our new slash command handler all right so let's actually start the transition so in the command handler we're gonna go to the command header file and we're gonna actually edit a couple of things [Music] uh um make sure uh if you're using my command header this is how your command and the file should look like so what we're gonna be doing is now actually creating an array we're gonna do that under this line number six we're gonna type const commands array equals to we can create an array object right and then over here below the client.commandset command.name and the command set we're gonna push the actual command file to the array so commands commands array push we're gonna push that to my file itself then we're gonna go down a couple of more lines and we're gonna type client dot on ready we're gonna create a quick error function we're gonna here type client dot guilds dot um cache dot get we're gonna leave this string empty for now and then we're gonna type dot slash dot commands dot set we're gonna pass in the commands array so what you're gonna be needing to place in this quote is the actual um guild id that you want your commands to be displayed in i recommend and this one recommends using guild commands instead of global commands because for global commands it takes time to update them and create them right now that is done let's create that the excess lines over here right so now we're done with our um changing some of the command handler stuff um and now we're going to create an actual event listener so we can listen to the actual interactions so it's straightforward we're going to go to the events we're going to create a new folder we're going to call it interaction or depending on your event handler you can do whatever you want we're going to create the file and to be direction create we're going to copy that name.js and then here we're going to model with exports and the name of the listener is going to be interaction creates then we're going to put a comma over here we're going to go down one more line and we're going to type async execute and move this we don't need it has execute and then here we're gonna pass in um lines in direction all right and then we're gonna open this up open up this bracket i don't know what's happening with my keyboard today and here we're gonna check if the interaction is command so it in direction dot is commands we're gonna open up these brackets we're gonna here type await interaction and therefore reply it's gonna be see under this bracket is gonna be put in the middle and if let's see how this is actually called i'm guessing it's so i don't know it's not auto completing for me but i'm pretty sure it is right and then we're gonna if an error happen we're gonna catch all right you're gonna catch error we're gonna pass it to an empty object we're gonna go down one more line and we're gonna type const demand equals to blind dot commands dot get we're gonna get the actual interaction command name and then we're gonna check if there is no command by that name existing in our command folders uh we're gonna follow up with the message saying this command does not exist so return uh interaction follow up and the content is gonna be content this command no longer exists all right we're gonna and and actually here we're gonna add uh and option we're gonna remove the actual command from the collection so client command dot delete we're going to create the interaction dot command name so so other people don't have to use the command if it doesn't exist and then here we're going to command dot execute a client and interaction we're gonna close up this line over here and we should be done with our event listener all right now that is done we can actually this is the actual slash command handler guys and now that we're done with this we're gonna transition our uh previous commands that we created in our tutorial series but if you only needed the slash command handler this is it uh this is my event handler this is my command handler and this is the event listener so if you follow along uh the second episode of this show series you should have already these files set up all right so now if you go and let's change the actual avatar command first because it's it's the simplest and so what we're going to do is we're going to actually get some parameters we're going to tap on lines [Music] and um sorry it's actually called command actually let's just require the package to it it also completes this for us required just for the js right so it's going to be command interaction and then here we're going to record the message inbit all right the analysis we can remove the description we can leave it as it is and here we're going to set the options and we're going to make it an sorry like this and i'm gonna put a comma at the end of this line so here we're gonna type the name or the first option target and the description remove that this is gonna be uh select uh target uh the type of the option is going to be accept the user let's put the comma then this line and then here we're going to make it required so required set the true and this should be it now we're going to get we're going to remove this message also we don't need that no more we're going to pass in the client and then the introduction and then here we're going to create our parameters that line is going to be clients and for the interaction it's going to be command interactions we can auto complete our commands and the target is going to change uh it's going to be const target equals to um let's see here interaction dot options uh so get we're gonna get the user object user from the target option let's see my keywords having some trouble and we don't need the discord number because we already defined the messaging bit we required it from the package directly and he requested by message also dot tag this is gonna change to be interaction.user.tag and the message replied is going to be changing to be in the direction don't follow up and this should be it for the avatar command now for the ping command it's going to be the same basically the same thing you don't need to set the parameters because it's an easy command so message channel send is gonna be introduction dot follow up not interaction create the interaction and here we're going to execute we're going to get line and introduction we can remove the cooldown we're going to remove the permission we're going to remove the elastic um and this should be it for our pin command basically um yeah i'm pretty sure this is this should be it for our pink command now we're gonna transition our user information uh commands it's quite a lot so we're gonna go to again let's close all of these files we're going to go to our avatar and we're going to copy this on the options down to the parameters all right so we remove the license like we did we're going to put paste this in and we can also copy this and paste it over here uh all right so now let's see we're gonna remove the execute uh arguments and stuff like that we're gonna pass in the client and interaction simple simple and now we can remove a couple of a couple of stuff over here so what we're going to be removing is these two lines we're going to type bones target equals to interaction dot options dot get we're gonna get the actual member not the user object from the target option all right and we're gonna be changing a couple of things here message.reply should be interaction.follow and here we're going to change a couple of things because this is a member object the user the target user that we use here is going to have to change so instead of the target.user name it's going to be targeted user same over here target.user and same with the subnet all right now the target ids should be targeted user id at target i mean member rule should be target rules um and we can just remove this because i actually now want that at everyone to be in the map um the member will join that should be target to join that same over here and the target that created that should be target.user create that user and the mistakes are going to happen we're going to error handler mechanism right now now we should be theoretically done if we start our boat it's over here yeah we should remove this from over here guys same with the events if you have discord passed in here you can remove it same over here if you have a this will pass in it should remove it so note dots if you go to the discord server and if you type slash we should see our board pop up here to the left directly and we should see the commands that we created so let's try the ping command it should send us but it taken some time that means the error has happened so if you go here interaction is not a function uh let's see what's the error here let me figure out everyone will come back to you guys right so the issue was pretty simple guys it was an honest mistake if you go to the commands if you use a ping command and uh you see we haven't defined the message input so we removed this discord built and we did we get the message input from the discord package required and another quick critical error that we didn't um think of is we actually have to update our packages i forgot to update in this boat so you go to your terminal and you type npmi discord.js without the dev because it's actually version 13 is actually released now and yeah your command should be working right now so let's try them out yeah so node notes all right the bot is now ready if you go up to our uh discord board i mean this will save it with the type slash you should see that both options let's try the pin command dot slash ping the pink should return let's write the avatar command you see it will require a target and it will fetch the members of the guide members you can search for yourself too but like let's take place for example now you see uh it gives this avatar now for the user info with type dot user info i'm in the slash user info we're gonna select the target and we're gonna get the actual information of that user that we made as a target so this is it guys it's pretty simple and straightforward i hope you like this episode and tune in for uh the future episodes and see you
Info
Channel: Lyxcode
Views: 4,616
Rating: undefined out of 5
Keywords: discord, discord.js, discord.js v13, discord v13, discord slash commands, slash commands handler, discord.js commands handler, slash commands, discord.js v13 slash commands, discord.js interactions, discord.js v13 update, discord bot, discord.js command handler
Id: huflDTsF-Xs
Channel Id: undefined
Length: 17min 16sec (1036 seconds)
Published: Tue Aug 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.