Discord.py Rewrite educational number one - How to Create a Discord Bot With Python

close the top of the video we will be. writing a little bit code that'll only be. like two or three mins simply to make. certain everything's working do it remainder. of the video we are gonna be placing. everything up and it actually is incredibly a. few steps to to set this up so please if. you do not have already got your environment. hooked up and you do not have a discord bathroom . linked please make sure you  watched. the complete video because i do know  i am. gonna get tons of questions asking why. things did not work and i am gonna have got to. ask you if you watch the video and if. you are saying no I'm simply gonna direct you to. watch it again so if you guys have any. questions and you believe you studied the total. component you could definitely good touch me. on discord on my discord server otherwise you. can leave a comment down below yet i am. prone to answer you if you wish.

broken image
broken image

right here so now that we've done that what we. gonna want to do in fact is open up our. discord developer portal now you will see. here if you so all you ought to do to do. it really is just pass to only scored developer. portal like that aalright and then I'm. just doing Stabila / curb or. functions I will go away the hyperlink in the. description and all this would be up on. my website tech with Tim done that you. can go look into that aas well all the code. and every thing and iif you you mustn't. have anything right here so you gonna register. together with your discord so what did I do. yeah i've signed it with my discord so. do this and then just click create new. application like this now you can simply. provide it a name I just named my experiment. server and i already have it here so I'm. not gonna do that but just create a brand new. one if you haven't and then you may open.

This up and so it delivers your purchaser. id after which you're gonna see this element. that says purchased so for bought what. we are gonna do is we are gonna create a. new bot so it should say right here I already. have one it's going to say i will upload a bot. simply click certain confirm that aand then. should give you a bot and i just named. mine let's simply name thiis okay that'll. be the call of our bot wide variety 4380 now. it's gonna ask you to give some . permission to this bot now you would possibly not. have the desire to make it a minister yet you want. to ensure that it's aable to at least. ship and see messages so let's do with. view channels ship messages perhaps delete. messages examine message history mention. out every person and you can prefer via. which of them you desire here but at least. give it enough that it's gonna be able. to ship and consider messages because it.

desires to do that so we will do that i'm. save changes after which we are nearly good. to head on developing style of the discord. this factor of things so what we're gonna. do now correctly mounted the environment. now earlier than I preserve going I just want to. say quickly this is truly a sponsored. video persons have Pro xbn they reached. out to me and that i suggested hello we are a VPN. enterprise and we wish to provide you with and your. viewers to reduction so i'll in fact. have a 50% off code in case you guys want to. desire to use this VPN it works in your. cellphone it works on Mac it really works on. Windows and one account correctly will. paintings for every little thing so they gave me a. unfastened account and i've in fact been. utilizing it for the past like two months I. haven't got it installed at present yet on my.  dj bot discord  and my phone due to the fact I'm on. school WiFi and II want to make sure.

that each one my stuff is like encrypted and. like persons cannot glance through all my. data so i take advantage of professional xbn to try this. it's aactually been like a beautiful decent. VPN considering a lot of the other ones. so this one is 625 a month us yet with. my discount code you can get it. for an what's half of  that 360 something. a month and that is like you don't it is. not just the first month like all. month you just pay that amount so for 3. dollars to have your information safe. and feature entry to some of these capabilities. I will allow you to men read by means of it um go. to the link in the outline and just. you know in case you do actually purchase. this you are supporting me because i get. what do you name it like referral cash. in case you uh if you utilize this so write this. that's approximately that so we have to do now. in fact established the environment as a way to do.

That we are gonna use anaconda it truly is. a twin of a kit manager in the. conveyor it manager for Python you don't. have got to use this yet lower back that's what. I'm using for the academic simply click on. downloads on anaconda again hyperlinks will. be in the outline. i am simply downloaded 3 7 edition if. you are on Windows Mac identical component I. already have it downloaded but just pass. by means of that aand it will ask you to feature. and. kondeh two paths so make sure you  choose. like upload two paths when it does that and. certain okay so now we obtained anaconda now what. we have to do is set up a digital. surroundings with anaconda so what we're. gonna do is going to visit CMD so our. command immediate just drag this over right here. and just kind Conda first of all so if. you get something like this and this. works you probably did everything actually if. this does not work.

make sure you  add Conda to direction so. reinstall it and make sure you examine. that add to path button and if you know. it further to the trail manually you are able to do. that ok so now we're going to do is. gonna create a new environment so we. gonna do Conda create n after which we're. gonna give this a name i am just gonna. call mine discord or correctly i do not. be aware of  if that's gonna work let's simply i am. just gonna call mine uh let's have a look at here. academic okay for tutorial and then. we're gonna need to do and that's. significant ensure you python equals. 3 point six because the current. edition of Python 3 seven isn't. supported for discord rewrite so make. sure you do Python equals 3 point. six ok so we are going to do that it is gonna pass. via fixing the environment setting. it up simply click convinced and then once. that's completed we're correctly to put in.

