bot.utils.messages#

Message utilities.

Module Contents#

Functions#

format_user(→ str)

Return a string for user which has their mention and ID.

get_discord_message(→ discord.Message | str)

Attempt to convert a given text to a discord Message object and return it.

get_text_and_embed(→ tuple[str, discord.Embed | None])

Attempt to extract the text and embed from a possible link to a discord Message.

convert_embed(→ discord.Embed)

Convert the text in an embed using a given conversion function, then return the embed.

bot.utils.messages.format_user(user: discord.abc.User) str[source]#

Return a string for user which has their mention and ID.

async bot.utils.messages.get_discord_message(ctx: discord.ext.commands.Context, text: str) discord.Message | str[source]#

Attempt to convert a given text to a discord Message object and return it.

Conversion will succeed if given a discord Message ID or link. Returns text if the conversion fails.

async bot.utils.messages.get_text_and_embed(ctx: discord.ext.commands.Context, text: str) tuple[str, discord.Embed | None][source]#

Attempt to extract the text and embed from a possible link to a discord Message.

Does not retrieve the text and embed from the Message if it is in a channel the user does not have read permissions in.

Returns a tuple of:

str: If text is a valid discord Message, the contents of the message, else text. Optional[Embed]: The embed if found in the valid Message, else None

bot.utils.messages.convert_embed(func: collections.abc.Callable[[str], str], embed: discord.Embed) discord.Embed[source]#

Convert the text in an embed using a given conversion function, then return the embed.

Only modifies the following fields: title, description, footer, fields