Full Featured Discord.py Bot Dashboard - Part 1: Making the Bot

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello am i audible yeah i think so i am actually audible right now right great so uh welcome guys to another live stream and this will be a series where i create a full feature discord bot web dashboard in python um so a lot of you have been asking me for a long long time like after my last web dashboard series to make another one like sorry the last one was the series but you guys asked me to create a whole series where i'll show you how you can actually you know change configuration prefixes welcome messages leave messages etc etc so this series will cover how to create the bot that we'll be using how to create a backend api for our dashboard and how to create the front-end website for our dashboard so before we get started let me actually say what technologies will be using so for the uh front end we are going to be using react you guys probably know what react is and for the back end we're going to be using python now specifically we're going to be using sanic now if you guys don't know what sonic is it is an asynchronous um you know web framework for python there's also quartz and aio http although aiohtp is not the best thing to run servers with but still it's usable but we're going to be using sanik because it's like it's really easy to use it's almost like flask although if i wanted a flask clone i would rather use quartz but i've been wanting to learn how to use sanic and i have never used sanic before so it's going to be extremely for me as well and for the database the bot's going to be using postgres so you guys should have node python as well as rest installed so give me a moment and i'm gonna be right back okay so uh let's get started let me actually check chat oh hello guys cassio with aria and aqua paradox welcome to the stream so let's get started with actually uh creating a project directory so we can just see the two documents and also we need to actually check if our postgre server is running because we need to actually uh wait let me actually do system ctl status yeah so we got postgres running here that's great so you can just mk dear uh thanks for the live streaming with dashboard as a search of dashboard and python thanks you're welcome uh so we can now create a directory for our dashboard so you can just uh bot dashboard tutorial so you can do bot dashboard tutorial and let's just actually open up visual studio code here so we have um this here and i want to create three directories so we're gonna have uh right now let's just create two directories so we can create a directory called bot and a directory called uh backend okay so we're gonna create a directory called bot as well as backend so gonna have these two here and what features are going to cover in this um probably gonna cover a custom prefix custom welcome messages and leave messages so your bots gonna have like right now this is not going to be like a like a practical bot it's just going to have like change prefix welcome messages leave messages and we're go i'm going to add like systems where you can modify these through the web dashboard so we have these two folders here and let us get started with the bot first of all so we can just create a bond.pi and before i do that i'm going to cd into the bot folder and let's create a virtual end so i'm going to uh install virtual lan first like i already have it installed to install this if you're on linux you just do install virtualenv you can do this if you want to uninstall virtualenv with uh linux but if you're on something like windows or mac you can just do pip install virtualenv you can just do this so i'm just going to do a virtual lens event so i'm just going to create a really really simple virtual lens here and i'm just going to do something like dot dot slash and i'm going to activate this since i'm using fish shell i'm just going to use activate.fish so we have this and let us actually create a requirements.txt so the file the uh libraries that we're going to need so first of all i'm going to use discord.pi specifically version 1.6.0 and then i'm going to also be using the uh postgres sql driver let's use async pg since we're going to be using tortoise rm for postgresql and we are also going to need tortoise or m and we are going to need uh python dot n for our environment variables so you're going to need this and let us actually run pip install minus our requirement.txt this is now going to start installing everything we have and while it's installs uh let's actually create discord box so from discord.ext sorry from discord.exe import commands and right now it says that there's nothing here because i need to actually select the virtual length so i'm gonna go to the bin and then python select interpreter and yes visual studio code is now using virtual length so all of this has installed properly so you have this and now let's just create this bot so uh chat should i actually increase the font size or like is it too small should i increase the font size well i don't see any response so i'm probably gonna go and increase the font size so uh font zoom in okay so commands dot bot and then command prefix let's just say something like a dollar sign have a dollar sign dollar sign seems fine and let us do adbot.event async dev on ready and let's just print what is ready great and now we can just do bot.run now the thing we need to do in this case is we want to have a dot envy so dot n and then token we're going to paste our token in here later on which i'm going to hide from the stream uh so yeah we can just go here and then we can import the built-in flip so from python.10 import load button and then i'm just going to load the 10 here first of all so i'm loading this in here and then i can just import os so import os and over here os.inviron token so we're gonna have this token in here and i'm just gonna paste the token in here be right back so i'm just gonna go and copy the token and paste this right in here boom okay so i have pasted the token in so the token for my bot is in dot end here so we have that and now let's actually try running this bot so i'm gonna open up integrated terminal here because i'm gonna need um this later on so i'm gonna open up this one here and i'm gonna do cd bot and let's do python.pi so it's gonna take it to start and it says bot is ready so if you go to my uh test discord server here general the prefix is dollar sign even though we don't have a help command by default discord.pipebots have a help command here so uh yeah we have this it's uh working perfectly here so we can just uh now start working on our commands so first we need to actually uh initialize a tortoise or connection so to do that it's pretty simple to do we need a models file so models.pi and that's where we are going to have all of our database models so basically what i'm going to do here is i'm going to have a i'm just going to open up the tortoise or documentation so tortoise or m documentation and we are just going to import tortoise or from tortoise import models or something like that actually forgot what i was supposed to do here yeah so models import model and then we are also going to do tortoise import fields so this is the orange that we're going to be using and let's just do some like guild config and this should inherit from model and i want to have a guild id and this will going to be fields dot big int field and this will be pk equals to true and unique will be true nullable false so we want every girl config to be unique now what we're going to be doing is we're going to have a custom prefix so uh fields dot text field text field and let's actually do something like a string field let's do a text field and this can not be nullable although this should be nullable because we are going to have a default um prefix so we have this and now we can actually load everything in the tortoise rm so let us actually create a function uh connect db so this is going to be an async function and we're going to call this function when the bot is online like in the on ready function so i'm going to import toy toys from here so from toy toys import toy toys and i want to use await tortoise dot init and this should have the db url and this is where we might face some issue the first this should be postgres or should it be post resequal we need to actually check this out so tortoiseorm dialects so we need a specific dialect for the uh database that we're going to be using so for the dialects we have um for post rest yeah we do use this postgres one so we're going to do colon slash slash and this is going to be your username password at localhost and this can be just 5432 and let's actually call what should we call this bot let's just call this something like bought or like testing bot zoom calls up like this but before we do any of this we need to initialize a postgresql database to do that first let me actually clear the terminal i'm going to do sudo run this command okay so basically i'm just switching to this postgres user and what i'm doing here is i'm going to go to that user and now i'm going to create a user so create user interactive uh password prompt enter a name of role to add let's just call this uh let's just call this bot password of new rule i'm just gonna put one two three four five and then one two three four five shall the role new rule be a super user and yes why not let's just put it like this i mean it shouldn't be a super user but i can't be bothered to you know write my own like configure that database granted permissions and stuff yeah uh we're going to call this the what user did we create by the way it was bought i think yeah support at one two three four five and wait we also need to create a database so i'm talking about postgres so psql oops my bad so we need to go to uh psql and then we're going to create a database create database testing bot okay so we have created this now we can connect to the database and the models or the modules in this case we are going to have the models is going to be models so this is our models dot py file we are actually like telling tool toys hey use this one and now i want to initialize the tables or the schemas tortoise or generate schemas so when the bot is ready i want to await this so connect db i want this to run so let me stop the bot python.pi it should connect to the database once the bot is ready and yeah it says bot is ready if i type uh if i go to something like this you know what i'm gonna i'm gonna stick around here i'm gonna do a slash c testing bot i'm not connected to the database testing bot as user postgres that's fine uh i'm gonna run slash dt to see the relations uh we have here and yes we have guild config so we have this guild config here this table that we had created so this is awesome and i can just stay like i can just keep it as it is so we we want this command prefix to be you know something different and that's why for customer prefixes we want a get prefix function so async def get prefix and it should return me the prefix okay so uh one second okay so we have a get prefix here and then what we want to do is we want to get the bot here so in this case it's gonna be the bot as well as the message so the message will be discord.message in this case so let's actually do import discord and the bot will be commands dot bot and we do want to import the models so what i want to do here is from models import guild config and in the async dev get prefix what i want to do here is i want to prefix going to be uh guild config dot um filter and this will be basically uh id so this is gonna be guild id id will be message dot guild dot id and it's going to be get or none so basically what this will do is it's going to filter the database check if it has this uh if an entry exists for the specific guild if it does not exist it returns none if it exists it just returns that config so it's like get or none so if that config exists so if prefix return prefix i opened up a separate database okay if prefix return prefix else return dollar sign so i want the default prefix to be dollar sign although we can do something like this here uh we can use a ternary operator so return prefix if prefix else dollar sign you can do something like this and over here for the command prefix i can just put get prefix here so this will now give us a custom prefix system let's just wait for the bot to start uh one second here okay yeah sorry about that so yeah the bot is ready and if i actually type dollar sign help now it says current prefix must be plain string eyeshadows callable returning as not query set oh yeah my bad my bad it should be an await so uh should the filter get or none and this should be a query set yes so we can now return the prefix so we can have a config and we can return the config.prefix here so contract dot prefix using original configure prefix if that's configured exists so we can run this and let's just wait for the bot to load yeah it says um dollar sign help that's great so we have this and now i want to make a command where if like where you can actually change that prefix so i i want a bot dot command async def prefix and i want this to have the uh prefix okay i'm just gonna import typing because without type ins um vs code doesn't give you proper intellisense so you're going to have this here and if we have if there is no prefix so basically the command will be something like this dollar sign prefix or it can be dollar sign prefix as well as some other prefix maybe an exclamation mark so if this prefix part does not exist i want this to uh return the current prefix so what i want to do here is every time this is run i want to get the guild context so if not prefix i want to get the config anyways because we're going to need it later on so guild config.filter i'm going to copy this part because programming is a lot about copy pasting and we can just do ctx.guild.id yeah that works if not prefix if no prefix was um entered i can just do something like uh i can just do the if config so if the config exists here rig is going to return on return away ctx dot send and the current prefix for this server is let you know what let's actually create a variable we're going to create something called um let's call this constants and this will be default prefix i'm gonna have this dollar sign so the default prefix would be this and the current reacts of the server is this default prefix if not config so if you don't have a guild config who's going to do this um uh dead aura no i'm not making a discord bot i am making a discord bot web dashboard and for that i am going to uh like make a bot for that so we're going to have this if not configuring this and the current prefix for the server is default prefix and if that contract exists bring us away ctx dot send we can actually do this over here so we can do um instead of doing this we're going to say config.prefix if pre if config else default prefix so you can have that here and yep we could do that so if not prefix yeah we're gonna do this so let's actually stop this button and run it this time it's gonna be a door sign prefix um okay great great so we are going to have if you type this door sign prefix it's going to send you the current prefix for the server's dollar sign that's great now we want it to be so that if someone does enter a prefix at the end we want them to update it but before we do that we want to have a command start check so guild permissions so haskell permissions and this should be a uh discord dot no it should be like manage server is going to be true wait a second permission system for discord.pi i'm actually taking a look at that um hey yeah so we can do something like so we put this at the top here yes we put this here so let us run this bot now um it will require in invalid permission manage server oh yeah it should be managed killed here my bad that will run we have this and now if we don't have a previous server so we want to create a new config if that config doesn't exist so if not config we want to create new uh new config would be tortoise or m so not tools or i'm guilt config uh config and this should have the uh guild id or just the id would be mess ctx dot guild.id and the prefix will be the prefix that we have here well let's do underscore prefix okay we're gonna have this here oh my bad okay great so gonna have this we're gonna create this new config here and then we're going to do new config.save but this is a core routine so we gotta await this great so we're gonna return and we're just going to you know return with an away c text on set later on so we're going to do return await ctx dot send um set the prefix for this server to uh the underscore prefix great and if there is no config but if there is config we want the config.prefix to be the rs4 prefix and then await config.save is it update i think it is update for dict is it anyway so we're going to do this and it's going to say set the prefix for the server to this so this is like a really it's a simple custom prefix command here that we have so we can now run this uh what's running okay so you can just do dollar sign help we can just set door sign prefix and you can do dual sign prefix exclamatory mark i'll just say set the prefix for this server to explain trademark now if you type this okay so the custom prefix is working now if you type prefix okay great and if we set the prefix to dollar sign again boom we have this now great so uh yeah our custom prefix system is working perfectly now what we want to do here is create a few event handlers so we want welcome messages now for that i want to actually add a few columns here so let's actually add a welcome message enabled is it true or false so we need a fields dot uh it's gonna be a boolean field as far as i know and by default i want the uh it can be nullable to be honest or it should be like this by default okay wait one second there's no prefix we have this we have the guild config and effects okay that's fine um how long have i been streaming for 25 minutes okay that's not a problem it's a boolean field so welcome message enabled and let's just call it welcome enabled and then we have a leave enabled and that's going to be a field dot boolean field great so we're gonna have this and you know what yeah we can just have a welcome enabled and leave enabled and then we can have a uh welcome config model and then this should be a channel id that's going to be a big end field like this it's going to be the primary key yeah and then the message will be a text field okay and the default would be false default will be false and yeah so you have this and yeah so fine and then right now let's just do the welcome message first then we can just leave messages i'll stop this run this again and i hope it doesn't give me like any uh migration issues because i don't want to start a database migration right now uh so we have this and we're gonna start working on the things here okay so on member join and on member leave i'm going to add bot dot event async def on member joined or is it on member join uh i forgot which one it is to be honest on member join yeah i i think it's on member join here okay great so the member will be discord dot member and what i want to do here remember.guild.id so this is going to be our guild id so guild id and i want to have a guild config so the guild config it's gonna have all of this by default but one thing i want to do here first of all is whenever the bot has been added to the guild i want to uh add a like create this new configuration because but right now like the database gonna get messed up so uh okay so we can now actually run this event here uh bot dot event i can do async death on guild join guild would be dispro desperate killed okay so what i want to do here is i want to create new config here okay a new config and by default i want this to be a default would be the door sign yeah we can just do default it's going to be door sign here and i can now stop this you know what right now let's do pass we're going to keep the bot running i hope it doesn't give me any migration issues and if it does that's not a big deal here we could just do something like uh wait first let's actually do defects it says welcome enabled does not exist well we do need database migrations i think right now you know what we can actually work with that later i can now uh go to this i can drop table guild config and now i can run this because i i really don't want to start doing database migrations right now it's a huge pain to do so we can just do dual side prefix the current previous for the servers okay that's that's fine you can actually do a select asterisk from guild config yeah it has no entries right now that's completely fine with me um so what i want to do here is on the when whenever the bot joins guild i want to have a new guild config and yeah so i want to do this i don't even need a prefix for this i just want to have a kill dot id i'll write new contact or safe okay so i have this and let's actually stop the bot let me take a look at my stream um okay oh hello is she not found thank you uh for joining the stream okay so what i'm gonna do in this case is probably gonna remove the bot from the guild i'm going to remove this on the guild so i'm going to kick the spot here with the bot running i'm going to invite the spot again on to my server so i'm just going to go off and bots gonna join permissions i'm gonna set to eight i'm gonna get admin perms okay so i'm gonna add the spot to the server i'm currently adding this spot to my server authorized discord is being really laggy for me today i don't know why it takes a while for the website to load for h capture to run probably my internet or something like that i don't know but anyways the bot has joined and what i'm going to do is i'm going to check the guild config and boom we have a guild config here because the bot has joined the server now uh that's actually pretty awesome here oh welcome shabby man to the stream well it's pretty loud outside because an airplane is flying so we have this here and now i want an event where a member joins remember leaves so you can just do bot.event async def on member join and member is going to be discord dot member okay uh so discord dot member or should it be a ctx never mind it doesn't need ctx okay so uh now what i'm going to do is whenever the member joins i want to get the guild config and i want this to be the members.guild.id remember.guild.id here none and there should be a config i mean bot is joining a guild and if not config if not config return but if the config has this enable so we're going to do if config.welcome enabled if the welcome messages are enabled we're just going to like put a comment here welcome messages are enabled now we need a command which will enable these welcome messages here now we can just create another command and bot.command and we also need manage guild for this one so we can do async def welcome and this will take the uh this will take the context and now what i'm gonna do is i'm gonna get the guild conflict for this and i get the guild config as well as the welcome config the welcome config is going to be like this so one second please by the way is my intern is my stream lagging i hope my stream is not lagging here i'm gonna have welcome config uh one second guys okay so we want to uh yeah so we're gonna have the welcome config and i made a an oopsy there it should have a guild id or it should have this here id should be the the guild id guild id it should be unique because it can't be the same and yeah like i should remove unique from this one the channel id and the primary key should be set to the guild id here so we can have that here let's put kill id because why not so uh we can do dt we can do drop table welcome config we can drop this table we can once again no problem so welcome command is gonna check if this is enabled so what i want to do if config if config.welcome enabled await ctx dot send welcome messages are enabled in this guild all member join events will be sent to going to be sent to um so to get the welcome channel open channel and the channel will be we need to use discord.utils for this so discord dot users.get dot uh the series ctx dot guild.channels is going to be this and then the id will be welcome config dot uh channel id this is gonna be sent to this dot mention you're gonna return this function if you're on this you can just do something like else await ctx dot send to turn away ctx dot send um welcome messages are not enabled for this killed sorry killed okay yeah so we have this command it's basically gonna show if we have a welcome messages configuration or not for this um so what i'm going to do uh keyboard asmr yep keyboard asmr is good good for health so we have um so welcome so we can do welcome oh my bad i made a title there so welcome it says unknown pram id allowed base values are channel id uh wait a minute where did i mess this up field error unknown pram id did i my setup somewhere unknown pram id where did i mess this up yeah my bad i forgot channel id sorry guild id yeah okay so i am gonna start the bot again and let's actually see this so wow why is it taking the bot so long to start it says vocal messages are not enabled for this skill that is fine uh you know what like a member can view the welcome message conflict from here so we don't need that but i'm going to now make a command which sets the welcome messages i'm going to do async def set welcome and this is going to be the command.context and then now basically what i'm going to do is i'm going to ask for uh the what do you call it i forgot like it's going to ask for the welcome messages so what i'm gonna do here is i'm gonna ask uh one second okay so basically what i'm gonna do is i'm gonna do some like so i'm gonna actually ask this user to a like i'm gonna ask them for the channel where you don't want the welcome message to be sent to so wait channel dot oh sorry not channel i'm going to be bought dot um wait for this is gonna wait for a message and the check would be the author check so the author check what i want to do here is i want to add a message check author so i want to do def check author and this is going to be passing the go through here right so i have one second please although one thing we can do wait wait i was actually being admitted here in this case i realized something that we can just have a lambda function so this function whenever this function is cooled this will basically have this so we can do x dot author dot id so it's gonna be the message and why is it long by the stupid lamp dot it should be equal to the ctx dot author dot id yeah we can actually uh do that in this case and we are going to take this and we are also going to um we're going to try to convert that text message to a text channel so text on converter um dot convert and we're going to add ctx and then message.content also i want to add a timeout here so you can do something like timeout it's going to be 20 it's gonna be 20. and if this has a commands dot errors dot channel not found because that can happen if the user has entered something invalid so as e we can just do um weight ctx dot send invalid channel you know what what the best thing is you can make this recursive so if the user enters the wrong input it's going to ask again and again so we can we're going to do something like e dot argument and we're going to do please enter a channel name again and i'm going to do this here so i'm amazing death ask my bad ask welcome message and we can do this in this case it's gonna run this message again so we can do await ask welcome message we're going to run this command again and basically what i'm going to do here is i want to uh ask for this message so i'm going to do away ctx dot send um please enter the uh channel where all the welcome messages will be sent and i want to do uh oops my bad i want this to be message for the channel in this case so channel will be a way to ask welcome message so that's what i want the channel to be okay so we're gonna have this and yeah i have the channel here now let's actually see if it works or not i can print the channel and now let's run this so we're going to ask them for that channel afternoon welcome to the boy i'm watching you from windows 11. congrats on installing your windows 11 uh so we have the set welcome now set welcome it's not going to ask please enter a channel where all the welcome messages would be sent if i type in something else something that doesn't exist it's going to keep asking and it's going to time out after 20 seconds so don't worry about that it's not going to be like an infinite loop it's going to time out after 20 seconds so we can do something like a good channel uh general we can just say general and boom uh right now it says that this is none this channel is not for some reason wait one second uh it should say channel converter.ctx message.content now this shouldn't be uh none here now why is this none interestingly one second so this is returning none here for some reason okay so let me actually see whatever oh i forgot it should return this because every time it's gonna do a recursion it should return like the return value that it gets so like when it recursively runs this this is going to return something and whatever this return like what this function returns you return that as well or else it's always going to be none so yeah that return statement is mandatory so we can just do something like uh set welcome and we can just enter some invalid stuff and then we can enter a correct channel and boom we have general here so that return statement is necessary now i want the uh lesson to do something like yeah let's now ask the user to enter the text so what i'm gonna do here is i'm gonna do another message so this is gonna be the uh welcome message this is going to be a way to wait for i'm gonna do the same thing here dot content because this will return your message so um let's actually run flash dot oh forgot a sudo app installed black it's going to install python black here don't worry it's not going to reformat oh god it's formatting my virtual and for some reason okay uh let's run python.pi and it should start up so once we have this we will then create a guild conflict so we can do something like uh set that welcome oops okay so we have this please enter the name of the channels where welcome master will be sent general it says co routine object has no attribute content oh yeah i forgot um you have to wrap this in a quotation so it's going to wait till that core routine is finished with that async function and then it's going to check the attribute content of that um place okay um one second is my video lagging now because obs as well as youtube is saying that my stream is sort of lagging but i hope that it it is not lagging okay so please enter the message general it's not lagging all right thanks chap so yeah it's gonna present your channel where all welcome messages will be sent now it should ask for weight haven't i saved the spot yet it should ask for another message oh wait i forgot ctx dot send ctx dot send please please enter your welcome message below and you can do something like use use where so we're gonna use this curly braces where you want to uh mention the user so basically wherever you put this here like this curly braces it's gonna um replace that with the user dimension so we're going to welcome message it's going to ask for this and then we will create a new guild config here so we can modify the guild config so if the guild conflict does not exist that's fine i guess i mean we can now get the guild's config in this case where's the girl config and the welcome config yeah we can have the guild configure welcome config so we can just do config dot welcome enabled is going to be true await config.save so it's gonna like the config is always going to exist because every time the bot is being added we are going to um create a new configuration welcome dev hypercoder to the live stream so we're gonna save this configuration in this case and now we also want to make a volume contract so if not welcome config uh config so if we don't have a working config we want to create one so we can just do our new welcome config and this is going to be welcome config oops config and what are the arguments does it like it takes guild id okay so we're gonna have this guild id here guild id will be ctx dot gil dot id and then the channel id would be channel id channel id would be the channel that we have dot id and then we are going to have the message and the message would be the welcome message so this is where you're going to have and then await new welcome content dot save if we do have this config we want to do welcome config dot uh channel id is going to be channel id if this does exist we're gonna do channel dot id and then we're gonna have a welcome config dot message and that's going to be a welcome message here oh wait welcome contact dot save and then we're going to do a wait uh we're just going to do return away ctx dot send and we're going to set welcome now we can just do enabled okay so we want this message to be a bit different if this does not exist if this does not exist uh can i upload flask anything without using unicorn um unfortunately no instead of using unicorn you can use something like uws gi or hyper corn because you need a wsgi compliant server that is running that flask app and we are using nginx as a reverse proxy for this so uh yeah ixc uh you cannot use it without unicorn although there are other unicornish alternatives like uw-sgi or hypercorn or maybe uv corn and waitress there are like tons of wsu servers available so we can now over here do uh enabled welcome messages all uh member join events will be sent to we can do uh dot mention um the stream ended no it hasn't ended yet it hasn't had dead yet okay so we're gonna do channel dot mention that's where everything's gonna be sent and now we're gonna do updated welcome config i'll do welcome config all my all join events so it's gonna be updated and enabled that's what we're gonna have here and yeah we have this uh set welcome message command so we can now run this run the bot i'm gonna do something like uh wow there are six pings in this server holy cow so uh we're gonna do please under the channel you can have general here's our message uh we're going to use the curly braces so we can do something like welcome to the server so we're going to enter something like this here enable welcome messages all my all member join events will be sent to general because that's where you set it now if we type uh select master from welcome config would you look at that we have the guild id as well as the channel id and the welcome message here so that's where we have everything and now what i want to do is i want to make an event for this so whenever someone joins the server i want to send this message so we can do something if the welcome message is enabled i want to create a new embed here and i can now get the welcome config the welcome config is going to be this for this oh never mind your welcome config is here okay great so we are going to fetch the config so we can do member dot build on id and this will not be none this will always have a value because whenever you enable that uh welcome message it's always going to have like a configuration for this in the database entry so we can do um embed disk for dot embed and then we can do or maybe instead of doing an embed should i do an embed or without an embed should i do it without an embed or with an embed um i'm waiting for a response well there aren't any responses in shots so uh let's do an embed so discord not embed and do embed all right thank you thank you raph for the response uh this world embed and the title would be welcome and the color would be discord dot color dot i forgot the u here dot blue okay yeah so uh we're gonna have that embed and then we can do embed dot set image and the url is going to be member dot avatar url and then we can do embed dot description and this will be welcome config dot message dot format and i want this to format like the first one the curly braces got format and i can just do member dot mention and then we can get the channel so uh send channel hello welcome to this stream i use shrivastova sorry if i pronounce your name wrong so you have the send channel here and the send channel would be discord.utils.get discord.utils.get and this is going to be a member.guild.channels not build guild channels member.kill.channels and then the id of that channel will be welcome message.channel id undo wait send channel.send embed equals embed we can try this out i'm not sure if it's gonna work or not but there's no harm in trying so i have my old account here um i'm gonna invite myself copy this invite here i'm gonna leave that server so i'm not in that server anymore with my old join a server i'm gonna join here and it should send this message although it is not sending it i don't know why this is happening we can just print config and i don't know why this is happening to be honest uh we can do dt select asterisk from config yeah we do have a welcome enabled so why is this if not config okay that's interesting it should have it should work here i'm gonna you know i'm gonna leave and then rejoin or maybe should i fix my intents because for some reason maybe my intents aren't working i don't know why i do have my intents working properly i don't want this are not working we can wait let me put this here okay so we're gonna put this uh i'm gonna kick myself out i'm gonna rejoin using my link here uh where's my link wait where are my invites okay never mind i'm gonna invite myself to the server hidden use copy button i have copied and rejoin again uh now one member join is my events name working properly on member join for some reason this function is not being triggered here i don't know why this is not working uh wait let me actually check if it's working or not okay so what i'm going to do here is uh search i'm just going to search why this is not working so uh hmm so we do need proper intents here how would i do intense dot oh wait i forgot yeah we need to do intense dot discord dot in 10 star full i need to do this here first i forgot that you were supposed to do this i'm going to leave leave that server and then rejoin again join yeah it does show me a guild config and yeah boom it says welcome on 420 to the server and yeah we have perfectly working welcome messages right now guys we have welcome messages i can remove the skills configure print statement that i had here so yeah the guild context ah sorry the welcome messages is working now should we do a leave message system yeah we can actually do something like that welcome haku bin singh uh sorry if i pronounce your name wrong i actually pronounce a little people's names wrong so we can just do a leave message uh and should i have wait i should create a leaf contact first yeah i should i think so we can have this leaf config uh wait uh dead aura no need for any contact please so uh leave config we should uh yeah so we can start with this and now what we're going to be doing here is uh we're going to have leave messages here it wasn't config we can just have leaf config leave config we just have uh leave config did this auto import vs code tell me i want to import it so we have the leave conflict or channel id all member leave events and we're just gonna do some like leave then leave channel and then leave enabled yeah we have that and then we can do this great so we have this and now we can actually copy this whole function since i'm a programmer copy pasting is something that i've practiced since i started programming oops my bad um someone's at the door right back okay sorry about that someone says someone was at the door um yeah so we're going to do set leave international door no no no uh like some guy was at the door set leave ask leave msg so invalid channel we're gonna do that same thing me going hope i don't get caught fingers crossed yeah sure we'll leave yeah i'm gonna have a gun don't worry okay so please enter your leave messages below we can have a leave message leave message and uh we can have the leave config and this would be the leave config and we can just have leave enabled so i have leaf config and have the leave message just replace everything read member leave so like i'm just typing leave everywhere leave messages and then we can just uh okay boom we have this right now great so we can uh enable delete messages in this case and now we can also have that event that we had before so we can have on member leave because i don't remember leave them actually search that out one member leave on it should be on member remove yeah it should be on member removed not all remember leave so remove uh leave enabled at the leave config it's all leaves now you know leave config and then yeah so we can now do something like uh remember left so yeah we can do that and since this one caches that member we don't have to worry about that member being in the guild cache or not in the bot cache or not we don't need to worry about that so we can now separate those commands and the only reason i'm not using cogs here because i can't be bothered and it's sort of getting really big this file um so we can just uh separate these in cogs later on what's ready great i'm gonna leave that server with my alt there should send a message oh wait i forgot that um you don't have welcome messages invite people copy uh i'm gonna join that server back okay so yeah we have this welcome message here so we can just do a set leave and please enter the channel where all the messages will be sent we also want this to be in general because yes please entry leave me below we are sorry to witness that has left the server hope you had a good time here it says key guild already exists and why is that definitely oh my god i forgot that you um you need to do this yeah so it says he exists because the configuration already existed and that was just my bad so you can do set to leave here let me actually check my streamer can i invite him the pogbot no you can't because it is a private bot here as far as i know let me actually check if it's a private board or not no yeah it is it is a private bot even if you try if you even if you know the id you won't be able to invite it so uh please enter that oh oh fudge i i forgot i forgot that i had to like copy this okay so uh we had a an async yo timeout error that leave general enter the message boom and i believe has just all member leave events will be sent to general great now i'm going to leave that server with my uh old account it should say that i have left the server okay so um it is working here great so we have uh working welcome and leave messages so this this stream was uh only for the bot part in the next room we're going to be doing uh starting with the front end as well as some of the back end but one thing i'm going to do before i stop this stream is i'm going to separate everything into cogs so i'm going to open up cogs and then let's just call us just like events.pi and we can do from discord.ext import commands and commands and then we can do class events commands cog and we can do def underscores for init self bots going to be a commands dot bot and we can do cell dot bots gonna be bought let's actually put all of those events in the uh thing here one second okay uh wait where are my events oh yeah i have these events here i'm gonna copy these events here right here and paste it in here and i know that i broke literally everything here so don't worry uh now i'm gonna uh probably import these models from somewhere else maybe i can do a from bot dot models import probably gonna import these here the reason i'm doing bots is because it's the parent directory of everything here and i'm still gonna do import discord and i'm gonna do commands dot co dot listener this is basically gonna do a cog event listener so we should have all of this and in front of every single command here we're gonna have this uh self here so wait isn't this the uh thing that vs code has where you can select multiple lines never mind self copy this paste it literally everywhere in every single place work where you see a non-static method so we have this and now we can just add a setup function so def setup and the bot will be commands dot bot bot.ad cog events you have that that's great so uh i hope that this works now so before i actually change it any further i want to actually uh like import all this so i i probably gonna have os over to import it oh i do have os that's great i did need os okay so uh what i'm gonna do here is i'm going to run os.lister so for inos dot list gear dot slash cogs oh not on it should be os so it's going to dynamically import literally everything that's in there this is going to be if i dot ends with dot pi so i've done the dot pi i want to do a bot dot load extension f string it's going to be cogs dot and then the i and so this is going to be the file name and then accept the last three characters dot p y so we're going to remove the last three characters trim them out it's gonna load all of this and then it's gonna be it's not gonna return anything but i'm gonna print out loaded events cog you know what i'm gonna have this here in the print statement so uh uh we can do something like cell dot underscore underscore class dot name is this class name salvage class is going to return this type event okay yeah we can actually try that let's see if it works or not um it says commands.eve could not be found and why is that it says uh wait a second can i print i it says events.pie okay okay oh wait i forgot minus three it should be from the end that during another exception occurred key error cost events the bottled moles bought is not a package um what what's not a package oh we need to init and then net dot pi will this work now nope it is not working because yes so we need to import like this we oh wait we want to relative import forgot that um it requires relative imports here yeah it says loaded events cog forgot the fact that it has um how long will the stream go on and it's gonna be pretty um like what five or ten minutes it says bot is ready that's great we can try the join event right now join event copy the invite paste that in here and boom it says member has joined the server i i try leaving it says i have left the servers join and leave great we have our messages working here so this cog is working now we can have a uh so instead of stash like literally putting and stuffing all this in here we can just have like uh messages dot pi or yeah we can just have um dot pi or just config.pi why i was just struggling so much with this okay so we can just from discord.ext import commands and then we can do class config commands.cog and then we just want to uh create a constructor so and then we can just run a def setup bot is going to be uh commands dot bot and bot dot add cog and that's going to be a config bot i also want to copy that to that thing from here gonna basically load that this coke has been loaded uh yeah we can actually have this here effects great and boom so this here we're gonna have a you know what i'm a fancy man so bot dot command it's gonna be commands dot command i am a fancy person so uh we're gonna put this in here oh or we can just have a constant stockpi so we can just do something like constance dot pi and then the default prefix this is going to be the default prefix okay yeah great oh my bad so uh we can just import constants constants we can import constants and then we can do constants dot default prefix right run the same thing again we're going to have uh so we're going to import discord import typing import constants this is the prefix and uh okay and from the events we're going to do the same thing from here all my own imports are going to be on this side you're going to have bot so water dot okay so i have this and then this uh let's actually remove this part here what we're going to um remove this part for now we can do bot dot um something like wait for stuff like that yeah so we can do what don't wait for and do cell.wait for and uh we can do something like ctx and then we can have that same thing but this time it's going to have cell before it boom now we're going to have vod.cog uh config what okay so it's gonna import all this no errors whatsoever we're gonna only have this on ready this simple already here that's the only thing it's gonna have over here and uh wait uh girls we have that get prefix here python. so it says the no module found called constant oh yeah my bad the audio bit rate is pretty low uh obs is saying that i have a really really low audio bitrate that's fine we can do uh prefix yeah it says the prefix is working so um you can do prefix is going to be uh this prefix so we can do prefix store sign oops my bad for prefix dollar sign and yeah so we have a working bot here let's actually run black uh cogs slash to black bot pi constants.pi models.pi and boom so yeah we have a working bot over here have a configuration cog this is working we also have this constant file the events so we have a working bot and in the next stream we're going to start with the web dashboard for this bot because this series is for the web dashboard but without making that bot first we can't make a web dashboard for it so anyways guys uh that was today's live streams where if it was a bit long um but i hope you enjoyed it and if you did please subscribe to my channel and like this video i put a lot of effort into my content and i really appreciate it if you guys help me out by subscribing so anyways have a good one guys
Info
Channel: DevGuyAhnaf
Views: 825
Rating: undefined out of 5
Keywords: python, discord.py, hikari, discord bot web dashboard, discord.py web dashboard, discord.py bot dashboard, hikari bot dashboard, sanic, discord.py sanic
Id: 56Zw8-eaNq8
Channel Id: undefined
Length: 74min 43sec (4483 seconds)
Published: Thu Jul 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.