Skip to main content

Typed Flags

A Typehint based system for including flag input in your discord.py commands.

Why bother with numerous decorators and patched commands when you just typehint your input to receive command flags?

Examples


Usage is as simple as typehinting the entire input argument string to TypedFlags, this in turn will convert everything and will return this argument as a dict of key:value pairs where each key is the flag, and the value is the value for that flag

from typed_flags import TypedFlags

@bot.command()
async def test(ctx, *, args: TypedFlags):
    # Send all of command args
    await ctx.send(args)

An example calling the above code: %test this "Lol ez" --try:=test string --hard:=This is kinda cool

args = {None: ['this', 'Lol ez'], 'try': 'test string', 'hard': 'This is kinda cool'}

A further example: %test --try:=test string --hard:=lol This is kinda cool

args = {'try': 'test string', 'hard': 'lol This is kinda cool'}

Note: Since we have no argless arguments, it is not in the returned data

Customization


You can customize two things, the string to preceed any flag values as well as the string to split up between the flag and its value. Both of these are keyword arguments when initializing TypedFlags

  • start: str -> The string to preceed any flags (Defaults to --)
  • delim: str -> What to split flags with to get the key:value split (Defaults to :=)

You do not have to provide these values. There are defaults in place. It is only for customization purposes

Important Notes


This package works in-line with how discord.py handles command parsing and consumption. That is to say the argument Hello world will be two variables, where as the argument "Hello world" will be parsed as one argument. This is something important to understand otherwise you will experience unexpected behaviour.

However, this only applies to 'flagless' arguments. Values between flags are considered to be all part of said flag (See examples)


Any arguments not associated with a flag will be added to the dictionary under the key None. The value for this key is a list containing all of the arguments found that do not corrospond to a given flag.

It is also important to note that if no flagless values are detected then this key will not be in the dictionary. You should check for this in your code.


Any arguments in argless are ordered according to the order they were received.

Metadata

Release files for discord-typed-flags 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord-typed-flags 1.1.4
File Size Uploaded
discord-typed-flags-1.1.4.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-typed-flags 1.1.4
File Interpreter ABI Platform
discord_typed_flags-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / discord-typed-flags-1.1.4.tar.gz

Download URL discord-typed-flags-1.1.4.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a600e1a41b97cfb9a0afad84f9b56033dcaaa47bfe38c2b2c494862f5123a142
BLAKE2b-256 checksum
How to use checksums
50d4d577b5b15b3e01f8fb3b8719fb250ccb36377a76166b2d306c654c9b6045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

Release files / discord_typed_flags-1.1.4-py3-none-any.whl

Download URL discord_typed_flags-1.1.4-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f082a1671eebb302b9083df3e1a4b52e25e9adee2fca6db2c192c2e5baf07ba1
BLAKE2b-256 checksum
How to use checksums
2bf22ed1cae9a727c742545c19a22f7adb189896480ac9dc120a5953ac711294
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.5

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page