Python: Making a Discord bot (Part 1: Setup)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to part 1 of my brand new series making a discord pot in Python now I know what you guys are thinking Lucas buddy you already have a series on how to make a discord button Python what what is this what are you doing here what kind of trick is this and to that I'm gonna have to say we are going to be using the rewrite branch of discord py now for those of you who have no clue what the rewrite branch of discord py is it's essentially the version that everyone is going to be using you know sooner rather than later because it's the version that's kept up to date more often actually the other one the other version which was the async version so there's a sink and rewrite async is no longer being kept up it hasn't been even at the time of making my old videos and rewrite is the one that is being updated so rewrite is the place to go if you want the latest discord bot features and the reason I'm making this series now instead of you know having made it in the first place is because one the when I first started to make discord BOTS I learned how to use a sink where I was learning how to use a sink but the actual reason is that the way that I originally installed the a sink branch now by default installs the rewrite branch so for those of you guys who watched my old syriza's first video you guys are going to have the rewrite branch on your PC not the async branch except you will be following an async tutorial that will cause some problems so I decided I would make this series and then you guys will have a brand new series you know to sort of help you guys make your discord BOTS so for those of you who have no idea what I'm talking about and just want to make a discord bot you're in the right place don't leave I'll help you I promise and for those of you who do know what I'm talking about even if you want to keep you know using a sink no harm in learning how to use a rewrite and on that note we are going to officially start with making a discord bot and rewrite so let's bring over Google Chrome here and as you can see I have a couple of links open the first two are just sort of resources so the first one is the the github page for disk or py as you can see here you'll need to have Python 3.5 point three or higher in order to use rewrite this is important obviously because I don't know if it doesn't work or it will work and there will be errors I don't know but just three point five three or higher I believe I'm using three point six five actually I can check for you just now python version yeah three point six five so if you guys want to be perfectly exact and use the exact same version of Python as me three point six five there you go and but as you can see here you know tells you how to install it there's examples here there's lengths here such as the documentation which I'm going to go over in a second and a link to the official help server which is also they're not the official help server per se but you can get help there but it's sort of their official discord server where you can talk with them about the discord pyf module as well as you know yet help I'll leave links to both of these in the description as well as the github page itself and let's go over the documentation real quick I can close this actually the documentation for those video don't know it's essentially where everything is outlined in terms of the discord py module so as you can see here this is the documentation for version 1.0 point one which is the rewrite version and you can see here that right here there is a migrating to version 1.0 which is again the rewrite version so migrating in the sense that those of you coming from the async version or you know my old youtube series if you want to learn how to use rewrite just read through these files here you know if you don't care then you can just jump right into it and you might make a couple mistakes here and there but you know it can't hurt to sort of go through this right I went through it it's not so bad but yeah documentation very important so we can close that down too so now let's actually create the box right so first of all we need to create a an application a bot application so what we're going to do is we're going to over to the discord website the homepage discord app calm and we are going to go to this developer's tab here hover over it and click on developer portal alright so as you can see there's my one application here this is my my personal bot that I have running in my help server well running is kind of a stretch but my bot that I have in the help server doesn't do much but either way we are going to be creating our own application and by obviously as you can see there clicking new application so the name here is going to be the name of your but I'm not entirely sure if you can change it but I'm just gonna call it YouTube but create okay yeah it looks like you can change it here but this is essentially the application that you're going to be controlling with your code alright so this is an application it's not a bot application just yet we need to turn it into one so as you can see on this less left hand side right here under settings we are going to click on bot and we are going to click on add bot yes do it and a wild bot has appeared so now our application has become a bot application alright so we have done everything we need to do here at least for now we'll come back to this page later when we invite the bot to a server but we can leave this alone for now so let me know not discord we can go into code actually we can't go into code I just remembered we have to install discord ey so go to your command prompt you can just type CMD and you'll get into your command prompt right here you're just going to type the command quite simple Hiep p IP install discord dot py just hit enter as you can see here it says requirement already satisfied because I personally already have it installed if you don't have it installed you know it'll install it if you do have it installed you shouldn't have something that looks like this requirement already satisfied all right but now you'll have it installed as you can see here you know I have version 1.0 point 1 which is the version that was outlined in the documentation here all right so now we can write our code all right I was jumping around a little bit too much so this is all gonna be very straightforward if you don't understand what's happening just yet you know I'll try to explain it as best as I can but things like the events that we're gonna create we're gonna create one event in this video and it's a very simple one but if you don't know what an event is or how we're creating it or sort of what's going on with that code don't worry about it I'm gonna have a video on events you'll understand what events are the different ones you can create things like that in that video in this video it's just a matter of make sure you have the code that I have or your bot may not work properly all right so this is very basic stuff every but in the world is gonna have code very similar very similar to this I'm stuttering too much anyways so we're going to import discord that is the first thing we're going to do oh and for those of you who don't know what I did i I just have a bot py file open and Adam so just open a Python file and start typing that's all I did except I already had it open so import discord obviously very important we just downloaded the module because we need to use it so import that then we were going to say from discord ext sow discord dot e xt that stands for extension presumably import main commands plural sorry I don't know if I enunciated the s properly and this is going to be very important obviously as you can tell when we create commands but we will make use of this right now when we create our bot instance which is actually what we're going to do next but for those of you guys who you know maybe are thinking ok why don't why do I need this line I don't know why I've seen other videos where I only just needed import discord or someone only told me I needed import discord trust me this is important all right make sure you have all of these lines are very important so we're going to have we're next going to have a client variable and we are going to set that equal to man's dot bot alright so as you can see we're making good use of that second line right there the commands extension and in the parenthesis here we are going to set a command prefix now again we're not going to be creating commands in this video we will in later videos but we need to set a command prefix so we're going to do that now so command underscore prefix and we are going to essentially set it equal to a string representing that prefix so I personally like to use a little dot or a period just because it's quick to type you know it's right next to the forward slash which is sort of the standard prefix for a command so you know it's just my my personal favorite you can have it set to anything you want as far as I'm concerned so we have our instance of a bot created we now are going to add on our very first event alright so we're going to say act client event and this is going to be a function decorator denoting that the function is going to represent an event and we were going to say async because it's an asynchronous function async death on ready so the on ready function essentially how do I explain it it's just when the bot is ready when it's got all the information it needs from discord the bot is has puts itself into like a ready state and when it's ready you know everything's running smoothly and you know everything is working nicely I should say so you know I don't expect you to understand perfectly what unready does it's a pretty common first event to create and you can read through the docs to understand what it does in depth I'm probably not the best person to explain what it does but it's all it's all there in the documentation and this is just the first event we're going to have just so you know that things are working it's not going to be a very extensive but it's just a functional but kind of thing right so when the bot is ready we're just going to say print bot is right I don't know just something straightforward so that we know you know this event triggered kind of thing and the bots doing something and the last line we need is client run so obviously you know we've created our client here we've given it an event to sort of look for and then we need to run the client it self-right so inside of these parentheses here we need to use our BOTS token so what token token am i referring to if you go back to this page the developer page you can see here it says token now what is a token a token is essentially just a little a little code that links your bot we're sorry that links your code to an application so that the code can manipulate the application now this token is very important because like I said the token connects the connects the code to an application meaning that if someone else has your token they can control your application with their code and that can be problematic you know they can ban people and servers they can spam people they can do a lot of malicious things in servers that you may or may not want right so more often than not it's better to keep your token to yourself or you know to a small group of people probably the people that maybe you're working on a bot with etc you know if you're doing it on your own keep it to yourself there there's there's really no benefit to other people knowing and you know there are some downsides right so keep it to yourself but I'm gonna copy my token here you're going to see my token because I need to show you how to use it in the code and I can always regenerate it if I have to but I'm just going to paste in the token here as a string into client dot run so the run method here on clients or just passing in the token all right so let's go over what we have here we've imported discord we've imported the commands extension we've created an instance of a bot and set it to our client variable we've then made our very first event again I don't expect you guys to understand what an event is just yet but we've created one and then we are running our bot using its token all right so now before we run the bot before we run the bot we're going to head back to this page and on the left here we are going to go to this o off to section right here alright and it's essentially this or start this section is just going to give a a link of which we can use to get into our disk work to get the bot into our discord server all right so we're just going to scroll down here to these little checkboxes and we are going to click the bot checkbox all right now you can give the bot some additional additional permissions but you can give the bot permissions that it will have upon joining these server I personally just like to give it administrator just because administrators can do everything and I don't have to go through each permission individually but if you want the bot to only have you know a certain amount of permissions you can go through each one and just check it off and that's if you don't want to give it administrator permissions excuse me so now that we've given the bot administrator permissions we've now got a modified link which we can copy and paste into our browser and as you can see we're just connecting our bot to discord aka inviting the bot to our server I have a test server that I've set up here and I'm going to just give the bot administrator permissions again as I've sort of requested with this link and authorize it I'm not a robot I'm pretty sure you know I just burped so authorized as you can see here so if we go into our discord as you can see here YouTube bot has spawned in the server however it is offline now if we go back into Adam or you know maybe you guys are using idle whatever and we run the file as you can see here we get a run window and bot is ready and if we look at discord the bot is online so essentially we just have a bot okay I'm just trying to move these around we have a bot that essentially checks if it's ready and if it is ready it tells us that's all the bot does at this point so again I'm just making a bot that works it doesn't do anything crazy or fancy or even you know it doesn't have commands it doesn't have like fun games built-in right this is just to get your very first bot up and running get your foot in the door and that's what we've done we've got a bot the checks of it's ready and you know it goes and goes online in the server and we're able to control it with a Python script here so that's essentially it for the first video so yeah actually I already said that that's that's it for this first video I hope you guys enjoyed if you did leave a like subscribe for you know the rest of the series and if I make more series on you know some cool stuff in the future I don't know if it'll be discord or Python related necessarily but you know maybe I'll make another series on something cool eventually but you can subscribe comment below on our comment below and tell me the types of videos you would like to see I'm thinking I will obviously redo the videos that I did in my old series but I can always do new ones as well especially now that I'm I'm sort of restarting this and sort of getting back into making videos that Python series where I thought being in our Python was so incredibly boring so sorry for the slow uploads but hopefully this will be a bit better but yeah that's the end of this video hope you guys enjoyed and yeah bye
Info
Channel: Lucas
Views: 629,713
Rating: undefined out of 5
Keywords: python, programming, discord, bot, rewrite, v1.0, v1.0.1, youtube, tutorial, english, part 1, setup
Id: nW8c7vT6Hl4
Channel Id: undefined
Length: 16min 27sec (987 seconds)
Published: Fri Apr 12 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.