This is an alternative to XuaTheGrate/Flag-Parsing, which is not maintained.
⚠ Please be sure to read the entire README, it explains some important tricks.
Flag Parsing
A util for discord.py bots that allow passing flags into commands.
To install, run the following command:
pip install alt-discord-flags
2.1.0 changes how signatures appear. If you wish to use
the legacy signatures, use command.old_signature instead.
Basic example usage:
import discord
from discord.ext import flags, commands
bot = commands.Bot("!")
# Invocation: !flags --count=5 --string "hello world" --user Xua --thing y
@flags.add_flag("--count", type=int, default=10)
@flags.add_flag("--string", default="hello!")
@flags.add_flag("--user", type=discord.User)
@flags.add_flag("--thing", type=bool)
@flags.command()
async def flags(ctx, **flags):
await ctx.send("--count={count!r}, --string={string!r}, --user={user!r}, --thing={thing!r}".format(**flags))
bot.add_command(flags)
Important note that @flags.command MUST be under all @flags.add_flag
decorators.
@flags.add_flag takes the same arguments as argparse.ArgumentParser.add_argument
to keep things simple.
Subcommands are just as simple:
@commands.group()
async def my_group(ctx):
...
@flags.add_flag("-n")
@my_group.command(cls=flags.FlagCommand)
async def my_subcommand(ctx, **flags):
...
Usage of discord.py's consume rest behaviour is not perfect with discord-flags,
meaning that you have to use a flag workaround:
@flags.add_flag("message", nargs="+")
@flags.command()
async def my_command(ctx, arg1, **options):
""" You can now access `message` via `options['message']` """
message = ' '.join(options['message'])
Metadata
Release files for alt-discord-flags 0.0.5
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 |
|---|---|---|---|---|
| alt-discord-flags-0.0.5.tar.gz | 5.7 kB | Without provenance | Details for alt-discord-flags-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alt_discord_flags-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for alt_discord_flags-0.0.5-py3-none-any.whl |
Total release size: 12.4 kB
Release files / alt-discord-flags-0.0.5.tar.gz
| Download URL | alt-discord-flags-0.0.5.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
333bf26d32da38d3160fd63e7c11cde1e1909db1532b3ef94f3f60ff02216ead
|
|
BLAKE2b-256 checksum How to use checksums |
ce1ed08c0178dbce6b8fec77a8580e2aea7f001d01716fc6af0b6bd7658ecd1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0
|
Release files / alt_discord_flags-0.0.5-py3-none-any.whl
| Download URL | alt_discord_flags-0.0.5-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f48e24805927c033c2c3ed077a881ea5b36e6bea2dbfd8e20a15e2de58fe248a
|
|
BLAKE2b-256 checksum How to use checksums |
55b473458536104be4412effaf49c4201aacb23e6343d3254f6a3d73fa13586d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.0 importlib_metadata/3.7.3 packaging/20.9 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0
|
Security for alt-discord-flags 0.0.5
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.