Skip to content

Ready Responses

Ready Response

The DiscordResponse is available as a convenience object to assist you in generating a proper payload to return to discord.

Some methods and functions may require you to only use a valid DiscordResponse.

from dispike import DiscordResponse

# or

from dispike.responses import DiscordResponse

content, embeds, and tts is not required immediately, and can be configured later.

However, settings such as show_user_input and follow_up_message are set at first initialization and cannot be changed.

from dispike.responses import DiscordResponse

response = DiscordResponse()
response.content = "Content Text Here"
from dispike.responses import DiscordResponse
from dispike.helper import Embed
async def sample_function(...) -> DiscordResponse:
    ...
    return DiscordResponse(
        content="Content Text Here",
        tts=False,
        embeds=[Embed(...), Embed(...)],
        show_user_input=True
    )

Empherical Messages

Empherical messages (messages/responses that are only visible to the person who sent them ) are available by setting the optional empherical parameter to True.

Info

Setting a response to be empherical after initialization can be done by setting the ._is_empherical attribute. (Note this will be changed in newer versions of Dispike.)

from dispike.responses import DiscordResponse

response = DiscordResponse(empherical=True)
response.content = "Content Text Here"

GifOfDeferredMessage

Update original message

Warning

You can only update an original message if you are responding to a component interaction

You can update the original message if you are responding to a component interaction.

from dispike.responses import DiscordResponse

response = DiscordResponse(update_message=True)
response.content = "Brand new content"

Buttons

Info

Remember to register an event for these buttons!

DiscordResponse(
    content="Content!",
    empherical=True,
    action_row=ActionRow(
        components=[
            Button(
                label="Next",
                custom_id="tutorial_step1_next",
                style=ButtonStyles.PRIMARY,
            ),
            Button(
                label="Cancel",
                custom_id="tutorial_cancel",
                style=ButtonStyles.DANGER,
            ),
            LinkButton(
                label="Go to the docs!",
                url="https://dispike.ms7m.me/"
            )
        ]
    ),
),

Select Menus

Info

Remember to register an event for this select menu!

DiscordResponse(
    content="Content!",
    action_row=ActionRow(
        components=[
            SelectMenu(
                custom_id="class_select_1",
                placeholder="Choose a class",
                min_values=1,
                max_values=1,
                options=[
                    SelectMenu.SelectMenuOption(
                        label="Rogue",
                        description="Sneak n stab",
                        value="rogue",
                        emoji=PartialEmoji(name="rogue", id="625891304148303894"),
                    ),
                    SelectMenu.SelectMenuOption(
                        label="Mage",
                        description="Turn 'em into a sheep",
                        value="mage",
                        emoji=PartialEmoji(name="mage", id="625891304081063986"),
                    ),
                ],
                disabled=False,
            )
        ]
    ),
),
Info

DiscordResponse is simply a helper to help you generate a valid response to discord. If you can generate a valid response yourself, you can simply type-hint your function to hint at a dict and return a proper response. This is only recommended for Advanced users.

Represents an outgoing Discord Response

Attributes:

Name Type Description
content str

A plain-text response to a user

tts bool

bool returning if the message should be spoken via tts.

embeds dict

a List representing .to_dict of an Embed object.

response dict

a valid response represented in a dict, to later be converted to JSON.

action_row: ActionRow property readonly

Returns a action row.

Returns:

Type Description
ActionRow

ActionRow: The action row.

content: str property writable

Either set or view the plain-text response to the user.

Returns:

Type Description
str

str: Content provided

embeds: List[dispike.helper.embed.Embed] property readonly

Returns a list of embeds to send to.

Returns:

Type Description
List[dispike.helper.embed.Embed]

List[Embed]: List of embeds in this object.

response: dict property readonly

A generated valid discord response

Returns:

Type Description
dict

dict: a valid discord response.

tts: bool property writable

Either set or view the tts attribute for the user.

Returns:

Type Description
bool

bool: tts

__init__(self, content=None, tts=False, embeds=[], show_user_input=False, follow_up_message=False, empherical=False, allowed_mentions=None, action_row=None, update_message=False) special

Initialize a DiscordResponse, you can either pass data into here, or simply create a DiscordResponse() and edit via properties.

Parameters:

Name Type Description Default
content str

A plain-text response to a user

None
tts bool

bool returning if the message should be spoken via tts

False
embeds List[dispike.helper.embed.Embed]

a List representing .to_dict of an Embed object

[]
show_user_input bool

Whether to delete the user's message of calling the command after responding.

False
follow_up_message bool

Whether this is a follow up to a previous message.

False
empherical bool

Whether to send message as an empherical message.

False
allowed_mentions AllowedMentions

Let discord filter mentions per configuration.

None
update_message bool

Whether to edit the original message this is responding too.

False
Source code in dispike/response.py
def __init__(
    self,
    content: str = None,
    tts: bool = False,
    embeds: typing.List[Embed] = [],
    show_user_input: bool = False,
    follow_up_message=False,
    empherical=False,
    allowed_mentions: "AllowedMentions" = None,
    action_row: ActionRow = None,
    update_message=False,
):
    """Initialize a DiscordResponse, you can either pass data into here, or
    simply create a DiscordResponse() and edit via properties.

    Args:
        content (str, optional): A plain-text response to a user
        tts (bool, optional): bool returning if the message should be spoken via tts
        embeds (typing.List[Embed], optional): a List representing .to_dict of an Embed object
        show_user_input (bool, optional): Whether to delete the user's message of calling the command after responding.
        follow_up_message (bool, optional): Whether this is a follow up to a previous message.
        empherical (bool, optional): Whether to send message as an empherical message.
        allowed_mentions (List[AllowedMentions], optional): Let discord filter mentions per configuration.
        update_message (bool, optional): Whether to edit the original message this is responding too.
    """
    if content is not None:
        if not isinstance(content, str):
            raise TypeError(f"Content must be a string")
        elif content == "":
            content = None

    # if isinstance(content, str) == False or content == "" or content != None:
    #    raise TypeError(f"content must be a string. recieved: {content}")

    if not isinstance(tts, bool):
        raise TypeError("tts must be a bool")

    self._content = content
    self._tts = tts
    self._embeds = embeds

    if action_row:
        self._action_row = action_row
    else:
        self._action_row = None

    if show_user_input:
        # show deprecation warning
        warnings.warn(
            "show_user_input is deprecated by Dispike as it is no longer supported by Discord. Future versions of dispike may remove this parameter entirely.",
            DeprecationWarning,
        )  # pragma: no cover
        logger.warning(
            "show_user_input is deprecated by Dispike as it is no longer supported by Discord. Future versions of dispike may remove this parameter entirely."
        )  # pragma: no cover

    self._type_response = 4

    if update_message:
        self._type_response = 7

    self._is_followup = follow_up_message
    self._is_empherical = empherical
    self._allowed_mentions = allowed_mentions

add_new_embed(self, embed_to_add)

Append a new embed, provided with a proper Embed object

Parameters:

Name Type Description Default
embed_to_add Embed

Proper Embed Object

required

Exceptions:

Type Description
TypeError

Raised if you do not pass a proper Embed object.

Source code in dispike/response.py
def add_new_embed(self, embed_to_add: Embed):
    """Append a new embed, provided with a proper Embed object

    Args:
        embed_to_add (Embed): Proper Embed Object

    Raises:
        TypeError: Raised if you do not pass a proper Embed object.
    """
    if isinstance(embed_to_add, Embed):
        self._embeds.append(embed_to_add)
    else:
        raise TypeError("embed must be a Embed object.")