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)
def launch_modal_from_button(ctx): return Message( content="Launch Modal", components=[ ActionRow([Button(custom_id=launch_modal, label="Launch Modal")]) ], )
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) ]), ]
def button(ctx): return Message( content="Hi!", components=[ ActionRow(components=[ Button( style=ButtonStyles.PRIMARY, custom_id="my_button", label="My Button", ) ]) ], )
def google(ctx): return Message( content="search engine", components=[ ActionRow( components=[ Button( style=ButtonStyles.LINK, url="https://www.google.com/", label="Go to google", ) ] ) ], )
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!", ) ]) ], )
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, ) ]) ], )
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?", ) ] ) ], )
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!", ) ] ) ], )
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, )
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"), ], ) ]) ], )
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)
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": "⬇️", }, ), ] ) ], )
def action_row(ctx): return Message(content="Hi!", components=[ActionRow()])