A few programs into this environment and. set it up into pycharm so i am going to simply wait. one moment as soon as finishes okay so now. that our environment is mounted we are. gonna ought to do is really turn on it. and we'll install a few programs. into it so if you haven't used this. earlier than in actual fact all we are doing is. creating a digital environment to store. a gaggle of packages in order that that manner um. what do you call it is we've every thing. type of organized into this surroundings. and we do not litter  our like leading. Python file and that is what an account. is used for it is like a package manager. and a virtual environment supervisor so I'm. just gonna switch on my surroundings so I. simply known as this academic so you bounce to. you turn on and then the call of your. surroundings that you just created so. we will do this and you must see those.

Little brackets shooting up it's the left. of your path ok now do not do what I'm. about to do don't to do this in case you do. it's just gonna kind of be a headache. okay so pip set up this way do not do. that in case you do that you are gonna install. the ancient edition of discord pi which does. no longer have the same syntax as what I'm. gonna be utilizing so you're just gonna be. all messed up and yeah so just don't do. that we are correctly gonna must. install this off of the github so. truly discord rewrite that's. what we're utilizing is not it's not wholly. released yet so it's not. like pip like you cannot just you cannot. pip set up it so so what we have to do. is get it from github so we can select. use pip yet we need to just give a. sure command so i've it in a. notepad here we're simply gonna grab it. from the github so I will positioned this hyperlink in.

the outline again it will likely be on my. web site besides in case I forget to place. it on there after which all we are gonna do. is just reproduction this in right here and says pip. set up how do you get a choice it. means we're getting it from github ok. and then we are simply gonna click enter. enter there we move and it's gonna clone. the repository and iinstall that for us. so as soon as that is completed we are going to be lower back ok. so we complete doing that so now i think. that is in fact about it that we need. for our bots now if you guys desire to go. forward and stir like numpy and pandas or. some other module is you believe you are. gonna use you can do that now or you may. always come back later you may turn on. your environment after which reinstall it. into there so there is not any rush you don't. have to put in all the applications now. lower back this would be in the outline.

okay alright so now we're executed with. our command immediate and now it's time to. pass to PyCharm. okay so that's my bot I'm simply gonna conclusion. this and you will see changed into in fact. logging like any the messages that it. sent to you in addition I'm simply gonna close. this project and just begin sparkling that. i am with you men okay so we are gonna. create a new task and i am just gonna. call this C Python will call this. discord after which tutorial  like that ok. now for the task interpreter you can. mess with it here if you wish or you could. just wait till in spite of everything just mess with. it here what you gonna do is you are. gonna visit existing interpreter. you are gonna visit click these dot dot. dots and we will discover this Condit. surroundings that we just created so that you. can select Kannada surroundings I go. to go to in place of no interpreter we're.

Gonna click on these three dots we're gonna. visit our C Force we will visit. clients we're going to visit our consumer and. then we are gonna go to anaconda three. ok lower back you may investigate the path up. here if you're getting misplaced and wherein. i am typing yet it truly is the default. install region for anaconda in case you. installed it somewhere else then you're. definitely gonna have got to find in which that. is yet mine is just and that is the. default one and C drive okay you recognize. open and Akhanda and this should be the. same no matter where your anaconda is. you are gonna click on env standing for. environments and you're gonna uncover your. surroundings so mines tutorial  on yet you. can see my different environments here I. have discord our disk new web tensor. tensorflow for the computing device. gaining knowledge of stuff at it so we'll. put tutorial  and then we are gonna go and.

we're gonna click on Python W Exe and this. is gonna be the interpreter that we use. we will click okay and we now have you could. see 3 point six this could be. shooting up and you have now configured the. interpreter so we are nearly actually. able to go insert tightness of code so. let's click create and now we are loaded. up and let's simply make a brand new Python file. ok so I shut  to restart my webcam. soon because each time I release. pycharm it type of system faults out yet. truly all we messed this is we're. just gonna cross here and cross new python. file so I mentioned that by rightclicking. and just name it whatsoever you want i am. simply gonna de menthe bought and there we. move so now let's just quickly set up a. configuration for you to run this speedy. and we are going to upload configuration plus Python. after which we are just gonna do what do you.

 

 

Call it. let's name it BOTS after which we are simply. going to visit script path and we will move. to discord academic box okay make sure. the right surroundings so three six. discord dump i feel that's the right. one maybe after we were using Python. three six or is it yeah assignment default. sorry Python three six that's when we. want task default back you can setup. your interpreter here if you recognize to do. that yet I'm notably sure if you just do. assignment default that should work at. least we will experiment that out in a moment. okay so now we're good with that and. what we're gonna do is we're simply gonna. import discord here and ensure that. this is working so truly I forgot. to mention this but when you men don't. have this it just simply referred to as PI tram. correct it is it's like the best. like what do you name it identification east for.

