Skip to content

yuyo.links#

Classes and functions for handling Discord Links.

Bases: ABC

Base class for all link objects.

find classmethod #

find(app, content)

Find the first link in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Self | None

    Object of the found link or None.

find_iter classmethod #

find_iter(app, content)

Iterate over the links in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Iterator[Self]

    Iterator of the link objects in the passed string.

from_link(app, link)

Create a link object from a raw link.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • link (str) –

    The string link to use.

Returns:

  • Self

    The created link object.

Raises:

  • ValueError

    If the string doesn't match the expected link format.

Bases: BaseLink

Represents a link to a channel.

The following class methods are used to initialise this:

channel_id property #

channel_id

ID of the channel this links to.

guild_id property #

guild_id

ID of the guild this links to.

Will be None for DM links.

is_dm_link

Whether this links to a DM channel.

__str__ #

__str__()

Create a raw string representation of this link.

fetch_channel async #

fetch_channel()

Fetch the channel this links to.

Returns:

  • PartialChannel

    The this links to channel. This will be a derivative of hikari.channels.PartialChannel, depending on the type of channel you request for.

Raises:

  • UnauthorizedError

    If you are unauthorized to make the request (invalid/missing token).

  • ForbiddenError

    If you are missing the READ_MESSAGES permission in the channel.

  • NotFoundError

    If the channel is not found.

  • RateLimitTooLongError

    Raised in the event that a rate limit occurs that is longer than max_rate_limit when making a request.

  • InternalServerError

    If an internal error occurs on Discord while handling the request.

fetch_guild async #

fetch_guild()

Fetch the guild this links to.

Returns:

  • RESTGuild | None

    Object of the guild this links to.

    Will be None if this links to a DM channel.

Raises:

find classmethod #

find(app, content)

Find the first link in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Self | None

    Object of the found link or None.

find_iter classmethod #

find_iter(app, content)

Iterate over the links in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Iterator[Self]

    Iterator of the link objects in the passed string.

from_link(app, link)

Create a link object from a raw link.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • link (str) –

    The string link to use.

Returns:

  • Self

    The created link object.

Raises:

  • ValueError

    If the string doesn't match the expected link format.

get_channel #

get_channel()

Get the channel this links to from the cache.

Returns:

  • GuildChannel | None

    Object of the guild channel that was found in the cache or None.

get_guild #

get_guild()

Get the guild this links to from the cache.

Returns:

  • GuildChannel | None

    Object of the guild that was found in the cache or None.

    This will also be None if this links to a DM channel.

Bases: InviteCode, BaseLink

Represents a Discord invite link.

The following class methods are used to initialise this:

code property #

code

The invite's code.

fetch_invite async #

fetch_invite()

Fetch the invite this links to.

Returns:

  • Invite

    Object of the invite this links to.

Raises:

  • UnauthorizedError

    If you are unauthorized to make the request (invalid/missing token).

  • NotFoundError

    If the invite is not found.

  • RateLimitTooLongError

    Raised in the event that a rate limit occurs that is longer than max_rate_limit when making a request.

  • InternalServerError

    If an internal error occurs on Discord while handling the request.

find classmethod #

find(app, content)

Find the first link in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Self | None

    Object of the found link or None.

find_iter classmethod #

find_iter(app, content)

Iterate over the links in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Iterator[Self]

    Iterator of the link objects in the passed string.

from_link(app, link)

Create a link object from a raw link.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • link (str) –

    The string link to use.

Returns:

  • Self

    The created link object.

Raises:

  • ValueError

    If the string doesn't match the expected link format.

get_invite #

get_invite()

Get the invite this links to from the cache.

Returns:

Bases: ChannelLink

Represents a link to a message on Discord.

The following class methods are used to initialise this:

channel_id property #

channel_id

ID of the channel this links to.

guild_id property #

guild_id

ID of the guild this links to.

Will be None for DM links.

is_dm_link

Whether this links to a DM channel.

message_id property #

message_id

ID of the message this links to.

__str__ #

__str__()

Create a raw string representation of this link.

fetch_channel async #

fetch_channel()

Fetch the channel this links to.

Returns:

  • PartialChannel

    The this links to channel. This will be a derivative of hikari.channels.PartialChannel, depending on the type of channel you request for.

Raises:

  • UnauthorizedError

    If you are unauthorized to make the request (invalid/missing token).

  • ForbiddenError

    If you are missing the READ_MESSAGES permission in the channel.

  • NotFoundError

    If the channel is not found.

  • RateLimitTooLongError

    Raised in the event that a rate limit occurs that is longer than max_rate_limit when making a request.

  • InternalServerError

    If an internal error occurs on Discord while handling the request.

fetch_guild async #

fetch_guild()

Fetch the guild this links to.

Returns:

  • RESTGuild | None

    Object of the guild this links to.

    Will be None if this links to a DM channel.

Raises:

fetch_message async #

fetch_message()

Fetch a the message this links to.

Returns:

  • Message

    Object of the message this links to.

Raises:

  • UnauthorizedError

    If you are unauthorized to make the request (invalid/missing token).

  • ForbiddenError

    If you are missing the READ_MESSAGE_HISTORY in the channel.

  • NotFoundError

    If the channel is not found or the message is not found in the given text channel.

  • RateLimitTooLongError

    Raised in the event that a rate limit occurs that is longer than max_rate_limit when making a request.

  • InternalServerError

    If an internal error occurs on Discord while handling the request.

