A Discord.py extension allowing you to pass flags as arguments.
Reason this release was yanked:
Bugs
Project description
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'])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for alt_discord_flags-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28b820205fd4df6b12a24dec57e1216d71b2e5b899583b2da4763c487f5df2dd |
|
MD5 | fbb6d113d98e46e4e1dec2f51009fac4 |
|
BLAKE2b-256 | 080f7642d37a29d781f2b007f7b4744fdea4c9fcbd80084d5a0c4359747c1a21 |