what is going on everybody and welcome
to part 4 of the bots in discord with
this chord pie tutorial series in this
video what we're doing is working on
attachments how can we make an
attachment in this case with an image
and that image is a graph over time of
our 1 at least one of our user metrics
eventually I'd like to make like
multiple axes and show them all and
stuff I'm not gonna get too crazy with
that here mostly I just want to show you
guys how you can make an attachment so
to begin we need to first actually graph
the metric the metrics themselves so
let's go over the code for that really
really quickly or I could just
copy/paste this bit I think I'm just
gonna copy and paste it it's in the
text-based version of the tutorial so
that link will be in the description and
I'll just kind of explain it so here
we're using pandas matplotlib and
changing the style all this stuff if you
don't know anything about pandas or
matplotlib I've got tutorials on all
those then all we're doing we're reading
in the user metrics we're assigning the
column names the time is in unix time so
then we just convert the time to an
actual date time we compute a total
column because eventually I'd like to
show total users over time like that
user growth then we get rid of the time
column itself because I see you next
time we don't care about that we're
gonna set the date as the index later we
can resample like right now this is
every 5 seconds so there's way too much
and later if you wanted to show a big
graph you might have way too much data
you might want to resample or something
but for now it's good enough in this
case we print the head just to see what
we're working with we plot show the
legend show the plot and then save the
actual figure so let me go ahead and run
that real quick so you can just see so
this will be the graph that we show
there's just dead time here cuz the bot
wasn't actually connected to the server
I was this is probably where I was
filming a tutorial actually so anyway
you can see the growth over time this is
just the last I don't know 40 minutes so
yeah I didn't have enough patience to
wait a few days so so here we are
didn't actually know the answer to this
question so we had to figure it out okay
so so this is the the code that we want
to do to actually save the image so
basically we want to take this code and
add it to that background you know the
user metrics background so I am going to
copy this code come over here and
basically after we save the metric let's
just paste
let's tab this stuff over great and then
before before we actually start plotting
let's do a PL T dot CLF and that should
clear the figure if we don't do that
what's gonna happen is every time
because first of all we're not gonna do
a show we are gonna save the figure
locally if we don't do this basically
every 5 seconds this background task is
going to run and it's going to see this
plot operation we're sharing the axis so
it's just going to keep yeah it's just
gonna keep plotting that line but then
it's gonna have like the legend it'll
just be like a bunch of different colors
it'll mess it up so we're gonna clear
the figure every single time then when
we're done we save the figure as online
dot PNG and then our goal here is later
when someone goes to call the you know
community report it shows the graph so
before we forget let's also bring in our
imports here so I'm going to scroll up
paste that's all of our imports so now
we just want to attach the image itself
so right now it's just local
so under community report we'll go ahead
and keep this output also just to make
it kind of cool let's make it PI new
line so after it sends that message
that's just like the stats you know what
we want to do is we're going to say file
and that's going to equal a discord dot
file and then we specify that file it's
going to be on line dot PNG and the file
name itself on line dot PNG
then what we want to do is a wait and
then we're going to message channel
channel dot send and then we're going to
send on line on line dot PNG and then
file equals file so this will be like
whatever you put here I believe will be
like kind of like the title text to the
actual thing and then this will be the
thing that it actually attaches if you
forget PNG it'll still attach but I'm
pretty sure it doesn't convert it to an
image it needs to be like a dot PNG or
something like that okay so I think I
think with all that we're ready to
rhumble so let's go ahead and save that
let's start the bot hopefully we didn't
forget something we'll find out soon
enough I just kind of want to see it
speaking of scart harwood we're still
printing out the head let me just
comment that out I should have had that
or actually we just delete it so it
appears that that's all running and if I
open up here is the image so again you
can see there's a gap there I'm filming
this tutorial so it so anyways let me
close that so we're hoping to be able to
attach that so let's come over here
copy community report and let's paste
awesome so there you have that like
online dot PNG but you could call it
like anything you wanted anyways so now
we have attached this lovely awesome
graph might be cool to like maybe make
the background the same color as discord
off to grab that color for at least the
dark theme and then like make these
lighter that'd be kind of neat then it
would look like it's almost see-through
I think that's probably what I'm gonna
do but I'll spare you guys that also
probably include you know total users
over time and all that
and try to make it a little more fancy
but for now that's pretty cool so this
bot is slowly coming together so
probably at this point I'm gonna I'm not
sure what else I really want to show you
guys as far as basic discord PI is
concerned if there's like some sort of
task that you'd really like to see let
me know down below or if you've got some
sort of cool suggestion to add to the
bots the only thing I really haven't
shown you guys is a search functionality
for tutorials but besides that anything
else is I'm interested to hear what you
guys are looking for so with that as
usual quick shout out to my recent new
sort of new I recognize two of these
names members opponent Nathon e new
castle geek and Joab a stoolie new
castle geek and Joe past Julie are you
guys reading as members because some
people say that they don't show up on
that list again but certain names do so
comment below let me know if you're just
like canceling every time in reaping or
what if you didn't know how to support
and you haven't watched the other ones
don't forget there's that beautiful
button down below okay that's it for now
if you guys want to come and hang out
this core GG / cent Dex otherwise let me
know again what you guys want to see if
you want any other content with discord
pie otherwise so probably the end as I
start to kind of work on my bot anyway
till next time