예제 #1
0
def launch_modal_from_button(ctx):
    return Message(
        content="Launch Modal",
        components=[
            ActionRow([Button(custom_id=launch_modal, label="Launch Modal")])
        ],
    )
예제 #2
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)
        ]),
    ]
예제 #3
0
 def button(ctx):
     return Message(
         content="Hi!",
         components=[
             ActionRow(components=[
                 Button(
                     style=ButtonStyles.PRIMARY,
                     custom_id="my_button",
                     label="My Button",
                 )
             ])
         ],
     )
예제 #4
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": "⬇️",
                        },
                    ),
                ]
            )
        ],
    )
예제 #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 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?",
                    )
                ]
            )
        ],
    )
예제 #9
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!",
                    )
                ]
            )
        ],
    )
예제 #10
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,
        )
예제 #13
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,
    )