find classmethod #

find(app, content)

Find the first link in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Self | None

    Object of the found link or None.

find_iter classmethod #

find_iter(app, content)

Iterate over the links in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Iterator[Self]

    Iterator of the link objects in the passed string.

from_link(app, link)

Create a link object from a raw link.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • link (str) –

    The string link to use.

Returns:

  • Self

    The created link object.

Raises:

  • ValueError

    If the string doesn't match the expected link format.

get_channel #

get_channel()

Get the channel this links to from the cache.

Returns:

  • GuildChannel | None

    Object of the guild channel that was found in the cache or None.

get_guild #

get_guild()

Get the guild this links to from the cache.

Returns:

  • GuildChannel | None

    Object of the guild that was found in the cache or None.

    This will also be None if this links to a DM channel.

get_message #

get_message()

Get the message this links to from the cache.

Returns:

  • Message | None

    Object of the message that was found in the cache or None.

Bases: BaseLink

Represents a link to a guild template.

The following class methods are used to initialise this:

code property #

code

The template's code.

__str__ #

__str__()

Create a raw string representation of this link.

fetch_template async #

fetch_template()

Fetch the guild template this links to.

Returns:

  • Template

    Object of the guild template this links to.

Raises:

  • NotFoundError

    If the template was not found.

  • UnauthorizedError

    If you are unauthorized to make the request (invalid/missing token).

  • RateLimitTooLongError

    Raised in the event that a rate limit occurs that is longer than max_rate_limit when making a request.

  • InternalServerError

    If an internal error occurs on Discord while handling the request.

find classmethod #

find(app, content)

Find the first link in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Self | None

    Object of the found link or None.

find_iter classmethod #

find_iter(app, content)

Iterate over the links in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Iterator[Self]

    Iterator of the link objects in the passed string.

from_link(app, link)

Create a link object from a raw link.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • link (str) –

    The string link to use.

Returns:

  • Self

    The created link object.

Raises:

  • ValueError

    If the string doesn't match the expected link format.

Bases: ExecutableWebhook, BaseLink

Represents a link to an incoming webhook.

The following class methods are used to initialise this:

app property #

app

The bot or REST client this is bound to.

token property #

token

The webhook's token.

webhook_id property #

webhook_id

ID of the webhook this links to.

__str__ #

__str__()

Create a raw string representation of this link.

fetch_webhook async #

fetch_webhook()

Fetch the incoming webhook this links to.

Returns:

Raises:

  • UnauthorizedError

    If you are unauthorized to make the request (invalid/missing token).

  • NotFoundError

    If the webhook is not found.

  • RateLimitTooLongError

    Raised in the event that a rate limit occurs that is longer than max_rate_limit when making a request.

  • InternalServerError

    If an internal error occurs on Discord while handling the request.

find classmethod #

find(app, content)

Find the first link in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Self | None

    Object of the found link or None.

find_iter classmethod #

find_iter(app, content)

Iterate over the links in a string.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • content (str) –

    The string to search in.

Returns:

  • Iterator[Self]

    Iterator of the link objects in the passed string.

from_link(app, link)

Create a link object from a raw link.

Parameters:

  • app (RESTAware) –

    The Hikari bot or REST app this should be bound to.

  • link (str) –

    The string link to use.

Returns:

  • Self

    The created link object.

Raises:

  • ValueError

    If the string doesn't match the expected link format.

make_bot_invite #

make_bot_invite(client, /, *, disable_guild_select=None, guild=None, permissions=hikari.Permissions.NONE)

Create a Bot invite url.

Parameters:

  • client (SnowflakeishOr[PartialApplication]) –

    Object or ID of the application to make an invite link for.

  • disable_guild_select (Optional[bool], default: None ) –

    Whether users should be prevented from changing the pre-selected guild.

    This only works properly when guild is also passed.

  • guild (Optional[SnowflakeishOr[PartialGuild]], default: None ) –

    Object or ID of a guild to pre-select for the user.

  • permissions (Union[Permissions, int, None], default: NONE ) –

    The permissions the bot is requesting.

    Defaults to requesting a role with no permissions.

    Passing None here will lead to no role being created for the bot.

Returns:

  • str

    The created bot invite.

make_channel_link(channel, /, *, guild=None)

Make a raw link for a channel.

Parameters:

Returns:

  • str

    The raw channel link.

make_invite_link(invite)

Make a raw link for an invite.

Parameters:

  • invite (Union[str, InviteCode]) –

    Object or string code of the invite to make a raw link for.

Returns:

  • str

    The raw invite link.

make_message_link(channel, message, /, *, guild=None)

Make a raw link for a message.

Parameters:

Returns:

  • str

    The raw message link.

make_oauth_link(client, scopes, /, *, disable_guild_select=None, guild=None, permissions=None, prompt=None, redirect_uri=None, response_type=None, state=None)

Create an Oauth2 authorize link.

For more information on how Discord's Oauth2 system works see https://discord.com/developers/docs/topics/oauth2.

Warning

response_type and redirect_uri are usually required.

Parameters:

Returns:

  • str

    The created Oauth2 authorize link.

make_template_link(template)

Make a raw link for a guild template.

Parameters:

  • template (Union[Template, str]) –

    Object or string code of the template to make a raw link to.

Returns:

  • str

    The raw template link.

make_webhook_link(webhook, token)

Make a raw link for an incoming webhook.

Parameters:

Returns:

  • str

    The raw webhook link.