Placeholder Image

字幕表 動画を再生する

  • What's going on?

  • Everybody welcome to part three of the making bots with discord pie tutorial Siri's in this video are gonna be working on is something a little different.

  • So most of this stuff is just using, you know, a command on DDE.

  • Have that command do some stuff.

  • So you're just like reading a message in performing some logic.

  • It's all basically the same stuff.

  • It's just, you know, how creative do you want to get with it?

  • Um, Now what I want to do in this video is talk about how we can time certain actions.

  • So that's not really something we've covered yet.

  • So let's go ahead and get into it.

  • So the thing that I want a time is I want to just output toe like a C S V.

  • The's like user metrics, basically, but I don't want to do it.

  • I don't want to, like have to sit here and call the command.

  • Every time I want it to happen, I'd like it just automatically happen.

  • So the first thing that I want to do is put this into a function because I basically want the exact same thing to occur.

  • I just wanted to occur in its own function.

  • The other thing we really need to do is like Centex Guild, because we're gonna do this, like, right now, we could pass the guild to the function.

  • So, like, for example, um, I'll just come up here and we'll just define community report, and then community report will get guild past to it.

  • And then we're just going to take this copy paste and have that over, and then we can just return online Idol offline.

  • Then we do this.

  • And in fact, actually, I think I'll do this.

  • Copy that.

  • And then we come in here and we'll say online Idol offline Eagles community report, um, and then the Centex Underscore Guild.

  • So now that should give us the community report.

  • And in fact, let's just go ahead and test that really quick.

  • Make sure I didn't make any mistakes.

  • Uh, center, but you poor Oh, we didn't neck OSC.

  • No, we do.

  • So how come it didn't, um, community report sent?

  • They bought dot community.

  • Did I spell it wrong?

  • No center.

  • Oh, okay.

  • I forgot the died.

  • Didn't underscore rather than died.

  • Okay, so we did get an error Centex Guild is not defined, do we?

  • Yeah.

  • Okay, so I needed This needs to be changed.

  • Guild save.

  • Come back over here.

  • Uh, let me, uh, sent a bond dot Log out and let's try that one more time.

  • Close of these two.

  • Okay, so this time, let's run the community report, make sure that's working as intended.

  • Okay, great.

  • All right.

  • So we've moved that.

  • We just move this up here.

  • Um, so now we want to do is add a background task that also calls this but saves it.

  • So the way that we're gonna do that is by 1st 1st I think what we'll do is we'll just write the background task.

  • So just somewhere up here, um, actually, maybe after the community report, um, we will write the task, so this will be a sink deaf.

  • Ah, user metrics, background, um, in background task.

  • Empty palms here.

  • And then what we want to do is await client dot Uh, wait until ready.

  • And then we need that Centex Guild.

  • So part of me kind of regrets going with the wrappers.

  • Because if this was Opie, this would be so simple.

  • You had given attributes And in this case, there's there are ways that we can share this like, basically, I just want to keep defining it.

  • It's not the end of the world like we could have, like a maybe a constant.

  • So Centex killed equals client get guild in the constant.

  • Um, we could do that, or we can use global's.

  • So I'm gonna use a global I know that's gonna just work.

  • Some people, um, you could use, like a ah a to pull like a dictionary or something like that.

  • Maybe, um, but I'm gonna just I'm just gonna go ahead and global this.

  • So I'm gonna from Global Global Centex Guild, and then we after we do that, we can just come up thio this wait, await client until ready, and then once it's ready, we'll global the Semtex skilled.

  • So then, while not client dot is closed, this is just a a method that we can call in the client.

  • So while that's not the case, we're gonna throw in a try, except because if we don't do this at any point, if it fails in this loop or background, task is gonna quit, and it's not gonna continue running.

  • So we are going to try and accept, uh, exception as he and will just print string either.

  • And what we want to try is basically this exact uh, what is this?

  • This this line here.

  • So I'm gonna copy it.

  • Come back up here.

  • Paced online Idol offline Community report Centex Guild.

  • We've global did it.

  • So we should be all set to use it there.

  • Then what we want to do now that we have those metrics is with open and then we'll just call this user Metric Stott C s V.

  • We're gonna open with the intention to upend as f we're gonna f dot Right?

  • We're gonna write an F string that has four values, actually, three for the first value will be time, so I'm gonna go ahead.

  • And actually, I think we're not using sis anymore.

  • That didn't solve it for us.

  • So I'm gonna get rid of cysts.

  • That's where it usually if you don't use something, though it says, hey, you're not using it.

  • Are we actually using it somewhere?

  • We're not.

  • That's kind of weird.

  • Usually it alerts me.

  • Oh, maybe it is alerting me.

  • Usually has a little dot though.

  • Anyway, let's import time.

  • We're also gonna import a sink.

  • Io, um and we're gonna We're importing a sink.

  • A sink I owe.

  • So we can do in a sinker and asleep as well.

  • This way doesn't impact the rest of our functionality.

  • Which, by the way, if you don't know much about co routines and all that kind of stuff since we're using them so heavily here, um, if you go to python programming dot net and search for a sink, you'll find a sink.

  • Io basics.

  • Go ahead and click on that.

  • And that will take you here and you can see get a tutorial on a sink.

  • Io Um, so yeah.

  • Okay, so, uh, back to here.

  • So what we want to write is we'll do the invaluable of time dot time we will do.

  • Uh then we'll do online idol offline, and then we'll do a new line, and, uh, that should be good.

  • So once we've done that, once we've saved that file, we're just gonna do in await a sink io dot Sleep.

  • For how long?

  • Now, I'm probably gonna do something like 600.

  • I don't really need these metrics like super frequently, but for the purpose of the editorial, I'm gonna say five for now.

  • Also, if we do hit an air, let's go ahead and sleep.

  • There is, well, no reason to pit that air.

  • Like, a 1,000,000 times If we hit an air, probably it'll be something wrong with the Guild.

  • It will be my guess.

  • Um, it's gonna take a second toe, pull the guild in, even though, which is kind of weird, because I would think until ready.

  • But maybe if we could wait until oh, the guilt isn't Let's see, Let's define the guild.

  • Let's cut that here.

  • Paste here.

  • That was stupid.

  • So it wouldn't work until we had a message.

  • Uh, cut here, paste here.

  • And then let's global Centex killed here because we're gonna need it.

  • And I bet that'll solve the issue for us.

  • We'll see if it doesn't, though, So let's just go ahead and save that.

  • Now, Uh, what we need to do is call this to actually occur.

  • So this is just a background test that we want to run.

  • So where should we call it?

  • Well, we we could call in a few places, but I'm gonna call it right before a client dot run.

  • That's the way they suggest we do it so sweet.

  • I'm gonna do it So kalai int dot loop dot create underscore task and then we just want to create that task name.

  • So are basically run it.

  • So it's that user metrics background task.

  • Don't forget your parentheses.

  • Boom, and that should be everything.

  • Let's go ahead and run it.

  • We'll see what happens if we hit any errors.

  • I see scented body in the chat.

  • Uh, Centex Guild.

  • Not defined initially, Let's just wait such kind of weird We got, um, some chat information and then it said we logged in already.

  • That's kind of weird.

  • I'm not sure what to think about that.

  • I don't know if it's because, like luke dot create task, but luke dot create task starts with.

  • Wait until ready.

  • If anything, maybe we should define the guild in here and global it everywhere else.

  • But then it would be defined every no cause.

  • It's in the wild, not I want to try that.

  • Let's see if that will cause problems, but we'll do that in a moment.

  • Let me pull up here.

  • So here's user metrics that C s V.

  • Sure enough there we have all of our metrics.

  • Hopefully every five seconds.

  • Any second now There it is.

  • There's an update.

  • So pretty cool.

  • Looks like we've Ah, 88 89 90.

  • We're gaining users.

  • And then we lost a couple.

  • Darn it!

  • Interesting.

  • So over time, I've forgot already.

  • This is probably online Idol and then offline.

  • And then you could add these all up to get total users.

  • Um and then this is just time you the UNIX time stamp.

  • Cool.

  • Okay, so last thing I want to try it is rather than on ready.

  • Let's continue global ing Centex Gilb!

  • Let's cut it here.

  • And let's paste Centex Guild in his background task.

  • Just cure use.

  • So I'm gonna kick out the bought real quick.

  • Oh, okay.

  • I just took a second.

  • He didn't like leave, Okay?

  • And then I'm gonna rerun it.

  • We'll see how we do his back.

  • No airs yet.

  • Cool.

  • Okay, so we'll stop it there.

  • Global probably isn't the best way to handle this problem, but at least we're not hitting an air anymore.

  • I just really wanted to solve that.

  • Okay, so I think that's enough for now, in the next tutorial, what I'd like to cover is something I would like to let this run.

  • Let's fix this.

  • I would liketo let this run for at least, like a day or two days or something like that, and then show you guys like the next command would be to, like, change community report toe, actually be like a cool report rather than just numbers.

  • Well, we could do is have have a muse like Matt live or Pie gal or any of the 1,000,000 plotting options that we have available to us to generate an output toe like a PNG image.

  • And then we can actually submit that PNG image with the bots so it can actually embed that image and upload that image.

  • So when we do a community report, we could see, like trends over time and stuff, so that would be pretty darn awesome.

  • So, uh, that's what I'd like to do next.

  • Because again, most of this stuff is just kind of command, stuff like that.

  • It's just a bunch of the same stuff.

  • So I think that's kind of boring, but I'd like to do something a little different.

  • So attaching files and uploading files I don't yet know really how to do that.

  • Um, that's something a little unique.

  • So that's what we're going to be doing in the next tutorial.

  • Quick shoutout to my most recent members, Taj Al Agha Wani Scott Harwood are June suck Deva?

  • I don't know, Stefan are and some guy thank you guys very much for your support, You guys especially Scott Hardwood.

  • Uh, okay, so that's it for now.

  • Questions, comments, concerns.

  • If you have, ah, suggestion about how to handle and not use Global's in a nice clean way Um, let me know in the consulate.

  • Otherwise, I will see you guys in the next tutorial where we are uploading some beautiful charts.

What's going on?

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

ボットアクションのタイミング - Discordpy 1.0.0.0 p.3でDiscordボットを作る (Timing bot actions - making Discord bots with Discordpy 1.0.0 p.3)

  • 1 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語