Skip to content

Conversation

EnokiUN
Copy link
Contributor

@EnokiUN EnokiUN commented Mar 8, 2022

No description provided.

Copy link
Contributor

@EmmmaTech EmmmaTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, here are some changes that you might wanna make

With the tasks extension you can make background tasks without worrying about the asyncio hell and stuff like "what if my internet dies" and "how do I handle reconnecting" with the added benifit of alot of useful additions that are one line of code away!

### Example Usage
```py title="Example Usage"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the title field is needed


If you do run this code in your terminal you should see something like this after about 15 seconds:

```sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sh code block indicator is also not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay

async def very_useful_task():
print('doing very useful stuff.')

bot.run(your token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe replace the your token text with "TOKEN"

# ...
```

## [Tasks](https://docs.pycord.dev/en/master/ext/tasks/index.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an extra newline after this line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be fixed with formatting


These attributes serve as a really powerful asset to get info about your loop.

### Example
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an extra newline after this line.

```

For a more usful example here's a task in a cog context ripped straight from the [docs](https://docs.pycord.dev/en/master/ext/tasks/index.html#recepies):
```py title="Cog Example"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the title field is needed

Now let's create a cog that handles a leaderboard we have in our bot using Tasks then explain what we did after that and also provide a refresher of how slash commands groups work in cogs.

For the sake of this example let's pretend that we have a leaderboard module that does all the leaderboard handling for us and that computing the leaderboard is very expensive computationally wise so we want to store one version of it that gets regularly updated insetad of generating it every time someone calls the `/leaderboard view` command.
```py title="Using Tasks"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the title field is needed

@EnokiUN
Copy link
Contributor Author

EnokiUN commented Mar 9, 2022

@emretech @BruceCodesGithub how's this

@VincentRPS VincentRPS merged commit 5bc4733 into master Mar 9, 2022
@VincentRPS VincentRPS deleted the ext-tasks branch March 9, 2022 13:03
@BruceCodesGithub BruceCodesGithub mentioned this pull request Mar 14, 2022
35 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants