Simple example, triggers every 3 seconds:
from interactions.ext.tasks import IntervalTrigger, create_task
@create_task(IntervalTrigger(3))
async def my_task():
print("hi")
my_task.start()
Multiple conditions (example will be improved when more triggers are added)
The task will only run every 5 seconds because every trigger needs to be ready
from interactions.ext.tasks import IntervalTrigger, create_task
@create_task(IntervalTrigger(3), IntervalTrigger(5))
async def my_task():
print("hi")
my_task.start()
To have the task run when any trigger is ready, use the OrTrigger.
The task will run every 3 and 5 seconds (it may run twice occasionally due to how timing works)
from interactions.ext.tasks import IntervalTrigger, OrTrigger, create_task
@create_task(OrTrigger(IntervalTrigger(3), IntervalTrigger(5)))
async def my_task():
print("hi")
my_task.start()
Classes are special, due to how functions turn into methods and other python black magic
There are two ways to properly do tasks in classes
The first way is to pass self when starting the task
Any args or kwargs passed to Task.start() will be prepended to the function
from interactions import Extension
from interactions.ext.tasks import IntervalTrigger, create_task
class Cog(Extension):
def __init__(self, client):
self.method.start(self)
@create_task(IntervalTrigger(1))
async def method(self):
print(self)
The other way is just to wrap the method manually
from interactions import Extension
from interactions.ext.tasks import IntervalTrigger, create_task
class Cog(Extension):
def __init__(self, client):
self.method = create_task(IntervalTrigger(1))(self.method)
self.method.start()
async def method(self):
print(self)
Metadata
Release files for interactions-tasks 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| interactions-tasks-1.0.0.tar.gz | 4.9 kB | Without provenance | Details for interactions-tasks-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| interactions_tasks-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for interactions_tasks-1.0.0-py3-none-any.whl |
Total release size: 10.4 kB
Release files / interactions-tasks-1.0.0.tar.gz
| Download URL | interactions-tasks-1.0.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8ab83788bdd06fb43fd79ed867bcfa6fba268ce94916ac4c986bd3182d7c4d5c
|
|
BLAKE2b-256 checksum How to use checksums |
7de4b727cecef2002315ed5dfd1239d3a8ded290199e8d911fcae26931b59b42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / interactions_tasks-1.0.0-py3-none-any.whl
| Download URL | interactions_tasks-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73f389670a8968dc1e77dedaec4345a509f6c039a092da5715137b4f09e2c19e
|
|
BLAKE2b-256 checksum How to use checksums |
93615c787239e3bf051f69cc7f45b57067d213c1120151c443d0b0c58582f26f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for interactions-tasks 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.