yuyo.links#
Classes and functions for handling Discord Links.
BaseLink #
Bases: ABC
Base class for all link objects.
find classmethod #
find(app, content)
find_iter classmethod #
find_iter(app, content)
from_link classmethod #
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.
ChannelLink dataclass #
Bases: BaseLink
Represents a link to a channel.
The following class methods are used to initialise this:
- InviteLink.from_link to create this from a raw channel link.
- InviteLink.find to find the first channel link in a string.
- InviteLink.find_iter to iterate over the channel links in a string.
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_MESSAGESpermission 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_limitwhen 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:
Raises:
-
ForbiddenError–If you are not part of the guild.
-
NotFoundError–If the guild is 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_limitwhen making a request. -
InternalServerError–If an internal error occurs on Discord while handling the request.
find classmethod #
find(app, content)
find_iter classmethod #
find_iter(app, content)
from_link classmethod #
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.
InviteLink dataclass #
Bases: InviteCode, BaseLink
Represents a Discord invite link.
The following class methods are used to initialise this:
- InviteLink.from_link to create this from a raw invite link.
- InviteLink.find to find the first invite link in a string.
- InviteLink.find_iter to iterate over the invite links in a string.
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_limitwhen making a request. -
InternalServerError–If an internal error occurs on Discord while handling the request.
find classmethod #
find(app, content)
find_iter classmethod #
find_iter(app, content)
from_link classmethod #
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:
-
InviteWithMetadata | None–Object of the invite that was found in the cache or None.
MessageLink dataclass #
Bases: ChannelLink
Represents a link to a message on Discord.
The following class methods are used to initialise this:
- MessageLink.from_link to create this from a raw message link.
- MessageLink.find to find the first invite link in a string.
- MessageLink.find_iter to iterate over the message links in a string.
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_MESSAGESpermission 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_limitwhen 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:
Raises:
-
ForbiddenError–If you are not part of the guild.
-
NotFoundError–If the guild is 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_limitwhen making a request. -
InternalServerError–If an internal error occurs on Discord while handling the request.
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_HISTORYin 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_limitwhen making a request. -
InternalServerError–If an internal error occurs on Discord while handling the request.
find classmethod #
find(app, content)
find_iter classmethod #
find_iter(app, content)
from_link classmethod #
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.
TemplateLink dataclass #
Bases: BaseLink
Represents a link to a guild template.
The following class methods are used to initialise this:
- TemplateLink.from_link to create this from a raw template link.
- TemplateLink.find to find the first template link in a string.
- TemplateLink.find_iter to iterate over the template links in a string.
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_limitwhen making a request. -
InternalServerError–If an internal error occurs on Discord while handling the request.
find classmethod #
find(app, content)
find_iter classmethod #
find_iter(app, content)
from_link classmethod #
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.
WebhookLink dataclass #
Bases: ExecutableWebhook, BaseLink
Represents a link to an incoming webhook.
The following class methods are used to initialise this:
- WebhookLink.from_link to create this from a raw webhook link.
- WebhookLink.find to find the first webhook link in a string.
- WebhookLink.find_iter to iterate over the webhook links in a string.
fetch_webhook async #
fetch_webhook()
Fetch the incoming webhook this links to.
Returns:
-
IncomingWebhook–Object of the incoming webhook this links to.
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_limitwhen making a request. -
InternalServerError–If an internal error occurs on Discord while handling the request.
find classmethod #
find(app, content)
find_iter classmethod #
find_iter(app, content)
from_link classmethod #
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
guildis 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 #
make_channel_link(channel, /, *, guild=None)
Make a raw link for a channel.
Parameters:
-
channel(SnowflakeishOr[PartialChannel]) –Object or ID of the channel to link to.
-
guild(Optional[SnowflakeishOr[PartialGuild]], default:None) –Object or ID of the guild the channel is in.
This should be provided for guild links.
Returns:
-
str–The raw channel link.
make_invite_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 #
make_message_link(channel, message, /, *, guild=None)
Make a raw link for a message.
Parameters:
-
channel(SnowflakeishOr[PartialChannel]) –Object or ID of the channel the message is in.
-
message(SnowflakeishOr[PartialMessage]) –Object or ID of the message to link to.
-
guild(Optional[SnowflakeishOr[PartialGuild]], default:None) –Object or ID of the guild the message is in.
This should be provided for messages in guilds.
Returns:
-
str–The raw message link.
make_oauth_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:
-
client(SnowflakeishOr[PartialApplication]) –Object or ID of the application this Oauth2 application is for.
-
scopes(Sequence[Union[OAuth2Scope, str]]) –The Oauth2 scopes being requested.
-
disable_guild_select(Optional[bool], default:None) –Whether users should be prevented from changing the pre-selected guild.
This only works properly when
guildis also passed. -
guild(Optional[SnowflakeishOr[PartialGuild]], default:None) –Object or ID of a guild to pre-select for the user.
This is only relevant when the
"bot"scope is being requested. -
permissions(Union[Permissions, int, None], default:None) –The permissions the bot is requesting.
This is only relevant when the
"bot"scope is being requested. -
prompt(Optional[str], default:None) –How to handles existing authorization.
For more information see https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-authorization-url-example.
-
redirect_uri(Optional[str], default:None) –URI the user should be redirected to with the authorised access information.
-
response_type(Optional[str], default:None) –The type of Oauth2 flow being initiated.
This will likely either be
"code"(Authorization Code Grant) or"token"(Implicit Grant). -
state(Optional[str], default:None) –A request-unique state generated for security purposes.
For more information see https://discord.com/developers/docs/topics/oauth2#state-and-security.
Returns:
-
str–The created Oauth2 authorize link.
make_template_link #
make_template_link(template)
make_webhook_link #
make_webhook_link(webhook, token)
Make a raw link for an incoming webhook.
Parameters:
-
webhook(SnowflakeishOr[PartialWebhook]) –Object or ID of the webhook to make a link for.
-
token(str) –The webhook's token.
Returns:
-
str–The raw webhook link.