예제 #1
0
def modal(ctx):
    fields = [
        ActionRow([
            TextInput(
                custom_id="name",
                label="What's your name?",
                placeholder="John Doe",
                style=TextStyles.SHORT,
                required=True,
            )
        ]),
        ActionRow([
            TextInput(
                custom_id="age",
                label="What's your age?",
                style=TextStyles.SHORT,
                min_length=1,
                max_length=5,
                required=False,
            )
        ]),
        ActionRow([
            TextInput(
                custom_id="description",
                label="Describe yourself:",
                value="A very interesting person",
                style=TextStyles.PARAGRAPH,
                min_length=10,
                max_length=2000,
            )
        ]),
    ]
    return Modal("example_modal", "Tell me about yourself", fields)
예제 #2
0
def launch_modal_from_button(ctx):
    return Message(
        content="Launch Modal",
        components=[
            ActionRow([Button(custom_id=launch_modal, label="Launch Modal")])
        ],
    )
예제 #3
0
def get_page_buttons(*handler):
    # Split into two ActionRows because you can only have 5 buttons per row
    handler = list(handler)

    return [
        ActionRow(components=[
            Button(
                style=ButtonStyles.PRIMARY,
                custom_id=(handler + [i]),
                label=f"Page {i}",
            ) for i in range(5)
        ]),
        ActionRow(components=[
            Button(
                style=ButtonStyles.PRIMARY,
                custom_id=(handler + [i]),
                label=f"Page {i}",
            ) for i in range(5, 10)
        ]),
    ]
예제 #4
0
 def button(ctx):
     return Message(
         content="Hi!",
         components=[
             ActionRow(components=[
                 Button(
                     style=ButtonStyles.PRIMARY,
                     custom_id="my_button",
                     label="My Button",
                 )
             ])
         ],
     )
예제 #5
0
def google(ctx):
    return Message(
        content="search engine",
        components=[
            ActionRow(
                components=[
                    Button(
                        style=ButtonStyles.LINK,
                        url="https://www.google.com/",
                        label="Go to google",
                    )
                ]
            )
        ],
    )
예제 #6
0
def do_nothing(ctx):
    return Message(
        content="Do nothing",
        components=[
            ActionRow(
                components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=handle_do_nothing,
                        label="Nothing at all!",
                    )
                ]
            )
        ],
    )
    def click_counter(ctx):
        "Count the number of button clicks"

        return Message(
            content=f"The button has been clicked 0 times",
            components=[
                ActionRow(components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=[handle_click, 0],
                        label="Click Me!",
                    )
                ])
            ],
        )
예제 #8
0
def launch_modal(ctx):
    return Modal(
        example_modal_2,
        "Tell me about yourself",
        [
            ActionRow([
                TextInput(
                    custom_id="name",
                    label="What's your name?",
                    placeholder="John Doe",
                    style=TextStyles.SHORT,
                    required=True,
                )
            ])
        ],
    )
예제 #9
0
def message_parse_demo(ctx):
    "Demonstrate the ability to parse the original message in a handler."

    return Message(
        content="The answer is 42",
        components=[
            ActionRow(
                components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=handle_parse_message,
                        label="What is the answer?",
                    )
                ]
            )
        ],
    )
예제 #10
0
def stateful_click_counter(ctx):
    "Count the number of button clicks for this specific button."

    return Message(
        content=f"Click the button!",
        components=[
            ActionRow(
                components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=[handle_stateful, ctx.id, 0],
                        label="Click Me!",
                    )
                ]
            )
        ],
    )
예제 #11
0
def username(ctx):
    "Show your username and discriminator"

    return Message(
        content="Show user info!",
        components=[
            ActionRow(
                components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=handle_avatar_view,
                        label="View User!",
                    )
                ]
            )
        ],
    )
    def handle_click(ctx):
        nonlocal click_count
        click_count += 1

        return Message(
            content=f"The button has been clicked {click_count} times",
            components=[
                ActionRow(components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=handle_click,
                        label="Click Me!",
                    )
                ])
            ],
            update=True,
        )
    def handle_click(ctx, click_count):
        click_count = int(click_count)
        click_count += 1

        return Message(
            content=f"{click_count} clicks",
            components=[
                ActionRow(components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=[handle_click, click_count],
                        label="Click Me!",
                    )
                ])
            ],
            update=True,
        )
예제 #14
0
 def selectmenu(ctx):
     return Message(
         content="Hi!",
         components=[
             ActionRow(components=[
                 SelectMenu(
                     custom_id="my_menu",
                     placeholder="Choose an option",
                     options=[
                         SelectMenuOption(label="Option 1",
                                          value="option1"),
                         SelectMenuOption(label="Option 2",
                                          value="option2"),
                     ],
                 )
             ])
         ],
     )
예제 #15
0
def handle_stateful(ctx, interaction_id, current_count: int):
    current_count += 1

    return Message(
        content=(
            f"This button has been clicked {current_count} times. "
            "Try calling this command multiple times to see--each button "
            "count is tracked separately!"
        ),
        components=[
            ActionRow(
                components=[
                    Button(
                        style=ButtonStyles.PRIMARY,
                        custom_id=[handle_stateful, interaction_id, current_count],
                        label="Click Me!",
                    )
                ]
            )
        ],
        update=True,
    )
def make_favorite_color_message(**kwargs):
    message_embed = Embed(
        title="What is your favorite color?",
        description=("Favorite colors so far: \n" +
                     ("\n".join(f"{name}: {color}"
                                for name, color in favorite_colors.items())
                      or "None yet -- be the first!")),
    )

    menu = SelectMenu(
        placeholder="Choose your favorite!",
        custom_id=handle_favorite_color,
        options=[
            SelectMenuOption(
                label="Red",
                value="red",
                description="The color of stop signs 🛑",
                emoji={"name": "🔴"},
            ),
            SelectMenuOption(
                label="Green",
                value="green",
                description="The color of plants 🌿",
                emoji={"name": "🟢"},
            ),
            SelectMenuOption(
                label="Blue",
                value="blue",
                description="The color of the ocean 🌊",
                emoji={"name": "🔵"},
            ),
        ],
        max_values=2,
    )

    return Message(embed=message_embed,
                   components=[ActionRow(components=[menu])],
                   **kwargs)
예제 #17
0
def voting(ctx, question: str):
    "Vote on something!"

    return Message(
        content=f"The question is: {question}",
        components=[
            ActionRow(
                components=[
                    Button(
                        style=ButtonStyles.SUCCESS,
                        custom_id=handle_upvote,
                        emoji={"name": "⬆️"},
                    ),
                    Button(
                        style=ButtonStyles.DANGER,
                        custom_id=handle_downvote,
                        emoji={
                            "name": "⬇️",
                        },
                    ),
                ]
            )
        ],
    )
예제 #18
0
 def action_row(ctx):
     return Message(content="Hi!", components=[ActionRow()])