Skip to main content

A extension allowing you to pass flags as arguments.

Project description

version python-s license-s

âš  Please be sure to read the entire README, it explains some important tricks.

Flag Parsing

A util for bots that allow passing flags into commands.

To install, run the following command:

pip install discord-flags

You can install the legacy parser by running:

pip install discord-flags==1.5.2

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)
async def flags(ctx, **flags):
    await ctx.send("--count={count!r}, --string={string!r}, --user={user!r}, --thing={thing!r}".format(**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:
async def my_group(ctx):

async def my_subcommand(ctx, **flags):

Usage of's consume rest behaviour is not perfect with discord-flags, meaning that you have to use a flag workaround:

@flags.add_flag("message", nargs="+")
async def my_command(ctx, arg1, **options):
    """ You can now access `message` via `options['message'][0]` """

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for discord-flags, version 2.1.1
Filename, size File type Python version Upload date Hashes
Filename, size discord_flags-2.1.1-py3-none-any.whl (8.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size discord-flags-2.1.1.tar.gz (6.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page