Coder Social home page Coder Social logo

tansy's Introduction

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.

tansy's People

Contributors

astreatss avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.