Python you may certainly simply kind PyCharm. on the internet cross right here and down load it. there isn't certainly anything you ought to. do to set it up I just select like an. set up region and click on down load and. then all you're gonna do is launch it. returned such as you  can simply variety I attraction to. launch that and just comply with together with. the steps that I showed you sorry I. necessarily overlook that folks do not use. PyCharm due to the fact I necessarily use it but. anyways so now I'm just gonna run this. configuration by clicking this little. arrow up right here and what I did clearly. when you are stressed was I simply created a. new thanks to run my dossier because I'm. PyCharm you can use configurations. if you guys prefer PyCharm tutorials how. to apply this thing it is exceptionally beneficial I. have a number of  my channel that you'll be able to. inspect in addition. yet we'll simply click on thiis run icon and.

No errors so we're. in fact well ok so we have imported. discord ok so now what i am gonna do is. I'm just gonna create a new text file in. right here so I'm simply gonna call this. actually token dot txt because what I'm. approximately to do is get the token for my BOTS. now I don't want to give you men my. token due to the fact if I give it to then you definately. you're gonna be capable to code with my. bought and well mess with it so. essentially to get your token what. you are gonna do is go back to this. developer portal i'm hoping you didn't close. it but and you're just gonna click on. click on to reveal token now I'm gonna do. this offcamera but in actual fact gonna. click on thiis okay and then simply make. certain you have the token you don't have. to put it in a textual content dossier because you'll. see what we're gonna do with it just. like reproduction just reproduction it in here okay simply.

replica  like whatever the token is it's. gonna be a gaggle of letters and replica it. into your dossier just so you've it okay. so i am gonna pause soon do this and. then I'll be returned ok so i am back so. all I have completed truly is copied my. token into this token dot txt dossier. i think I stored that aand then all I'm. doing is I just made this function. that's just gonna examine the token in. back you men do not have to do that. you will see what i am gonna do in only a. moment okay so truly what we'd like. to do now's we need to just hooked up a. purchaser for discord so that is um the. beginning steps are only gonna say. client equals discord dot customers like. ok and we are going to positioned brackets and now we. have got to do is we have to run our purchaser. now it truly is in which we'd like the token. correct so from that developer page we bought. the token and what it's gonna do is.

Gonna connect us with our bot okay. and because our bot is we've two out so. companion that bot with the server so. we'll do that in only a moment but. basically we are gonna do is we are. gonna do purchaser dot run okay after which. right here we're gonna put our token so in. this example my token is definitely token all right. so actually I believe I higher close this. i didn't need  to do this so let's cross. returned to the discord developer portal. quickly I know what a test server ok. with the intention to hyperlink this up I was attempting to find. like the easiest way to do that but. essentially we simply need  this purchaser Identity. ok now what you men gonna have to do. is i've a link in the description. all right and you're simply gonna copy that. hyperlink now the hyperlink goes to look I. have it in a textual content file in order that  i can. show you exactly what it appears like but. clearly it is this ok so it is.

Gonna seem like this. it's what the hyperlink is now notice that. it says right here C which says purchased client. id and. just like the more than signal lesson signal. like encapsulating this you're gonna. delete thiis okay from the hyperlink so you are. gonna copy right into a textual content dossier what are you. gonna do and then delete that what we're. gonna do is you're gonna paste your. client id here now the customer Identity is that this. right. you're gonna copy that so we are going to reproduction it. we will visit the text dossier and this is. exactly what you ought to do paste it. correct there so you spot that it's not. late it is not in between the the we placed. the tag it's clone of Identity equals and. then you're gonna take this link ok so. it's a cyber web link we'll replica  it now we're. gonna positioned it up right here and i already did. it right here yet i'll simply i'll paste it whilst. we're attempting to show you so ctrl V click.

 

enter it's gonna load up a page that. seems like thiis now it's gonna say add a. bot to a server so what I'm gonna do is. we are gonna select experiment server like that. okay and i'm gonna click authorize all. right so now because you have been signing. with your Dischord right once you did. this it's gonna let you upload that to. your server so you are gonna click i am. no longer a robot go through these kind of these. steps and then you can find about us right here. and it's letting me be aware of  that in the the. textual content channel okay so if I go to discord. and open this again up then you may see. we have now an offline purchased now if. you are not getting this offline purchased. you are you made a mistake is it should. be displaying up in offline okay now what. i am gonna do actually so i am gonna close. this but I remember these hyperlinks are in. the description and you only have to.

 

 

