Skip to main content

discord-ext-wizards

A module for creating setup wizards easily.

Example Usage

Below is an example usage of discord-ext-wizards to create an interactive embed builder.

import discord
from discord.ext import wizards, commands


class EmbedBuilderWizard(wizards.Wizard):
    def __init__(self):
        self.result = {}
        super().__init__(cleanup_after=False, timeout=30.0)

    # register an action, so users can type "stop" or "cancel" to stop
    # the wizard
    @wizards.action("stop", "cancel")
    async def cancel_wizard(self, message):
        await self.send("Wizard Cancelled.")
        await self.stop(wizards.StopReason.CANCELLED)

    @wizards.step(
        "What should the embed title be?",
        position=1
    )
    async def embed_title(self, message):
        self.result["title"] = message.content

    @wizards.step(
        "What should the embed description be?",
        timeout=180.0,  # override the default timeout of 30
        position=2,
    )
    async def embed_description(self, message):
        length = len(message.content)
        if length > 2000:
            await self.send(
                f"That description is {length} chars, but the maximum is 2000."
            )
            return await self.do_step(self.embed_description)  # redo the step
        self.result["description"] = message.content

    @wizards.step(
        "Type 1 to add a field, or 2 to move on.",
        position=3,
    )
    async def embed_fields(self, message):
        self.result.setdefault("fields", [])
        if message.content == "2":
            pass  # move on to the next step
        elif message.content == "1":
            field_name = await self.do_step(self.embed_field_name)
            field_value = await self.do_step(self.embed_field_value)
            field_inline = await self.do_step(self.embed_field_inline)
            self.result["fields"].append(
                (field_name, field_value, field_inline)
            )

            # repeat the step, so users can add multiple fields
            return await self.do_step(self.embed_fields)
        else:
            await self.send("Please choose 1 or 2.")
            return await self.do_step(self.embed_fields)

    @wizards.step(
        "What should the field name be?",
        call_internally=False,
    )
    async def embed_field_name(self, message):
        return message.content

    @wizards.step(
        "What should the field description be?",
        call_internally=False,
    )
    async def embed_field_value(self, message):
        return message.content

    @wizards.step(
        "Should the field be inline?",
        call_internally=False,
    )
    async def embed_field_inline(self, message):
        if message.content.lower().startswith("y"):
            return True
        elif message.content.lower().startswith("n"):
            return False
        else:
            await self.send("Please choose yes or no.")
            return await self.do_step(self.embed_field_inline)


bot = commands.Bot("!")


@bot.command()
async def embed(ctx):
    wizard = EmbedBuilderWizard()
    await wizard.start(ctx)
    result = wizard.result

    embed = discord.Embed(
        title=result["title"],
        description=result["description"],
    )
    for name, value, inline in result["fields"]:
        embed.add_field(name=name, value=value, inline=inline)

    await ctx.send(embed=embed)


bot.run("TOKEN")

See here for the output of the code: https://circuit.is-from.space/kox47xokm9a.mov

Metadata

Release files for discord-ext-wizards 0.3.0

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-ext-wizards 0.3.0
File Size Uploaded
discord-ext-wizards-0.3.0.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-ext-wizards 0.3.0
File Interpreter ABI Platform
discord_ext_wizards-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / discord-ext-wizards-0.3.0.tar.gz

Download URL discord-ext-wizards-0.3.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5aed164f10276a616e207696119d63848d794ce22b919e2c263d5395885b3b91
BLAKE2b-256 checksum
How to use checksums
832b4aa0c333cc0ca421f6f2c9c46762c5514768473352cade25f7370abbb811
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Release files / discord_ext_wizards-0.3.0-py3-none-any.whl

Download URL discord_ext_wizards-0.3.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0792af4947e83171f2d2031d5afec2754598e826e2dd2e5957ca6691797fecf5
BLAKE2b-256 checksum
How to use checksums
23e88cdf71f1bf2ea9a0bb358bf453baeb36b75dfde3d427c67dbcb6af74a5a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.2

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