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.9.2.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

tansy-0.9.2-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tansy-0.9.2.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for tansy-0.9.2.tar.gz
Algorithm Hash digest
SHA256 5d676d3720c5403a3fbe1ad951fabdf126172c442c323f97608df654da01482a
MD5 a9f71e7f12861e4002220bd773b802e9
BLAKE2b-256 b5dd0974d4ea5c22c87ded9c645aa1a0892edfb54edf210700787786e35e8ea2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tansy-0.9.2-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for tansy-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f294c08ccea16cef8a333b2206599df98891726eb85360f8dcdded0637c4fc13
MD5 5194186d7f3a55b87a14bebf454e8713
BLAKE2b-256 49e9e053a310472d406fcb0d6a91b293e66fedafedbade9df90a400720dc686c

See more details on using hashes here.

Supported by

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