Update that with the client Identity that. you're getting out of your discord. developer portal i do know  it is a lot of. paintings yet it's aauthorized so i will. correctly cross forward and i can close this. because we don't desire that anymore now. the bots added all we need to do is simply. run it so we have the bot token correct. and the bot token I'm storing the token. dot txt dossier yet you guys gonna have it. in right here now simply to show you right here in case you. don't have the token in a string like. say it's like token token right here simply placed. quotation marks round it because it's. now not gonna work if you only have like a. bunch of letters and numbers Python. would not comprehend what to do with that so if. your tokens right here and it's like not from. a textual content dossier then just positioned it like that. so it comes in as a string okay just to. be sure in because I'm certain a persons.

possibly make the error all right so now. what we are gonna do is we run this and. see if everything's correctly working so. i am gonna run my purchased because we're. client dot run today i am gonna visit. my discord server you must. see the bot is online if you've got to. this factor you've completed everything. successful congratulations we're almost. able to begin like seeing if the bots. can get our messages or now not okay so now. the bot is online so simply to expose you. that is ancient this mod is simply going to be. on line when you're running the the. script so if you're like web hosting a bot. to illustrate on your computing device it's only. gonna be on-line when firstly your. computer's on and second of all you're. going for walks that BOTS script on your. computer so show in later video clips how we. can host our bot utilizing like like web. prospective buyers like Amazon web prospective customers and.

Stuff so we do not have to continuously. have it strolling on our computer yet for. now that is what we are gonna do. especially for testing so now notice if. I stop this script I go back here just. wait a moment it may go offline I. think it simply takes a second let's have a look at. right here if i alter  servers and return. ok well it is gonna go offline in a. moment just simply believe me on that ok. ok so now we have our token that we. ran the bot every little thing looks. operating so what we're gonna do now's. we are gonna attempt to get a message from. the user and the image of print that. message again so this all can move in fact. we are gonna go in among these . traces is we are gonna run after and what. we are gonna do is we're gonna established. events now this type of method works on. a bents so i am gonna do at client dot. occasion. ok and there is a intent that's why I.

Desire this client right here so that it is. gonna work and is there brackets no. there isn't so let's do a shopper event. and then what we're gonna do is we are. gonna state outline on underscore message. okay after which in here we are simply received a. variety message due to the fact what is in actual fact. gonna take place is anytime a message is. despatched this function is gonna be run so by using. placing this what's known as a decorator. right here it's announcing that after the development of. on message is brought on this function. runs so then we are gonna seize the. message from the user after which we are able to. start doing matters with it now i do not. imagine I can actually do define I must. do like a sink or anything let's have a. look here a sink outline but it may. help stop operating yeah a sink outline so. you need this async aspect I am not gonna. go through exactly what that does but.

This form you ought to do a sink outline on. message message and now every time a. message is shipped this function is gonna. run so how can we get the message how do. we verify how do we send messages oh. there is a lot of stuff so in actual fact. what we are gonna do firstly is. let's just print to our actual con. so what the message is and confirm. that this is working so we are going to say. message dot content material and II believe that is. what it's message dot content definite miss. check message I got that i'm just. observing the documentation right now. so I don't forget okay so I'm gonna. click on run and now let's test and spot if. we're getting messages ok so we. walking thiis no mistakes let's visit our. discord server i am going to make it smaller and. then let's simply say hello now inspect my. console to the left right here it is printing. out exactly what i am typing good day what's.

Up Tim ok so we're getting those. messages so we know that this is working. the bot is operating that is marvelous ok. so we're getting messages so now what we. want to do is we wish to verify what. these messages are and in line with that we. desire to ship messages back to the user. after I try this i'll end this. tutorial  but I simply want to show you so. you men can play around with it at. least somewhat so what will we do now. who say if message content don't uncover. ok and what I'm going to do is I'm. simply gonna do like an exclamation factor. and then howdy so all I'm gonna do. essentially is say if we find this so if. it really is more than or if it isn't. equal to unfavorable one because the manner. find is gonna work its gonna discover to get. adverse one if it does not uncover this. we're just see if dot or exclamation.

factor hi there is in the message if it is. we're gonna say hi returned so how do we do. thiis well to assert hello back we're correctly. undo a weight message dot channel dot. ship and then in right here we'll just say hi. now we double determine this but I believe. that is right message to channel do not. send definite so what we are doing now is. we're checking that if this exclamation. factor hiya is contained anywhere within the . message okay we're choosing a really. trouble-free Python uncover operate and try this. now uncover returns a adverse one if it. does not find it so if it finds it at any. point then it is not gonna be negative. one so we will say hello back so let's now. conclusion the ball and run it again let's cross. to discord which apparently I preserve. last and then let's simply sort let's. type hi and spot it's not printing. whatever out nothing's taking place yet now.