Coding Your Own Discord Bot - Discord.js - Kicks and Bans

Coding Your Own Discord Bot – Discord.js – Kicks and Bans

Views:7271|Rating:4.85|View Time:29:52Minutes|Likes:94|Dislikes:3
Help to support the channel if you are feeling super kind:

Join our Discord:

In this tutorial I teach you how to implement a kicks and bans system for your server using a Discord Bot.
If you liked the video then please respond with a like and a subscribe to show your support for the channel and I’ll repay you by creating more tutorials like this one 🙂

okay so hello and welcome back to another disco bot JavaScript tutorial and this one we're gonna be covering two or three different things depending on how much time we have how the video goes on the two things I definitely want to cover first of all changing the BOTS status so that as you see here it just says tutorial bot but if you're going to my main server which I'd recommend joining links in description if you haven't already got all these channels all these people given help one thing I wanna mention about the server quickly is please anyone who joins some people just join and end up sending screenshots their problems where there's red underlining x' that the whole point in the red underline is to tell you you know there's a problem here and generally if you have a red on the line and you mouse over it it'll tell you what the problem is or like just simple like bracket errors or typing like typos like from now on we're probably not going to really respond to those because well put in time to help people who have like genuine problems but some people just either don't watch the video properly or they come and try and make something like a discard bar without any programming knowledge all now I know it's a beginner series but that's more of like beginner series and making like this isn't a series on how to learn JavaScript like if you want you go in some JavaScript basic tutorials or Python or C sharp or basically any programming just learn the basics of programming first Kazu just make life easier because some people just come and copy and paste the code or they just type it what letter for letter and then the end up getting problems and not understanding what half the code does or any of it all so even though we are here to help you we're here to teach more so than help so we don't want to just copy and paste your code and just give you oh this is the problem we want to say you know I'll read the error message your problems here you know it tells you what the problem is so try and fix it it's a lot better so that's that anyway if you look at our bot we have a thing under it the stateís so like if someone's playing a game like this guy playing black so on the bot is playing and you can change it from playing but there's a few default there's only like four you can choose between I'll go on to the documentation to show you so you can choose a like status I put it as a question mark commands so that's the command for getting commands if I just like go down somewhere and I put like commands high-def a dyno sent you finger those commands there you go and you know here's all the commands basically like what they are and what they do so kick admin only kicks a yeah I've already got the kick command there so we're gonna add the stateís obviously moved up add a note whatever you can do what you want so we're gonna do that first then we're going to do kicks and buns so I'll just make a kick in a bun command for admins only obviously and then if I have time I'll cover the same idea that I've got with the suggestions in the main server so you can do the suggest command and leave a suggestion which gets saved to a text file kind of thing just showing you how to do all that but first let's do this so so we want to do the status now you can set the status wherever you want but you want it to be there when the box starts the problem is if you set it before the bot comes online properly it's not going to set it so you want to make sure the bots in online and how do you know that happens well when it happens it calls the bot Don ready event so remember these are events so like this gets called when the bots ready this gets called when someone joins a server if you want to go look at the list of those then obviously you can go in here and you search events you get WS event type here all the different ones so these are all the different events these get called at different times so ready resume whatever I don't know what all of them do but you can go you know if you find them I think it's like client dot on you'll find it somewhere on here it's probably client yeah so like here all the events so if you want to know what one doesn't you just click on it and you'll say so like guild member add when a user joins the guild so on and guild is what this code called service so we want to do it when the bots ready so here we go any code you type in here the bottle be ready at this point so we want to set it status and that's quite simple to do like this is the easiest part of video so what you can do is you can first of all it's a very easy command called white dot set activity so I mean I might start going through the because people don't seem to know how to use of the documentation like what'll happen is they'll have a problem will link them to that part of the documentation then they'll say I don't know how to use documentation so I'm going to use alongside the videos to explain how it works so we want to say activity now I guess you don't well you know you're saying activity certain activity oh look activity type now this doesn't really tell you such that just says like the four kind so if you do a dot set activity client user dot set activity so you see here it takes in a name which is compulsory and anything in the brackets in here means optional so and then you say here's an example so this is this is really helpful for the URL now as you see here for the options you can pass in a the actual thing old URL blah blah blah what type you can mod you can modify this quite a bit but let's go back to our code I want to make sure I keep going to the right one because once for the bot running in the other server so we want to do as you see it like this is okay so we have a client so this is bot remember client is what they call it we've called it but if we call the client and whatever so dot user dot set activity we have called it but haven't we yeah what dot user's activity and then if you see here it says well name string so in everyone the name string thing is just it's what it says under it so what do you want to do I'll just say F city to like teaching my viewers whatever you can put it what you want then comma and this goes to the next bit so this is the options now you put it inside of an object thing with the curly braces and you put what was the different things you can have you can have a type well it's a URL on a type or a type now what question mark means after the things is it means they're optional so you can have them or not see you have to have an options but I'm gonna have an options so I'm gonna have what type is so we'll put type you just put this back now we don't really as you see you down here as well the thing comma at that so let's let's put this back up there so what type should we have there's four different types if you remember correctly so I can just go show you that as well activity type we have playing streaming listening and watching it just you know doesn't matter what it is just what if you want it to say so I could say like playing this streaming that whatever so let's just put it as playing playing even gives you the options there to be honest I don't know if you need it in all caps I think it wants it in all caps it might not matter but playing so now if we go run the bots after saving that's another thing loads of people having having problems and it just because they don't save their code which is quite silly because you should just do that anyway to be honest in my opinion I see here but playing teaching my views I know I sound stupid but that's it you know you can set a status we can tweak that to be what everyone we could say streaming whoops no done so you could just set it say that and then go back now hasn't updated yet but it will today so see here it says live on twitch teaching my views so even though it's not true and so get it say what you want so let's put it back to play okay that's the first ball to video let's move into the next bit so the kick and band commands so let's go create a new command let's create a new folder in here called like admin and then inside admin we'll add a new file called like kick doc j/s okay and we'll just take one of these and copy it she that's probably the best one to coffee because it's got loads of let's let's take a simple one yeah that's a simple one to copy and paste okay let's just quickly do the normal stuff so kick command kick command then we'll just get rid of all the code inside here for now and then name kick so the command is like question mark kick it's not simple it's in admin and I'll just put like kicks a user okay and then the last thing we need to do for this is go back to our index finger we've got a new folder that we're putting commands then we need to do what dot registry dot register group and we've called it admin so like so so now it reads commands from that folder as well it's just to keep it nicely organized let's go into admin so here's our kit command now I'm gonna be making it the exact same way I made my the kick command for my other server to be honest it's the same command is pretty simple so what we need is we need to use augs because args is obviously the arguments we get back and we're gonna we're gonna format the command like this so let's say I have my friend in here I just invited him he's obviously not online now but I can still kick him so if we do that we would want to do question mark kick at the terminate for that that's what we want to do now it's not a command so it's not going to do it yet that's how we want to do it so we want kick and then at the person so first of all we need to get the person that we're kicking so we'll say what it kicked user equals and then we want to get the person that we've acid that we've mentioned so the way you do this is you just say message so the message that I sent dot guild so the server is sentient don't remember and then this means like we're going to be getting a type of member from the server so this is like when I put something in here it's kind of like searching the server for our members to find this person so if I just did remembered and I could put in like type name and then they got that guy but we want it to be depending on who we mentioned in the actual command so we'll say message dot mentions which basically you know who you mentioned dot users so it's like got a list of users and then we'll just do dot first which basically means that if they like mention multiple people in their command it would just get the first one but they should only do one anyway so there we go this kicked user variable has reference to the person we mentioned like their user object then we're going to do check we're going to say if not kicked user me if they don't add someone if we basically saying if kicked user is equal to norm or is equal to false or is equal to you know if it doesn't exist we're gonna do this so we're just gonna say like message dot channel dot send and then we're gonna send what we're gonna send we concerned something just like sorry I couldn't find that user and then what we can use we can just do return which means that it then breaks out of the whole command we don't want to do any more I'm do another check I want to say if and we want to check for permissions on the person that did the command to make sure their admin because if they're not admin we don't wanna do it so if message dot member dot has permission and as you see here these are all the different permissions you can check for there's as you see 21 more it won't just tell you on here but if you go to has permission member has permission just permission permissions well it was a list of them there's a list somewhere of the permissions just go back for a second I don't know where the big list is of all the permissions it doesn't really matter to be honest unless they're on here oh there we go yeah these are all the different things you can check for all the different permissions so you want to say basically if they have the best one to check for is managed messages because that's that's what everyone seems to do and it's the one for and it's one of the admin related things so we'll put manage messages so if they do not have that sore point exclamation mark if they do not have this then we want to say to message dot channel dot send you don't have the privilege is to kick of the users that kind of thing and then we'll return and then these are the two things that stop us from doing the command now we want to actually do the command so we can do we can just kick them now to be honest or we could like do a nice a little thing in the channel we'll just kick them first so what now you need to do is you simply need to do oh and also need to have a reason we could do a reason to so basically yeah let me just console.log args quickly I'm just going to make sure whether args is does think includes the game lost so yeah it's just the hogs zero because eggs is a list so it's a list of all the things afterwards so we want to basically ignore the person and then just get everything after that so what we can do is we can say say something like let words equal AG stop split no wait eggs is also is already a list so I'll say let reason equal and then we can say word no sorry it's args dot flies and then we're going to say where they're gonna slice from so we want all the words after after and including 1 index 1 because index series thing so then we'll say dot join I want to join it with spaces that should be fine let's go check out quickly so console.log reason no dot so we're gonna go and say we want to kick that person for like bad language or something like that okay arrgh slice to join how about what what a xargs because let me just comment this out all right KITT app for blah blah blah blah blah okay so yeah it's not in a list it's just a string that is flip at the spaces so we want to say yeah I was right the way I was doing it first is right so I'll support like something like let words he called stop split the gaps start puts it into an array and then we can say the reason is words dot slice one like that and we'll do reason basically we just come we want to get their reason for the ban because when you ban someone you actually send them the reason like if you go to ban someone or if you go to kick someone I think it's the same you have to give them a reason you couldn't leave it blank but so kick therefore bad language and is you down here we get the variable reason is just the bad language part that's good okay now we can finally do the kick bits so we can do message gild don't remember and then the person we're kicking so kicks user dot and then you come run things on them you want a kick kick is a thing and you see all it passes in is a reason and it's optional well we're going to pass in reason like so and then we can just do an error cache in case this doesn't work so well then just console dot log it and then we'll catch that console dot error whoops okay so that's done let's just quickly test this out and if it works I'll do the ban one but we can't prove it because it sees our afk he won't join back but let's just make sure we can kick because it's the same premise for the ban so okay for being bad boom it kicked him from the server and it'll have said to him being bad and as you see here we console along what happened the Gil member here we go so that works that's the kick command done now the reason you might want to actually have a kick command rather than just the kick button it's said that well first of all you can limit like certain people to be able to kick and not burn all this and it kind of means you don't have to do of rolls you could just well they don't have to be admin it's up to you you can do this exactly how you want but the benefit to it is you can actually log kick some bands a lot other than having to go through the audit log thing it's much better different ways of doing it let me just quickly check the time of the video yeah I'm just going to do the band one there nothing there'll be it for today so the band command I'm just gonna copy make him ban J s make a copy make a ban command and command and then we can just just for the sake of keeping it a nice band user bans a user to use it like just changing all this dot ban there you go it's basically the exact same thing to be honest that's that don't think there's anything else to do its ban reason ban command so that's that one you have to ban of the users can put that so that's that come undone actually now is there anything else I really want to mention the last video because because it's the summer holidays I've been quite busy when it comes to videos I've been helping a lot in the disco but I've been doing other stuff as well like besides that I'm some discord ready to help when I've been like I had a free minute when school starts again in like two weeks time when I'm back at school and into like a normal routine and not doing stuff all the time then I'll try and get back to doing daily videos like once a night like 20 minute videos it's not too hard to keep up with obviously just you know be patient to the end of the summer holidays I'll try and get a few more videos out between now and then but I'm really busy so yeah if you want to help support then obviously leaving a subscription would mean the most apart from just watching the videos in general obviously join the discord be part of the community share this stuff wherever you think people might find it useful and yeah so it's not much more so than that if you do join the server you might want to look at the progress of our aambat and our website and stuff we're all working on its like like in development there's nothing you can really do on it yet but we're making good progress on it we've added stuff like connections to API so our own API so that when you do certain commands it speaks the API and when someone adds like an FAQ to the server when one of the admins adds an FAQ it also gets added to the website on an FAQ page so it's all synced up I mean like if I quickly gone to our bar over here make sure I don't show anything I'm not meant to show her like secret codes and numbers and stuff why here people can leave tickets now this office looks a lot more complicated so this is all on a github page anyway we can go if I go to the add FAQ so here's like the FAQ thing for our server right so I'm actually going to run the command because it will wash it I could run the command just the show I'll run the comment well there's I'll comment out this this is the line that basically makes it speak with the API let's just do this bot works a bit differently it's a lot more complicated so I'm just not going to bother going into that at least not right now you can go look on the go page as I've said if you want to see that let's go to the server so if I go to the DEF nano-coating let's just get rid of these this is just me testing earlier so if you look in the FAQ channel we have these FAQ so question answer whatever we want that to be synced up with the website so rather than making our own little embed thing like that we got the bot to do it now what we can do is we can do watch so add FAQ now we're over than doing one of those things we add like thingy and unlike a slash thingy / wingy rather than making that really awkward we have a nice new system that me and Mickey been working on over the last two days and we've got it up and running now it works fine we've got a so I don't think you've sent then the bot responds with like Deford oh no answer question so I'm gonna go enter a question so it's like like how do I do this question mark then it takes away both those things and it says and to answer you simply do this then it asks you what do you like to add a resourceful URL and to yes if so of wizened No now obviously pressing though will just end it and send one of these little embed to the QA like to things like that so let's just say yes yes enter URL okay the this URL here is quite useful right so let's it's polite you are Ellen enter URL mask I just put like this god dot j s permissions send then boom it makes a little embed says how do I do this you simply do this useful resource disgorge a s permission now if I had not commented that line here if I had not commented that oops so if I didn't comment up what it would do is it would run our own API request Handler and it would send it to the API so if I go to up here and I go like Darfur Dino API FAQ just give it a second this is part of like the backend for the website and this is going to be linked up to the FAQ section on the website so any a fake using the server are going to be on the website obviously if any of you hanging around now this is just like an extra MIT's not part of the tutorial as such now I'm hoping it's actually often running now cuz Mickey on the server who is kind of like hosting it he is away currently but I'm sure he just left it off it's just being really slow at the moment for some reason go on everyone's seen enough for the run background while that's loading see it on the website this is how I use the documentation so if you've got something dot something so like let's say you got member dot add a message to offer if you want to look at that that you just do dot author and as you see it comes up with all the things that you can get author of so you can get offer of an embed of a message of a bottom line you can get here gets load L show you in a second so if there is an element or like a thing you want to get so like you want to get someone to user name dot username here all the things can get user name of client user you well I set those two so those are two kinds of data that you can get don't use name from so if you want have a go look at client user it takes you to the client user page but Scrolls you down to the dot username part which means that if you already know the type so you want to see what you have a message dot member and you might want to see what can I do with member well this is all stuff you can do with access to a member you can you know you can check so these are all checks you can say if you put member DFK voice channel it's the afk voice channel for the server there and currently whatever I don't know or whether it's yeah so it's good it passes a voice Channel so as you can see here it tells you the return types so if you did like something dot available then you know also my own guild Yellin guild sorry I was much young member remember skilled member how about if I could guild member and I just say come on there we go so this is this is a member so remember dot burnable if you do like if body blood burnable it does a boolean type because it's whatever that banner ball or not by this by the client user you can check all the stuff it's so useful it gives you everything you could possibly ever need disco duck GS has supposedly everything possible because how it works is discord has certain features and discord is the people who work on it work with the actual official discord API and all that lot and make a nice library for it so you have like simple functions to use what discord is is as a library as a wrapper for the discord actual API because the discord API is just available and people make their own libraries for it to make Karen's life easier so this discord rjs discord py is all the different discord libraries for different languages and whatever discord yes is probably the best meant maintained and most popular so I use it and there's lots of tutorials on it anyway and different things so yeah here's the API looks ugly basically yeah it's a thing on the web and as I add a fake use it adds them onto here so if you look here for example the first FAQ and the thing was something stupid just like why this was like a test one why does this channel show the message you have no permissions because only stuff can do so if you look here it said ID 13 cuts in a database number 13 because we mess around and have some like ones before it description North question why it's the chance for the message you have no permission answer because only staff can do it resource link no no because there's no link then if we go down and look at the I likes to learning c-sharp where I go to this place all right if I go to the here so are you 17 question I'd like to start learning program a c-sharp where to start and sir there's no real answer to this question bold well so if I keep going along where is it here go resource link I've lost day on it it's in its own object and it has a display name of Microsoft Virtual Academy and the actual link of HTTP this that the other it's obviously if I just took that in and when search I missed off the H but this is where it takes you anyway this there's a lot a lot going on a lot of busyness for me to be getting on with I'm still gonna have to see try to help you guys but just understand that I'm a busy person as well I have stuff to do but yeah thanks for the support the channels been growing pretty well I'm almost at the point where YouTube were going to start you know giving me that dollar but it's not gonna be a lot and I don't really care it's just interesting to see that the channels actually got to that point almost it's nearly there so yeah just keep watching the videos that's the most that you can do for me we can do anything you want to be honest but that's enough or subscribing or anything or taking part in the server I keep saying us all the time but you know keep growing the server get a lot of people in here talking about whatever learning coding teaching each other it's just a good community to be path I've liked this video dragged on far too much sir thanks for watching and good bye

21 Replies to “Coding Your Own Discord Bot – Discord.js – Kicks and Bans”

  1. Grațiela

    Can you make a video on how to do a queue, how to skip, stop and volume control on the music part of the bot? i'd appreciate it

  2. Oniromancie

    Love your videos! Could you do a video on how to detect UserStatus(Online, Idle, Not Disturb) and detect when the user change its status?

  3. Bingo85x

    Hey Dino. So when I asked you the question earlier i appreciated the response, but for some reason my bot still may go offline when i have the Visual Studio open. If you have any insight on this please let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *