def test_register_subcommand_options():
    app = Flask(__name__)
    app.config["DONT_VALIDATE_SIGNATURE"] = True
    app.config["DONT_REGISTER_WITH_DISCORD"] = True

    discord = DiscordInteractions(app)

    group = discord.command_group("group")

    @group.command()
    def subcommand(ctx, option1: str, option2: float, option3: str = ""):
        return "pong"

    discord.update_commands()
Exemple #2
0
test_client = Client(discord)


# Simplest type of command: respond with a string
@discord.command()
def ping(ctx, pong: str = "pong"):
    "Respond with a friendly 'pong'!"
    return f"Pong {pong}!"


print(test_client.run("ping"))
print(test_client.run("ping", pong="ping"))


groupy = discord.command_group("groupy")


@groupy.command()
def group(ctx, embed: bool):
    if embed:
        return Message(embed={"title": "Groupy group"})
    else:
        return "Groupy group"


print(test_client.run("groupy", "group", True))
print(test_client.run("groupy", "group", False))


@discord.command(
Exemple #3
0
# You can use the thread loop even from non-async commands
@discord.command()
def wait_partly_sync(ctx, seconds: int):
    "A synchronous command that uses the event loop for waiting."

    async def do_followup():
        await asyncio.sleep(seconds)
        ctx.edit("Done!")  # We are passed a Context, not an AsyncContext

    asyncio.create_task(do_followup())
    return Message(deferred=True)


# Async subcommands also work, and they can access context
toplevel = discord.command_group("toplevel", is_async=True)
secondlevel = toplevel.subgroup("secondlevel", is_async=True)


@secondlevel.command()
async def thirdlevel(ctx):
    async def do_followup():
        print(type(ctx))
        await asyncio.sleep(1)
        await ctx.edit(f"Hello, {ctx.author.display_name}!")

    asyncio.create_task(do_followup())
    return Message(deferred=True)


# Use set_route_async if you want to use Quart
@discord.command()
def unlock_command(ctx):
    "Unlock the secret command"

    ctx.overwrite_permissions([Permission(user=ctx.author.id)],
                              "locked_command")

    return "Unlocked!"


# Command groups can have permissions at the top level

group = discord.command_group(
    "group",
    default_permission=False,
    permissions=[Permission(role="786840072891662336")],
)


@group.command()
def locked_subcommand(ctx):
    "Locked subcommand"

    return "You have unlocked the secret subcommand!"


@group.command()
def lock_me_out(ctx):
    "Lock me out of this group"
Exemple #5
0
sys.path.insert(1, ".")

from flask_discord_interactions import DiscordInteractions, Message

app = Flask(__name__)
discord = DiscordInteractions(app)

app.config["DISCORD_CLIENT_ID"] = os.environ["DISCORD_CLIENT_ID"]
app.config["DISCORD_PUBLIC_KEY"] = os.environ["DISCORD_PUBLIC_KEY"]
app.config["DISCORD_CLIENT_SECRET"] = os.environ["DISCORD_CLIENT_SECRET"]

discord.update_commands()

# You can use a decorator syntax to define subcommands
comic = discord.command_group("comic")


@comic.command()
def xkcd(ctx, number: int):
    return f"https://xkcd.com/{number}/"


@comic.command()
def homestuck(ctx, number: int):
    return f"https://homestuck.com/story/{number}"


# Subcommand groups are also supported
base = discord.command_group("base", "Convert a number between bases")