Skip to main content

Unstable experiments with interactions.py.

Project description

tansy

PyPI Downloads Code style: black

Unstable experiments with interactions.py.

Commands

tansy provides a unique way to define options for slash commands - a way that appears often in other Discord Python libraries.

Instead of needing a decorator per option or to define the option in one huge list, tansy allows you to define each option in the function itself. By using a special metadata function, you can specify what each argument/parameter in a function should be like as an option, with tansy smartly handling the rest for you.

import interactions as ipy
import tansy

@tansy.slash_command(name="test", description="Nice test command, huh?")
async def test_cmd(
    ctx: ipy.InteractionContext,
    the_user: ipy.User = tansy.Option(name="user", description="The user to ping."),
):
    await ctx.send(the_user.mention)

Class Slash Command

In case you want to try something very unique, or just want to leverage classes, tansy allows you to leverage its toolset to make class slash commands.

import interactions as ipy
import tansy

@tansy.class_slash_command(name="test", description="Nice test command, huh?")
class Test:
    the_user: ipy.User = tansy.Option(name="user", description="The user to ping.")

    async def callback(self, ctx: ipy.InteractionContext):
        await ctx.send(self.the_user.mention)

Note that the class is being read and adjusted to be more like a typical functional declaration, and so isn't a fully true class-based approach. Subclasses are not going to become subcommands (though class_subcommand exists), and while the class does get initialized on every run (meaning you can use custom __init__s, as long as they have no parameters that need to be filled in), the class is largely untouched outside of declaration and using callback.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tansy-0.10.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tansy-0.10.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file tansy-0.10.0.tar.gz.

File metadata

  • Download URL: tansy-0.10.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for tansy-0.10.0.tar.gz
Algorithm Hash digest
SHA256 be7163066825975e35a01bf25a4fcac94db9bcf4a183591eb7d9c59897bc2f5b
MD5 2e2b20e9b063b20eec336081bffb6b37
BLAKE2b-256 b7be025b0bb81e3a8bd63e3c37391c9db7663a26d8026a305c23bd5fe5c175a6

See more details on using hashes here.

File details

Details for the file tansy-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: tansy-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for tansy-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 883c5568335f86c9bcb2483bebe784e74ed29d1510ab96dbe4e2e4391dbbab30
MD5 fb0e7526ae641a43816fa79a19fbe0ee
BLAKE2b-256 962e4fa0e3935286db1b9df2d5f607cd7133853339ca0a40a15c60d9614947cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page