what's going on everybody and welcome to
a discord pie tutorial discord pies used
to make BOTS in this cord so that's what
we're gonna be working on and let's just
go ahead and jump into it so first of
all as one does when they're trying to
install things they go to the
documentation and lo and behold this is
not what you want so currently the
discord pie is kind of a it's like
almost into two main areas or two
versions you know it's kind of like the
split with Python you've got discord pie
1.0 and you know and beyond and then
you've got this the 0.16 right now and
you want at least I was after 1.0 so I
came here to the 1.0 Docs and it says
hey just install it this way nope that
installs 0.16 so then I soon find myself
on Dish discord - rewrite from pie pie
great so I install that but I hit some
sort of weird error to there and I
couldn't quite figure it out so after
some digging around there couldn't
couldn't quite solve that problem so
then I came to the discord earth 2 tits
Court I came to the github and I just
cloned the github or downloaded the zip
and then installed it ok so that's what
I'm just gonna recommend that you guys
do so it's just this github keep trying
to call it discord I'll put a link in
the description usually I linked to the
text-based version of this tutorial
either the text-based version of the
tutorial will be in there which has all
the links or I'll put these links if I
forget one of those two just yell at me
and I'll throw them in there otherwise
yeah so this is this the official
discord pie but under the rewrite tree
so this is how you will get 1.0 so go
ahead and clone or download do a pip
install - are the requirements text it's
only two things
it's a io HTTP and WebSockets I believe
both of these will be installable via
pip no problem on Linux Windows Mac
whatever if you have a problem with a io
HTTP on Windows don't forget unofficial
Windows binaries exists and yeah that
should be everything also note this is
only apparently stable on three four and
three five I've been using it on three
six no problem
I will wager or I guess I can't wager
but I can't remember if WebSockets is
like fixed on three point seven yet so
that might cause trouble but feel free
to try it on three seven if you want I'm
gonna be on three point six for now so
once you have all that once you think
you've got it like once you've installed
the requirements then it's just a Python
setup I install right so whenever you
think you've done all those things go
ahead and run Python three six do an
import discord and then check the
version discord dot version make sure
you're on the same version as me if
you're not some of the things are going
to be a little different if you're
having any problems with the install you
can join our discord discord GG slash
Centex but yeah should be pretty simple
just clone pip install - our karma so
text
pythons effed up hi install done so once
you have that now we're ready to start
setting up the bot itself so the first
thing that we need is to create an
application because a bot needs an
application also I'm kind of assuming
you all have like a discord server that
you want to use this in if you don't
you'll need to like make your own
discord server and stuff - so just make
a discord account and then when you open
up you know discord there should be like
a little thing I don't know if I can
bring mine over or not let's see it says
streamer mode enabled so maybe it'll be
safe anyway like right here the little
button go ahead and click that you can
make your own server so once you've done
that we're gonna head to the discord app
comm slash developer slash applications
you probably won't have anything here
I've got a couple already but you'll
click on create an application so we
click on that we'll call this tutorial
but we don't need to know the client
secret but we do want to know the client
ID so go ahead and copy that save that
for a little later and we'll hit Save
Changes well I've got that copied I'm
just gonna come over here paste that in
that's the ID approach to write ID
before I forget what that was then what
we're gonna do is
is you've got a bot and we'll go add a
bot yes do it
a wild bot has appeared okay so now what
we're gonna do is a tutorial bot is fine
then what we do need is the token so I'm
gonna go ahead and hit click copy on the
token and I'm gonna come over here and
I'm gonna paste it
I don't plant I hope to remember to
delete this bot but anyway so please
don't use the token if ever again
public bot so whether or not everyone
else can add the bot that's fine we'll
leave that and then coming on down here
all the permissions so you know
depending on what you want your bot to
be able to do you might want to pick
these this is not set in stone though
you can change it later so for now
mainly I want to be able to definitely
send messages read message message
history honestly can't remember what
manage message messages is I don't know
if that's like like the bot could delete
messages possibly that might be it
anyway add reactions stuff like that I
don't know but moat mainly right now
let's send messages and read message
history but the biggest one is read
message hit message history but if you
want to be able to interact with it
probably send messages whenever you know
with that that'll give you a permissions
integer so you can go ahead and copy
that basically it's gonna happen it's
going to create a roll specific to your
bot so later you can go in and add or
change permissions as you want but I'm
gonna go ahead and save that permissions
thing to whoops okay so once we have
that it should be all save tutorial bot
I think we're ready to go so the next
thing we want to do is the following URL
I'm just going to copy it come over here
that was our permissions int this is the
URL we're gonna use so this is just to
authorize a specific client on your
server and this would be the same thing
someone else might use if you wanted to
if they wanted to use your I your bot so
first we have the permission integer so
we just paste that in and then the ID
I'm going to
copy that and then we paste that in
right here and now you're ready to
invite the actual but now where did I
here it is let me just paste that in
real quick okay tutorial bot add the bot
your server tells you what the
permissions will be it looks good so
let's go ahead oh wait we got a pic a
server sent X will it do
authorize I am NOT a robot just trying
to add one authorized ok so once we've
got that authorized were ready to
actually write a bot so um I think I'm
gonna close that and we can just come
right here I'm gonna leave this stuff up
just in case I'm gonna need it in a
minute anyways and let's actually start
to write so first of all we're going to
import discord because we are making a
discord bot
the next thing is client equals discord
dot clients that just kind of initiates
the client for us and then now there's
kind of two main ways that you can use
discord pie one is with just straight
object-oriented programming you can kind
of create your client object and do
things there or you can use wrappers and
functions and stuff and so I'm gonna use
the wrappers so first of all you can do
at client dot event and basically what
this is is it's just a event decorator
slash wrapper if if you don't know much
about those you can check out Python
programming dotnet search for decorator
you pull this over whoops maybe yeah and
you can go to click on that decorators
Python tutorial and you can learn a
bunch about decorators if you wish so ok
whoops gosh
okay got everything under control so
that's gonna be our our wrapper here so
basically it's any time you know some
some sort of event is about to occur
what do we want to do so first we're
gonna do a sync define on ready and this
is basically just whoops this is just
gonna be called one time yeah one time
when the bot is you know fully connected
basically to the actual server itself so
we're gonna say here is just print will
print an F string and we'll just say we
have logged in as and then client dot
user and that'll just output what you
know who we've connected as so then we
can come down here and we can actually
say client run and then we want to run
based on this token so I'm gonna copy
this paste and we could just make sure
everything's working up to this point so
I'm just gonna run that real quick and
see if it connects we've logged in as
tutorial bot and I think just for
further testing I'm gonna come down to
testing stuff and see edit that channel
will go to permissions role tutorial bot
so we'll add him and then read messages
send messages and where's the message
history this one always gets me like
read messages and you really need to
have read message history whatever
that's about okay so so there's tutorial
bots they are actually already in here
so hopefully hopefully my other BOTS
isn't going to get in the way anyway so
so the connection worked we're logged in
great so now what we want to do is maybe
maybe actually have handle for certain
events that actually occurs so we're
gonna say yet another act client event
and this one will just say async define
on message and then what gets passed
here is just any old message and then we
can print and then this there's like all
kinds of stuff that come from the mess
you've got a message message dot channel
you definitely want to know which
channel it was set in that way if you
ever if you want to reply you have to
reply back to the you know your ideally
you're going to reply back to that same
channel message channel and then then
what I'm going to do is just do this
like channel probably like these three
things or four rather then we'll do
author and then there's author names so
one of these will just be their like
their nickname the other one is the
actual the actual real screen name with
like the number on it and stuff and then
message dot content for the actual
message itself so let's just rerun that
one more time and then this one this
should read from all channels but just
in case nobody says anything while it's
running I'll just say something in this
chat so like for example will do hi
there and so as you can see in the
testing stuff channel sent text number
seven seven says hi there basically okay
easy enough so now not only can at this
point we're just kind of reading things
we're not actually doing anything so if
you wanted you could do stuff based on
what people say so a lot of times people
have you know certain commands so you
might look for an exclamation mark and
then some sort of command like kick and
then someone's user name for example or
their nickname so you can do stuff like
that probably kick is not really useful
because you can do that already pretty
simply but anyway it's just as an idea
you can you can use exclamation mark but
you could use anything you want but for
example one thing that we could do is
something like this like so we could say
if if hi there in message dot content I
don't think I think we would actually be
able to get away with this what we'll
test this real quick but I can't
remember if I have to convert that to a
string or not I think it should be
string but we'll see if I there in
message content lower let's just make
sure
handle both cases what do we want to do
well what we could say is we could have
the bots like reply back so we could
await and then a message ja channel dot
send hi like that let's go ahead and run
that again wait friend okay and then I
can just say hi there again and you can
see here that the tutorial bot replied
again but if I don't say hi there and I
just say how's it going tutorial bot
doesn't say anything right because we've
got some really really advanced logic
there ok so that's all for this tutorial
I'll try to make that as short and quick
as possible for me I'm gonna have to
remember to delete this token
immediately but that's really all I want
to show here like I said there's so much
here that you can do like you can do
anything like the first spot I made I
made it to change users nicknames like
so you can change people's like display
name basically and any time they try to
change it back and just immediately
change it back again so I'm a really
great discord host by the way joining my
discord discord GG's Authentics but
there's just like so much that you could
have it automatically create emojis you
can have it you know do reactions stuff
like that play files you can it can just
do so much that even though I'm gonna
like create a bot with this we're just
gonna do so little what's available here
I do just wish there documentation like
this is pretty full documentation in
terms of what's available but their
documentation for like getting started
is like a pain in the butt to be honest
with you so anyways that's all for now
stay tuned for a more interesting but
I'd like to have the bots searched
Python programming net for like
tutorials stuff like that
among doing some other you know typical
tasks that I wind up doing a lot in
discord hi so quick shout out to my
recent channel members
max Dinesh Kumar angel' font although
Martin Laursen and Zechariah Vickers
thank you guys very much for your
support I really enjoy my job and you
guys make it possible so thanks again so
that's all for now
questions comments concerns leave them
below or join the discord and get your
Nick changed until next time