Custom Buttons

The extension provides a way to customise the buttons used in the paginator.

class discord.ext.modal_paginator.CustomButton[source]

Bases: Button[Any]

Custom button class to pass to the buttons kwarg in ModalPaginator.

This can be used to override things of the default buttons. like the label, style, row, etc.

Parameters docs below is partially copied from discord.ui.Button.

Parameters:
  • style (discord.ButtonStyle]) – The new style of the button.

  • label (str) – The new label of the button.

  • emoji (Union[discord.PartialEmoji, discord.Emoji, str]) – The new emoji of the button. (If any)

  • row (int) – The new row of the button. See discord.ui.Button for more info.

  • override_callback (Optional[bool]) – Whether to override the callback of the button. Defaults to False. If True, your callback will be called instead of the one on the paginator.

async callback(interaction)[source]

The callback for the button.

This is called if override_callback is set to True.

Parameters:

interaction (Interaction) – The interaction that triggered the callback.

Return type:

Any

on_optional_modal(button)[source]

This method is called when the current_modal is optional.

This can be used to change the button’s style, label, etc. Might want to use this to revert the changes made in on_required_modal().

Parameters:

button (Button) – The button that was used.

Return type:

Any

on_required_modal(button)[source]

This method is called when the current_modal is required but discord.ui.Modal.is_finished() is False.

This can be used to change the button’s style, label, etc. This should be used in conjunction with on_optional_modal().

Parameters:

button (Button) – The button that was used.

Return type:

Any

Default Buttons

See here the default buttons used in the paginator. These are for reference only, and should not be used directly.

OpenButton

discord.ext.modal_paginator.default_buttons.OpenButton

Represents the default open button for ModalPaginator.

Default implementation is, (style=discord.ButtonStyle.gray, label="Open", row=0).

This overrides the on_optional_modal and on_required_modal methods to change the label and style.

OpenButton.on_required_modal()

Called when the modal is required.

This changes the label to "*Open" and the style to discord.ButtonStyle.blurple.

Return type:

None

OpenButton.on_optional_modal()

Called when the modal is optional.

This changes the label to "Open" and the style to discord.ButtonStyle.gray.

Return type:

None

NextButton

discord.ext.modal_paginator.default_buttons.NextButton

Represents the default next button for ModalPaginator.

Default implementation is, (label="Next", style=discord.ButtonStyle.green, row=1).

PreviousButton

discord.ext.modal_paginator.default_buttons.PreviousButton

Represents the default previous button for ModalPaginator.

Default implementation is, (label="Previous", style=discord.ButtonStyle.green, row=1).

CancelButton

discord.ext.modal_paginator.default_buttons.CancelButton

Represents the default cancel button for ModalPaginator.

Default implementation is, (label="Cancel", style=discord.ButtonStyle.red, row=2).

FinishButton

discord.ext.modal_paginator.default_buttons.FinishButton

Represents the default finish button for ModalPaginator.

Default implementation is, (label="Finish", style=discord.ButtonStyle.green, row=2).