Skip to main content

A module for making setup wizards easily.

Project description

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

Project details


Download files

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

Source Distribution

discord-ext-wizards-0.3.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

discord_ext_wizards-0.3.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file discord-ext-wizards-0.3.0.tar.gz.

File metadata

  • Download URL: discord-ext-wizards-0.3.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for discord-ext-wizards-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5aed164f10276a616e207696119d63848d794ce22b919e2c263d5395885b3b91
MD5 988d1fa89dd2481747c362debfd6849c
BLAKE2b-256 832b4aa0c333cc0ca421f6f2c9c46762c5514768473352cade25f7370abbb811

See more details on using hashes here.

File details

Details for the file discord_ext_wizards-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: discord_ext_wizards-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for discord_ext_wizards-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0792af4947e83171f2d2031d5afec2754598e826e2dd2e5957ca6691797fecf5
MD5 61c4d137039af188e8172888ecb4eac8
BLAKE2b-256 23e88cdf71f1bf2ea9a0bb358bf453baeb36b75dfde3d427c67dbcb6af74a5a3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page