hikari.interactions.command_interactions
Models and enums used for Discord's Slash Commands interaction flow.
View Source
# -*- coding: utf-8 -*- # cython: language_level=3 # Copyright (c) 2020 Nekokatt # Copyright (c) 2021-present davfsa # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. """Models and enums used for Discord's Slash Commands interaction flow.""" from __future__ import annotations __all__: typing.Sequence[str] = ( "AutocompleteInteraction", "BaseCommandInteraction", "CommandInteractionOption", "AutocompleteInteractionOption", "CommandInteraction", "COMMAND_RESPONSE_TYPES", "CommandResponseTypesT", "InteractionChannel", "ResolvedOptionData", ) import typing import attr from hikari import channels from hikari import commands from hikari import snowflakes from hikari import traits from hikari import undefined from hikari.interactions import base_interactions from hikari.internal import attr_extensions if typing.TYPE_CHECKING: from hikari import guilds from hikari import messages as messages_ from hikari import permissions as permissions_ from hikari import users as users_ from hikari.api import special_endpoints COMMAND_RESPONSE_TYPES: typing.Final[typing.AbstractSet[CommandResponseTypesT]] = frozenset( [base_interactions.ResponseType.MESSAGE_CREATE, base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE] ) """Set of the response types which are valid for a command interaction. This includes: * `hikari.interactions.base_interactions.ResponseType.MESSAGE_CREATE` * `hikari.interactions.base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE` """ CommandResponseTypesT = typing.Literal[ base_interactions.ResponseType.MESSAGE_CREATE, 4, base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE, 5 ] """Type-hint of the response types which are valid for a command interaction. The following types are valid for this: * `hikari.interactions.base_interactions.ResponseType.MESSAGE_CREATE`/`4` * `hikari.interactions.base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE`/`5` """ @attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class InteractionChannel(channels.PartialChannel): """Represents partial channels returned as resolved entities on interactions.""" permissions: permissions_.Permissions = attr.field(eq=False, hash=False, repr=True) """Permissions the command's executor has in this channel.""" @attr_extensions.with_copy @attr.define(hash=False, kw_only=True, weakref_slot=False) class ResolvedOptionData: """Represents the resolved objects of entities referenced in a command's options.""" attachments: typing.Mapping[snowflakes.Snowflake, messages_.Attachment] = attr.field(repr=False) """Mapping of snowflake IDs to the attachment objects.""" channels: typing.Mapping[snowflakes.Snowflake, InteractionChannel] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option partial channel objects.""" members: typing.Mapping[snowflakes.Snowflake, base_interactions.InteractionMember] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option member objects.""" messages: typing.Mapping[snowflakes.Snowflake, messages_.Message] """Mapping of snowflake IDs to the resolved option partial message objects.""" roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option role objects.""" users: typing.Mapping[snowflakes.Snowflake, users_.User] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option user objects.""" @attr_extensions.with_copy @attr.define(hash=False, kw_only=True, weakref_slot=False) class CommandInteractionOption: """Represents the options passed for a command interaction.""" name: str = attr.field(repr=True) """Name of this option.""" type: typing.Union[commands.OptionType, int] = attr.field(repr=True) """Type of this option.""" value: typing.Union[snowflakes.Snowflake, str, int, bool, None] = attr.field(repr=True) """Value provided for this option. Either `CommandInteractionOption.value` or `CommandInteractionOption.options` will be provided with `value` being provided when an option is provided as a parameter with a value and `options` being provided when an option donates a subcommand or group. """ # TODO: use typing.Self here options: typing.Optional[typing.Sequence[CommandInteractionOption]] = attr.field(repr=True) """Options provided for this option. Either `CommandInteractionOption.value` or `CommandInteractionOption.options` will be provided with `value` being provided when an option is provided as a parameter with a value and `options` being provided when an option donates a subcommand or group. """ @attr_extensions.with_copy @attr.define(hash=False, kw_only=True, weakref_slot=False) class AutocompleteInteractionOption(CommandInteractionOption): """Represents the options passed for a command autocomplete interaction.""" is_focused: bool = attr.field(default=False, repr=True) """Whether this option is the currently focused option for autocomplete. Focused options are not guaranteed to be parsed so the value may be a string even if the option type says otherwise. """ options: typing.Optional[typing.Sequence[AutocompleteInteractionOption]] = attr.field(repr=True) """Options provided for this option. Either `AutocompleteInteractionOption.value` or `AutocompleteInteractionOption.options` will be provided with `value` being provided when an option is provided as a parameter with a value and `options` being provided when an option donates a subcommand or group. `AutocompleteInteractionOption.is_focused` will be `True` for the value being autocompleted. """ @attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class BaseCommandInteraction(base_interactions.PartialInteraction): """Represents a base command interaction on Discord. May be a command interaction or an autocomplete interaction. """ channel_id: snowflakes.Snowflake = attr.field(eq=False, hash=False, repr=True) """ID of the channel this command interaction event was triggered in.""" guild_id: typing.Optional[snowflakes.Snowflake] = attr.field(eq=False, hash=False, repr=True) """ID of the guild this command interaction event was triggered in. This will be `None` for command interactions triggered in DMs. """ guild_locale: typing.Optional[str] = attr.field(eq=False, hash=False, repr=True) """The preferred language of the guild this command interaction was triggered in. This will be `None` for command interactions triggered in DMs. .. note:: This value can usually only be changed if `COMMUNITY` is in `hikari.guilds.Guild.features` for the guild and will otherwise default to `en-US`. """ member: typing.Optional[base_interactions.InteractionMember] = attr.field(eq=False, hash=False, repr=True) """The member who triggered this command interaction. This will be `None` for command interactions triggered in DMs. .. note:: This member object comes with the extra field `permissions` which contains the member's permissions in the current channel. """ user: users_.User = attr.field(eq=False, hash=False, repr=True) """The user who triggered this command interaction.""" locale: str = attr.field(eq=False, hash=False, repr=True) """The selected language of the user who triggered this command interaction.""" command_id: snowflakes.Snowflake = attr.field(eq=False, hash=False, repr=True) """ID of the command being invoked.""" command_name: str = attr.field(eq=False, hash=False, repr=True) """Name of the command being invoked.""" command_type: typing.Union[commands.CommandType, int] = attr.field(eq=False, hash=False, repr=True) """The type of the command.""" resolved: typing.Optional[ResolvedOptionData] = attr.field(eq=False, hash=False, repr=False) """Mappings of the objects resolved for the provided command options.""" async def fetch_channel(self) -> channels.TextableChannel: """Fetch the guild channel this was triggered in. Returns ------- hikari.channels.TextableChannel The requested partial channel derived object of the channel this was triggered in. Raises ------ hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.ForbiddenError If you are missing the `READ_MESSAGES` permission in the channel. hikari.errors.NotFoundError If the channel is not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ channel = await self.app.rest.fetch_channel(self.channel_id) assert isinstance(channel, channels.TextableChannel) return channel def get_channel(self) -> typing.Optional[channels.TextableGuildChannel]: """Get the guild channel this was triggered in from the cache. .. note:: This will always return `None` for interactions triggered in a DM channel. Returns ------- typing.Optional[hikari.channels.TextableGuildChannel] The object of the guild channel that was found in the cache or `None`. """ if isinstance(self.app, traits.CacheAware): channel = self.app.cache.get_guild_channel(self.channel_id) assert isinstance(channel, channels.TextableGuildChannel) return channel return None async def fetch_command(self) -> commands.PartialCommand: """Fetch the command which triggered this interaction. Returns ------- hikari.commands.PartialCommand Object of this interaction's command. Raises ------ hikari.errors.ForbiddenError If you cannot access the target command. hikari.errors.NotFoundError If the command isn't found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ return await self.app.rest.fetch_application_command( application=self.application_id, command=self.id, guild=self.guild_id or undefined.UNDEFINED ) async def fetch_guild(self) -> typing.Optional[guilds.RESTGuild]: """Fetch the guild this interaction happened in. Returns ------- typing.Optional[hikari.guilds.RESTGuild] Object of the guild this interaction happened in or `None` if this occurred within a DM channel. Raises ------ hikari.errors.ForbiddenError If you are not part of the guild. hikari.errors.NotFoundError If the guild is not found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if not self.guild_id: return None return await self.app.rest.fetch_guild(self.guild_id) def get_guild(self) -> typing.Optional[guilds.GatewayGuild]: """Get the object of this interaction's guild guild from the cache. Returns ------- typing.Optional[hikari.guilds.GatewayGuild] The object of the guild if found, else `None`. """ if self.guild_id and isinstance(self.app, traits.CacheAware): return self.app.cache.get_guild(self.guild_id) return None @attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class CommandInteraction(BaseCommandInteraction, base_interactions.MessageResponseMixin[CommandResponseTypesT]): """Represents a command interaction on Discord.""" options: typing.Optional[typing.Sequence[CommandInteractionOption]] = attr.field(eq=False, hash=False, repr=True) """Parameter values provided by the user invoking this command.""" target_id: typing.Optional[snowflakes.Snowflake] = attr.field(default=None, eq=False, hash=False, repr=True) """The target of the command. Only available if the command is a context menu command.""" def build_response(self) -> special_endpoints.InteractionMessageBuilder: """Get a message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `CommandInteraction.create_initial_response` should be used to set the interaction response message. Examples -------- ```py async def handle_command_interaction(interaction: CommandInteraction) -> InteractionMessageBuilder: return ( interaction .build_response() .add_embed(Embed(description="Hi there")) .set_content("Konnichiwa") ) ``` Returns ------- hikari.api.special_endpoints.InteractionMessageBuilder Interaction message response builder object. """ return self.app.rest.interaction_message_builder(base_interactions.ResponseType.MESSAGE_CREATE) def build_deferred_response(self) -> special_endpoints.InteractionDeferredBuilder: """Get a deferred message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `CommandInteraction.create_initial_response` should be used to set the interaction response message. .. note:: Unlike `hikari.api.special_endpoints.InteractionMessageBuilder`, the result of this call can be returned as is without any modifications being made to it. Returns ------- hikari.api.special_endpoints.InteractionMessageBuilder Deferred interaction message response builder object. """ return self.app.rest.interaction_deferred_builder(base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE) @attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class AutocompleteInteraction(BaseCommandInteraction): """Represents an autocomplete interaction on Discord.""" options: typing.Sequence[AutocompleteInteractionOption] = attr.field(eq=False, hash=False, repr=True) """Parameter values provided by the user invoking this command.""" def build_response( self, choices: typing.Sequence[commands.CommandChoice] ) -> special_endpoints.InteractionAutocompleteBuilder: """Get a message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `AutocompleteInteraction.create_response` should be used to set the interaction response. Examples -------- ```py async def handle_autocomplete_interaction(interaction: AutocompleteInteraction) -> InteractionAutocompleteBuilder: return ( interaction .build_response( [ CommandChoice(name="foo", value="a"), CommandChoice(name="bar", value="b"), CommandChoice(name="baz", value="c"), ] ) ) ``` Returns ------- hikari.api.special_endpoints.InteractionAutocompleteBuilder Interaction autocomplete response builder object. """ return self.app.rest.interaction_autocomplete_builder(choices) async def create_response(self, choices: typing.Sequence[commands.CommandChoice]) -> None: """Create a response for this autocomplete interaction.""" await self.app.rest.create_autocomplete_response( self.id, self.token, choices, )
View Source
@attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class AutocompleteInteraction(BaseCommandInteraction): """Represents an autocomplete interaction on Discord.""" options: typing.Sequence[AutocompleteInteractionOption] = attr.field(eq=False, hash=False, repr=True) """Parameter values provided by the user invoking this command.""" def build_response( self, choices: typing.Sequence[commands.CommandChoice] ) -> special_endpoints.InteractionAutocompleteBuilder: """Get a message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `AutocompleteInteraction.create_response` should be used to set the interaction response. Examples -------- ```py async def handle_autocomplete_interaction(interaction: AutocompleteInteraction) -> InteractionAutocompleteBuilder: return ( interaction .build_response( [ CommandChoice(name="foo", value="a"), CommandChoice(name="bar", value="b"), CommandChoice(name="baz", value="c"), ] ) ) ``` Returns ------- hikari.api.special_endpoints.InteractionAutocompleteBuilder Interaction autocomplete response builder object. """ return self.app.rest.interaction_autocomplete_builder(choices) async def create_response(self, choices: typing.Sequence[commands.CommandChoice]) -> None: """Create a response for this autocomplete interaction.""" await self.app.rest.create_autocomplete_response( self.id, self.token, choices, )
Represents an autocomplete interaction on Discord.
Variables and properties
The client application that models may use for procedures.
ID of the application this interaction belongs to.
ID of the channel this command interaction event was triggered in.
ID of the command being invoked.
Name of the command being invoked.
The type of the command.
When the object was created.
ID of the guild this command interaction event was triggered in.
This will be None
for command interactions triggered in DMs.
The preferred language of the guild this command interaction was triggered in.
This will be None
for command interactions triggered in DMs.
Note: This value can usually only be changed if COMMUNITY
is in hikari.guilds.Guild.features
for the guild and will otherwise default to en-US
.
The selected language of the user who triggered this command interaction.
The member who triggered this command interaction.
This will be None
for command interactions triggered in DMs.
Note: This member object comes with the extra field permissions
which contains the member's permissions in the current channel.
Parameter values provided by the user invoking this command.
Mappings of the objects resolved for the provided command options.
The interaction's token.
The type of interaction this is.
The user who triggered this command interaction.
Version of the interaction system this interaction is under.
ID used to execute this entity as a webhook.
Methods
self,
*,
app: hikari.traits.RESTAware,
id: hikari.snowflakes.Snowflake,
application_id: hikari.snowflakes.Snowflake,
type: 'typing.Union[InteractionType, int]',
token: str,
version: int,
channel_id: hikari.snowflakes.Snowflake,
guild_id: Optional[hikari.snowflakes.Snowflake],
guild_locale: Optional[str],
member: Optional[hikari.interactions.base_interactions.InteractionMember],
user: hikari.users.User,
locale: str,
command_id: hikari.snowflakes.Snowflake,
command_name: str,
command_type: Union[hikari.commands.CommandType, int],
resolved: Optional[hikari.interactions.command_interactions.ResolvedOptionData],
options: Sequence[hikari.interactions.command_interactions.AutocompleteInteractionOption]
):
View Source
def __init__(self, *, app, id, application_id, type, token, version, channel_id, guild_id, guild_locale, member, user, locale, command_id, command_name, command_type, resolved, options): self.app = app self.id = id self.application_id = application_id self.type = type self.token = token self.version = version self.channel_id = channel_id self.guild_id = guild_id self.guild_locale = guild_locale self.member = member self.user = user self.locale = locale self.command_id = command_id self.command_name = command_name self.command_type = command_type self.resolved = resolved self.options = options
Method generated by attrs for class AutocompleteInteraction.
self,
choices: Sequence[hikari.commands.CommandChoice]
) -> hikari.api.special_endpoints.InteractionAutocompleteBuilder:
View Source
def build_response( self, choices: typing.Sequence[commands.CommandChoice] ) -> special_endpoints.InteractionAutocompleteBuilder: """Get a message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `AutocompleteInteraction.create_response` should be used to set the interaction response. Examples -------- ```py async def handle_autocomplete_interaction(interaction: AutocompleteInteraction) -> InteractionAutocompleteBuilder: return ( interaction .build_response( [ CommandChoice(name="foo", value="a"), CommandChoice(name="bar", value="b"), CommandChoice(name="baz", value="c"), ] ) ) ``` Returns ------- hikari.api.special_endpoints.InteractionAutocompleteBuilder Interaction autocomplete response builder object. """ return self.app.rest.interaction_autocomplete_builder(choices)
Get a message response builder for use in the REST server flow.
Note: For interactions received over the gateway AutocompleteInteraction.create_response
should be used to set the interaction response.
Examples
async def handle_autocomplete_interaction(interaction: AutocompleteInteraction) -> InteractionAutocompleteBuilder:
return (
interaction
.build_response(
[
CommandChoice(name="foo", value="a"),
CommandChoice(name="bar", value="b"),
CommandChoice(name="baz", value="c"),
]
)
)
Returns
- hikari.api.special_endpoints.InteractionAutocompleteBuilder: Interaction autocomplete response builder object.
View Source
async def create_response(self, choices: typing.Sequence[commands.CommandChoice]) -> None: """Create a response for this autocomplete interaction.""" await self.app.rest.create_autocomplete_response( self.id, self.token, choices, )
Create a response for this autocomplete interaction.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int]
) -> None:
View Source
async def delete_message(self, message: snowflakes.SnowflakeishOr[messages_.Message]) -> None: """Delete a given message in a given channel. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to delete. This may be the object or the ID of an existing message. Raises ------ ValueError If `token` is not available. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook or the message are not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if self.token is None: raise ValueError("Cannot delete a message using a webhook where we don't know the token") await self.app.rest.delete_webhook_message(self.webhook_id, token=self.token, message=message)
Delete a given message in a given channel.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to delete. This may be the object or the ID of an existing message.
Raises
- ValueError: If
token
is not available. - hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook or the message are not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int],
content: Union[Any, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
*,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED
) -> hikari.messages.Message:
View Source
async def edit_message( self, message: snowflakes.SnowflakeishOr[messages_.Message], content: undefined.UndefinedNoneOr[typing.Any] = undefined.UNDEFINED, *, attachment: undefined.UndefinedOr[files.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedNoneOr[ typing.Sequence[special_endpoints.ComponentBuilder] ] = undefined.UNDEFINED, embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedNoneOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, replace_attachments: bool = False, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool] ] = undefined.UNDEFINED, ) -> messages_.Message: """Edit a message sent by a webhook. .. note:: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however. .. warning:: If you specify a text `content`, `mentions_everyone`, `mentions_reply`, `user_mentions`, and `role_mentions` will default to `False` as the message will be re-parsed for mentions. This will also occur if only one of the four are specified This is a limitation of Discord's design. If in doubt, specify all four of them each time. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to delete. This may be the object or the ID of an existing message. content : hikari.undefined.UndefinedNoneOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and no `embed` nor no `embeds` kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone. Likewise, if this is a `hikari.files.Resource`, then the content is instead treated as an attachment if no `attachment` and no `attachments` kwargs are provided. Other Parameters ---------------- attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish] If provided, the attachment to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachment, if present, is not changed. If this is `None`, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]] If provided, the attachments to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachments, if present, are not changed. If this is `None`, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. component : hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to set for this message. This component will replace any previously set components and passing `None` will remove all components. components : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing `None` or an empty sequence will remove all components. embed : hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed] If provided, the embed to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. embeds : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]] If provided, the embeds to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments: bool Whether to replace the attachments with the provided ones. Defaults to `False`. Note this will also overwrite the embed attachments. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, sanitation for `@everyone` mentions. If `hikari.undefined.UNDEFINED`, then the previous setting is not changed. If `True`, then `@everyone`/`@here` mentions in the message content will show up as mentioning everyone that can view the chat. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all user mentions will be detected. If provided, and `False`, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all role mentions will be detected. If provided, and `False`, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. Returns ------- hikari.messages.Message The edited message. Raises ------ ValueError If more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions` or `token` is not available. TypeError If both `attachment` and `attachments` are specified or if both `embed` and `embeds` are specified. hikari.errors.BadRequestError This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; too many components. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook or the message are not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ # noqa: E501 - Line too long if self.token is None: raise ValueError("Cannot edit a message using a webhook where we don't know the token") return await self.app.rest.edit_webhook_message( self.webhook_id, token=self.token, message=message, content=content, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, replace_attachments=replace_attachments, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, )
Edit a message sent by a webhook.
Note: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however.
Warning: If you specify a text content
, mentions_everyone
, mentions_reply
, user_mentions
, and role_mentions
will default to False
as the message will be re-parsed for mentions. This will also occur if only one of the four are specified
This is a limitation of Discord's design. If in doubt, specify all four of them each time.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to delete. This may be the object or the ID of an existing message.
content (hikari.undefined.UndefinedNoneOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and noembed
nor noembeds
kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.Likewise, if this is a
hikari.files.Resource
, then the content is instead treated as an attachment if noattachment
and noattachments
kwargs are provided.
Other Parameters
- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish]): If provided, the attachment to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachment, if present, is not changed. If this isNone
, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. - attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]]): If provided, the attachments to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachments, if present, are not changed. If this isNone
, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. - component (hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to set for this message. This component will replace any previously set components and passing
None
will remove all components. - components (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing
None
or an empty sequence will remove all components. - embed (hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed]): If provided, the embed to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. - embeds (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the embeds to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments (bool): Whether to replace the attachments with the provided ones. Defaults to
False
.Note this will also overwrite the embed attachments.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, sanitation for
@everyone
mentions. Ifhikari.undefined.UNDEFINED
, then the previous setting is not changed. IfTrue
, then@everyone
/@here
mentions in the message content will show up as mentioning everyone that can view the chat. - user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all user mentions will be detected. If provided, andFalse
, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all role mentions will be detected. If provided, andFalse
, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles.
Returns
- hikari.messages.Message: The edited message.
Raises
- ValueError: If more than 100 unique objects/entities are passed for
role_mentions
oruser_mentions
ortoken
is not available. - TypeError: If both
attachment
andattachments
are specified or if bothembed
andembeds
are specified. - hikari.errors.BadRequestError: This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; too many components.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook or the message are not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
content: Union[Any, hikari.undefined.UndefinedType] = UNDEFINED,
*,
username: Union[str, hikari.undefined.UndefinedType] = UNDEFINED,
avatar_url: Union[hikari.undefined.UndefinedType, str, hikari.files.URL] = UNDEFINED,
tts: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType] = UNDEFINED,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
flags: Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag] = UNDEFINED
) -> hikari.messages.Message:
View Source
async def execute( self, content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED, *, username: undefined.UndefinedOr[str] = undefined.UNDEFINED, avatar_url: typing.Union[undefined.UndefinedType, str, files.URL] = undefined.UNDEFINED, tts: undefined.UndefinedOr[bool] = undefined.UNDEFINED, attachment: undefined.UndefinedOr[files_.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files_.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED, embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool] ] = undefined.UNDEFINED, flags: typing.Union[undefined.UndefinedType, int, messages_.MessageFlag] = undefined.UNDEFINED, ) -> messages_.Message: """Execute the webhook to create a message. .. warning:: At the time of writing, `username` and `avatar_url` are ignored for interaction webhooks. Additionally, flags this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks. Parameters ---------- content : hikari.undefined.UndefinedOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and no `embed` kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone. Likewise, if this is a `hikari.files.Resource`, then the content is instead treated as an attachment if no `attachment` and no `attachments` kwargs are provided. Other Parameters ---------------- username : hikari.undefined.UndefinedOr[str] If provided, the username to override the webhook's username for this request. avatar_url : typing.Union[hikari.undefined.UndefinedType, hikari.files.URL, str] If provided, the url of an image to override the webhook's avatar with for this request. tts : hikari.undefined.UndefinedOr[bool] If provided, whether the message will be sent as a TTS message. attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish] If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]] If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs. component : hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to include in this message. components : hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects to include in this message. embed : hikari.undefined.UndefinedOr[hikari.embeds.Embed] If provided, the message embed. embeds : hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]] If provided, the message embeds. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, whether the message should parse @everyone/@here mentions. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all mentions will be parsed. If provided, and `False`, no mentions will be parsed. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all mentions will be parsed. If provided, and `False`, no mentions will be parsed. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. flags : typing.Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag] The flags to set for this webhook message. Returns ------- hikari.messages.Message The created message object. Raises ------ hikari.errors.NotFoundError If the current webhook is not found. hikari.errors.BadRequestError This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than `2000` characters; if neither content, file or embeds are specified. If any invalid snowflake IDs are passed; a snowflake may be invalid due to it being outside of the range of a 64 bit integer. hikari.errors.UnauthorizedError If you pass a token that's invalid for the target webhook. ValueError If either `ExecutableWebhook.token` is `None` or more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions or if `token` is not available. TypeError If both `attachment` and `attachments`, `component` and `components` or `embed` and `embeds` are specified. """ # noqa: E501 - Line too long if not self.token: raise ValueError("Cannot send a message using a webhook where we don't know the token") return await self.app.rest.execute_webhook( webhook=self.webhook_id, token=self.token, content=content, username=username, avatar_url=avatar_url, tts=tts, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, flags=flags, )
Execute the webhook to create a message.
Warning: At the time of writing, username
and avatar_url
are ignored for interaction webhooks.
Additionally, flags this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks.
Parameters
content (hikari.undefined.UndefinedOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and noembed
kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.Likewise, if this is a
hikari.files.Resource
, then the content is instead treated as an attachment if noattachment
and noattachments
kwargs are provided.
Other Parameters
- username (hikari.undefined.UndefinedOr[str]): If provided, the username to override the webhook's username for this request.
- avatar_url (typing.Union[hikari.undefined.UndefinedType, hikari.files.URL, str]): If provided, the url of an image to override the webhook's avatar with for this request.
- tts (hikari.undefined.UndefinedOr[bool]): If provided, whether the message will be sent as a TTS message.
- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish]): If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL.
- attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]]): If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs.
- component (hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to include in this message.
- components (hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects to include in this message.
- embed (hikari.undefined.UndefinedOr[hikari.embeds.Embed]): If provided, the message embed.
- embeds (hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the message embeds.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, whether the message should parse @everyone/@here mentions.
- user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all mentions will be parsed. If provided, andFalse
, no mentions will be parsed. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all mentions will be parsed. If provided, andFalse
, no mentions will be parsed. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles. - flags (typing.Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag]): The flags to set for this webhook message.
Returns
- hikari.messages.Message: The created message object.
Raises
- hikari.errors.NotFoundError: If the current webhook is not found.
- hikari.errors.BadRequestError: This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than
2000
characters; if neither content, file or embeds are specified. If any invalid snowflake IDs are passed; a snowflake may be invalid due to it being outside of the range of a 64 bit integer. - hikari.errors.UnauthorizedError: If you pass a token that's invalid for the target webhook.
- ValueError: If either
ExecutableWebhook.token
isNone
or more than 100 unique objects/entities are passed forrole_mentions
oruser_mentions or if
token` is not available. - TypeError: If both
attachment
andattachments
,component
andcomponents
orembed
andembeds
are specified.
View Source
async def fetch_channel(self) -> channels.TextableChannel: """Fetch the guild channel this was triggered in. Returns ------- hikari.channels.TextableChannel The requested partial channel derived object of the channel this was triggered in. Raises ------ hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.ForbiddenError If you are missing the `READ_MESSAGES` permission in the channel. hikari.errors.NotFoundError If the channel is not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ channel = await self.app.rest.fetch_channel(self.channel_id) assert isinstance(channel, channels.TextableChannel) return channel
Fetch the guild channel this was triggered in.
Returns
- hikari.channels.TextableChannel: The requested partial channel derived object of the channel this was triggered in.
Raises
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.ForbiddenError: If you are missing the
READ_MESSAGES
permission in the channel. - hikari.errors.NotFoundError: If the channel is not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def fetch_command(self) -> commands.PartialCommand: """Fetch the command which triggered this interaction. Returns ------- hikari.commands.PartialCommand Object of this interaction's command. Raises ------ hikari.errors.ForbiddenError If you cannot access the target command. hikari.errors.NotFoundError If the command isn't found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ return await self.app.rest.fetch_application_command( application=self.application_id, command=self.id, guild=self.guild_id or undefined.UNDEFINED )
Fetch the command which triggered this interaction.
Returns
- hikari.commands.PartialCommand: Object of this interaction's command.
Raises
- hikari.errors.ForbiddenError: If you cannot access the target command.
- hikari.errors.NotFoundError: If the command isn't found.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def fetch_guild(self) -> typing.Optional[guilds.RESTGuild]: """Fetch the guild this interaction happened in. Returns ------- typing.Optional[hikari.guilds.RESTGuild] Object of the guild this interaction happened in or `None` if this occurred within a DM channel. Raises ------ hikari.errors.ForbiddenError If you are not part of the guild. hikari.errors.NotFoundError If the guild is not found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if not self.guild_id: return None return await self.app.rest.fetch_guild(self.guild_id)
Fetch the guild this interaction happened in.
Returns
- typing.Optional[hikari.guilds.RESTGuild]: Object of the guild this interaction happened in or
None
if this occurred within a DM channel.
Raises
- hikari.errors.ForbiddenError: If you are not part of the guild.
- hikari.errors.NotFoundError: If the guild is not found.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int]
) -> hikari.messages.Message:
View Source
async def fetch_message(self, message: snowflakes.SnowflakeishOr[messages_.Message]) -> messages_.Message: """Fetch an old message sent by the webhook. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to fetch. This may be the object or the ID of an existing channel. Returns ------- hikari.messages.Message The requested message. Raises ------ ValueError If `token` is not available. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook is not found or the webhook's message wasn't found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if self.token is None: raise ValueError("Cannot fetch a message using a webhook where we don't know the token") return await self.app.rest.fetch_webhook_message(self.webhook_id, token=self.token, message=message)
Fetch an old message sent by the webhook.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to fetch. This may be the object or the ID of an existing channel.
Returns
- hikari.messages.Message: The requested message.
Raises
- ValueError: If
token
is not available. - hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook is not found or the webhook's message wasn't found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
def get_channel(self) -> typing.Optional[channels.TextableGuildChannel]: """Get the guild channel this was triggered in from the cache. .. note:: This will always return `None` for interactions triggered in a DM channel. Returns ------- typing.Optional[hikari.channels.TextableGuildChannel] The object of the guild channel that was found in the cache or `None`. """ if isinstance(self.app, traits.CacheAware): channel = self.app.cache.get_guild_channel(self.channel_id) assert isinstance(channel, channels.TextableGuildChannel) return channel return None
Get the guild channel this was triggered in from the cache.
Note: This will always return None
for interactions triggered in a DM channel.
Returns
- typing.Optional[hikari.channels.TextableGuildChannel]: The object of the guild channel that was found in the cache or
None
.
View Source
def get_guild(self) -> typing.Optional[guilds.GatewayGuild]: """Get the object of this interaction's guild guild from the cache. Returns ------- typing.Optional[hikari.guilds.GatewayGuild] The object of the guild if found, else `None`. """ if self.guild_id and isinstance(self.app, traits.CacheAware): return self.app.cache.get_guild(self.guild_id) return None
Get the object of this interaction's guild guild from the cache.
Returns
- typing.Optional[hikari.guilds.GatewayGuild]: The object of the guild if found, else
None
.
View Source
@attr_extensions.with_copy @attr.define(hash=False, kw_only=True, weakref_slot=False) class AutocompleteInteractionOption(CommandInteractionOption): """Represents the options passed for a command autocomplete interaction.""" is_focused: bool = attr.field(default=False, repr=True) """Whether this option is the currently focused option for autocomplete. Focused options are not guaranteed to be parsed so the value may be a string even if the option type says otherwise. """ options: typing.Optional[typing.Sequence[AutocompleteInteractionOption]] = attr.field(repr=True) """Options provided for this option. Either `AutocompleteInteractionOption.value` or `AutocompleteInteractionOption.options` will be provided with `value` being provided when an option is provided as a parameter with a value and `options` being provided when an option donates a subcommand or group. `AutocompleteInteractionOption.is_focused` will be `True` for the value being autocompleted. """
Represents the options passed for a command autocomplete interaction.
Variables and properties
Whether this option is the currently focused option for autocomplete.
Focused options are not guaranteed to be parsed so the value may be a string even if the option type says otherwise.
Name of this option.
Options provided for this option.
Either AutocompleteInteractionOption.value
or AutocompleteInteractionOption.options
will be provided with value
being provided when an option is provided as a parameter with a value and options
being provided when an option donates a subcommand or group.
AutocompleteInteractionOption.is_focused
will be True
for the value being autocompleted.
Type of this option.
Value provided for this option.
Either CommandInteractionOption.value
or CommandInteractionOption.options
will be provided with value
being provided when an option is provided as a parameter with a value and options
being provided when an option donates a subcommand or group.
Methods
self,
*,
name: str,
type: Union[hikari.commands.OptionType, int],
value: Union[hikari.snowflakes.Snowflake, str, int, bool, NoneType],
is_focused: bool = False,
options: Optional[Sequence[hikari.interactions.command_interactions.AutocompleteInteractionOption]]
):
View Source
def __init__(self, *, name, type, value, is_focused=attr_dict['is_focused'].default, options): self.name = name self.type = type self.value = value self.is_focused = is_focused self.options = options
Method generated by attrs for class AutocompleteInteractionOption.
View Source
@attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class BaseCommandInteraction(base_interactions.PartialInteraction): """Represents a base command interaction on Discord. May be a command interaction or an autocomplete interaction. """ channel_id: snowflakes.Snowflake = attr.field(eq=False, hash=False, repr=True) """ID of the channel this command interaction event was triggered in.""" guild_id: typing.Optional[snowflakes.Snowflake] = attr.field(eq=False, hash=False, repr=True) """ID of the guild this command interaction event was triggered in. This will be `None` for command interactions triggered in DMs. """ guild_locale: typing.Optional[str] = attr.field(eq=False, hash=False, repr=True) """The preferred language of the guild this command interaction was triggered in. This will be `None` for command interactions triggered in DMs. .. note:: This value can usually only be changed if `COMMUNITY` is in `hikari.guilds.Guild.features` for the guild and will otherwise default to `en-US`. """ member: typing.Optional[base_interactions.InteractionMember] = attr.field(eq=False, hash=False, repr=True) """The member who triggered this command interaction. This will be `None` for command interactions triggered in DMs. .. note:: This member object comes with the extra field `permissions` which contains the member's permissions in the current channel. """ user: users_.User = attr.field(eq=False, hash=False, repr=True) """The user who triggered this command interaction.""" locale: str = attr.field(eq=False, hash=False, repr=True) """The selected language of the user who triggered this command interaction.""" command_id: snowflakes.Snowflake = attr.field(eq=False, hash=False, repr=True) """ID of the command being invoked.""" command_name: str = attr.field(eq=False, hash=False, repr=True) """Name of the command being invoked.""" command_type: typing.Union[commands.CommandType, int] = attr.field(eq=False, hash=False, repr=True) """The type of the command.""" resolved: typing.Optional[ResolvedOptionData] = attr.field(eq=False, hash=False, repr=False) """Mappings of the objects resolved for the provided command options.""" async def fetch_channel(self) -> channels.TextableChannel: """Fetch the guild channel this was triggered in. Returns ------- hikari.channels.TextableChannel The requested partial channel derived object of the channel this was triggered in. Raises ------ hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.ForbiddenError If you are missing the `READ_MESSAGES` permission in the channel. hikari.errors.NotFoundError If the channel is not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ channel = await self.app.rest.fetch_channel(self.channel_id) assert isinstance(channel, channels.TextableChannel) return channel def get_channel(self) -> typing.Optional[channels.TextableGuildChannel]: """Get the guild channel this was triggered in from the cache. .. note:: This will always return `None` for interactions triggered in a DM channel. Returns ------- typing.Optional[hikari.channels.TextableGuildChannel] The object of the guild channel that was found in the cache or `None`. """ if isinstance(self.app, traits.CacheAware): channel = self.app.cache.get_guild_channel(self.channel_id) assert isinstance(channel, channels.TextableGuildChannel) return channel return None async def fetch_command(self) -> commands.PartialCommand: """Fetch the command which triggered this interaction. Returns ------- hikari.commands.PartialCommand Object of this interaction's command. Raises ------ hikari.errors.ForbiddenError If you cannot access the target command. hikari.errors.NotFoundError If the command isn't found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ return await self.app.rest.fetch_application_command( application=self.application_id, command=self.id, guild=self.guild_id or undefined.UNDEFINED ) async def fetch_guild(self) -> typing.Optional[guilds.RESTGuild]: """Fetch the guild this interaction happened in. Returns ------- typing.Optional[hikari.guilds.RESTGuild] Object of the guild this interaction happened in or `None` if this occurred within a DM channel. Raises ------ hikari.errors.ForbiddenError If you are not part of the guild. hikari.errors.NotFoundError If the guild is not found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if not self.guild_id: return None return await self.app.rest.fetch_guild(self.guild_id) def get_guild(self) -> typing.Optional[guilds.GatewayGuild]: """Get the object of this interaction's guild guild from the cache. Returns ------- typing.Optional[hikari.guilds.GatewayGuild] The object of the guild if found, else `None`. """ if self.guild_id and isinstance(self.app, traits.CacheAware): return self.app.cache.get_guild(self.guild_id) return None
Represents a base command interaction on Discord.
May be a command interaction or an autocomplete interaction.
Variables and properties
The client application that models may use for procedures.
ID of the application this interaction belongs to.
ID of the channel this command interaction event was triggered in.
ID of the command being invoked.
Name of the command being invoked.
The type of the command.
When the object was created.
ID of the guild this command interaction event was triggered in.
This will be None
for command interactions triggered in DMs.
The preferred language of the guild this command interaction was triggered in.
This will be None
for command interactions triggered in DMs.
Note: This value can usually only be changed if COMMUNITY
is in hikari.guilds.Guild.features
for the guild and will otherwise default to en-US
.
The selected language of the user who triggered this command interaction.
The member who triggered this command interaction.
This will be None
for command interactions triggered in DMs.
Note: This member object comes with the extra field permissions
which contains the member's permissions in the current channel.
Mappings of the objects resolved for the provided command options.
The interaction's token.
The type of interaction this is.
The user who triggered this command interaction.
Version of the interaction system this interaction is under.
ID used to execute this entity as a webhook.
Methods
self,
*,
app: hikari.traits.RESTAware,
id: hikari.snowflakes.Snowflake,
application_id: hikari.snowflakes.Snowflake,
type: 'typing.Union[InteractionType, int]',
token: str,
version: int,
channel_id: hikari.snowflakes.Snowflake,
guild_id: Optional[hikari.snowflakes.Snowflake],
guild_locale: Optional[str],
member: Optional[hikari.interactions.base_interactions.InteractionMember],
user: hikari.users.User,
locale: str,
command_id: hikari.snowflakes.Snowflake,
command_name: str,
command_type: Union[hikari.commands.CommandType, int],
resolved: Optional[hikari.interactions.command_interactions.ResolvedOptionData]
):
View Source
def __init__(self, *, app, id, application_id, type, token, version, channel_id, guild_id, guild_locale, member, user, locale, command_id, command_name, command_type, resolved): self.app = app self.id = id self.application_id = application_id self.type = type self.token = token self.version = version self.channel_id = channel_id self.guild_id = guild_id self.guild_locale = guild_locale self.member = member self.user = user self.locale = locale self.command_id = command_id self.command_name = command_name self.command_type = command_type self.resolved = resolved
Method generated by attrs for class BaseCommandInteraction.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int]
) -> None:
View Source
async def delete_message(self, message: snowflakes.SnowflakeishOr[messages_.Message]) -> None: """Delete a given message in a given channel. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to delete. This may be the object or the ID of an existing message. Raises ------ ValueError If `token` is not available. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook or the message are not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if self.token is None: raise ValueError("Cannot delete a message using a webhook where we don't know the token") await self.app.rest.delete_webhook_message(self.webhook_id, token=self.token, message=message)
Delete a given message in a given channel.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to delete. This may be the object or the ID of an existing message.
Raises
- ValueError: If
token
is not available. - hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook or the message are not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int],
content: Union[Any, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
*,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED
) -> hikari.messages.Message:
View Source
async def edit_message( self, message: snowflakes.SnowflakeishOr[messages_.Message], content: undefined.UndefinedNoneOr[typing.Any] = undefined.UNDEFINED, *, attachment: undefined.UndefinedOr[files.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedNoneOr[ typing.Sequence[special_endpoints.ComponentBuilder] ] = undefined.UNDEFINED, embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedNoneOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, replace_attachments: bool = False, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool] ] = undefined.UNDEFINED, ) -> messages_.Message: """Edit a message sent by a webhook. .. note:: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however. .. warning:: If you specify a text `content`, `mentions_everyone`, `mentions_reply`, `user_mentions`, and `role_mentions` will default to `False` as the message will be re-parsed for mentions. This will also occur if only one of the four are specified This is a limitation of Discord's design. If in doubt, specify all four of them each time. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to delete. This may be the object or the ID of an existing message. content : hikari.undefined.UndefinedNoneOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and no `embed` nor no `embeds` kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone. Likewise, if this is a `hikari.files.Resource`, then the content is instead treated as an attachment if no `attachment` and no `attachments` kwargs are provided. Other Parameters ---------------- attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish] If provided, the attachment to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachment, if present, is not changed. If this is `None`, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]] If provided, the attachments to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachments, if present, are not changed. If this is `None`, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. component : hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to set for this message. This component will replace any previously set components and passing `None` will remove all components. components : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing `None` or an empty sequence will remove all components. embed : hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed] If provided, the embed to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. embeds : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]] If provided, the embeds to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments: bool Whether to replace the attachments with the provided ones. Defaults to `False`. Note this will also overwrite the embed attachments. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, sanitation for `@everyone` mentions. If `hikari.undefined.UNDEFINED`, then the previous setting is not changed. If `True`, then `@everyone`/`@here` mentions in the message content will show up as mentioning everyone that can view the chat. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all user mentions will be detected. If provided, and `False`, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all role mentions will be detected. If provided, and `False`, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. Returns ------- hikari.messages.Message The edited message. Raises ------ ValueError If more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions` or `token` is not available. TypeError If both `attachment` and `attachments` are specified or if both `embed` and `embeds` are specified. hikari.errors.BadRequestError This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; too many components. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook or the message are not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ # noqa: E501 - Line too long if self.token is None: raise ValueError("Cannot edit a message using a webhook where we don't know the token") return await self.app.rest.edit_webhook_message( self.webhook_id, token=self.token, message=message, content=content, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, replace_attachments=replace_attachments, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, )
Edit a message sent by a webhook.
Note: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however.
Warning: If you specify a text content
, mentions_everyone
, mentions_reply
, user_mentions
, and role_mentions
will default to False
as the message will be re-parsed for mentions. This will also occur if only one of the four are specified
This is a limitation of Discord's design. If in doubt, specify all four of them each time.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to delete. This may be the object or the ID of an existing message.
content (hikari.undefined.UndefinedNoneOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and noembed
nor noembeds
kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.Likewise, if this is a
hikari.files.Resource
, then the content is instead treated as an attachment if noattachment
and noattachments
kwargs are provided.
Other Parameters
- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish]): If provided, the attachment to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachment, if present, is not changed. If this isNone
, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. - attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]]): If provided, the attachments to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachments, if present, are not changed. If this isNone
, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. - component (hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to set for this message. This component will replace any previously set components and passing
None
will remove all components. - components (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing
None
or an empty sequence will remove all components. - embed (hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed]): If provided, the embed to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. - embeds (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the embeds to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments (bool): Whether to replace the attachments with the provided ones. Defaults to
False
.Note this will also overwrite the embed attachments.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, sanitation for
@everyone
mentions. Ifhikari.undefined.UNDEFINED
, then the previous setting is not changed. IfTrue
, then@everyone
/@here
mentions in the message content will show up as mentioning everyone that can view the chat. - user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all user mentions will be detected. If provided, andFalse
, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all role mentions will be detected. If provided, andFalse
, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles.
Returns
- hikari.messages.Message: The edited message.
Raises
- ValueError: If more than 100 unique objects/entities are passed for
role_mentions
oruser_mentions
ortoken
is not available. - TypeError: If both
attachment
andattachments
are specified or if bothembed
andembeds
are specified. - hikari.errors.BadRequestError: This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; too many components.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook or the message are not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
content: Union[Any, hikari.undefined.UndefinedType] = UNDEFINED,
*,
username: Union[str, hikari.undefined.UndefinedType] = UNDEFINED,
avatar_url: Union[hikari.undefined.UndefinedType, str, hikari.files.URL] = UNDEFINED,
tts: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType] = UNDEFINED,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
flags: Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag] = UNDEFINED
) -> hikari.messages.Message:
View Source
async def execute( self, content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED, *, username: undefined.UndefinedOr[str] = undefined.UNDEFINED, avatar_url: typing.Union[undefined.UndefinedType, str, files.URL] = undefined.UNDEFINED, tts: undefined.UndefinedOr[bool] = undefined.UNDEFINED, attachment: undefined.UndefinedOr[files_.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files_.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED, embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool] ] = undefined.UNDEFINED, flags: typing.Union[undefined.UndefinedType, int, messages_.MessageFlag] = undefined.UNDEFINED, ) -> messages_.Message: """Execute the webhook to create a message. .. warning:: At the time of writing, `username` and `avatar_url` are ignored for interaction webhooks. Additionally, flags this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks. Parameters ---------- content : hikari.undefined.UndefinedOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and no `embed` kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone. Likewise, if this is a `hikari.files.Resource`, then the content is instead treated as an attachment if no `attachment` and no `attachments` kwargs are provided. Other Parameters ---------------- username : hikari.undefined.UndefinedOr[str] If provided, the username to override the webhook's username for this request. avatar_url : typing.Union[hikari.undefined.UndefinedType, hikari.files.URL, str] If provided, the url of an image to override the webhook's avatar with for this request. tts : hikari.undefined.UndefinedOr[bool] If provided, whether the message will be sent as a TTS message. attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish] If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]] If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs. component : hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to include in this message. components : hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects to include in this message. embed : hikari.undefined.UndefinedOr[hikari.embeds.Embed] If provided, the message embed. embeds : hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]] If provided, the message embeds. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, whether the message should parse @everyone/@here mentions. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all mentions will be parsed. If provided, and `False`, no mentions will be parsed. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all mentions will be parsed. If provided, and `False`, no mentions will be parsed. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. flags : typing.Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag] The flags to set for this webhook message. Returns ------- hikari.messages.Message The created message object. Raises ------ hikari.errors.NotFoundError If the current webhook is not found. hikari.errors.BadRequestError This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than `2000` characters; if neither content, file or embeds are specified. If any invalid snowflake IDs are passed; a snowflake may be invalid due to it being outside of the range of a 64 bit integer. hikari.errors.UnauthorizedError If you pass a token that's invalid for the target webhook. ValueError If either `ExecutableWebhook.token` is `None` or more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions or if `token` is not available. TypeError If both `attachment` and `attachments`, `component` and `components` or `embed` and `embeds` are specified. """ # noqa: E501 - Line too long if not self.token: raise ValueError("Cannot send a message using a webhook where we don't know the token") return await self.app.rest.execute_webhook( webhook=self.webhook_id, token=self.token, content=content, username=username, avatar_url=avatar_url, tts=tts, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, flags=flags, )
Execute the webhook to create a message.
Warning: At the time of writing, username
and avatar_url
are ignored for interaction webhooks.
Additionally, flags this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks.
Parameters
content (hikari.undefined.UndefinedOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and noembed
kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.Likewise, if this is a
hikari.files.Resource
, then the content is instead treated as an attachment if noattachment
and noattachments
kwargs are provided.
Other Parameters
- username (hikari.undefined.UndefinedOr[str]): If provided, the username to override the webhook's username for this request.
- avatar_url (typing.Union[hikari.undefined.UndefinedType, hikari.files.URL, str]): If provided, the url of an image to override the webhook's avatar with for this request.
- tts (hikari.undefined.UndefinedOr[bool]): If provided, whether the message will be sent as a TTS message.
- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish]): If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL.
- attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]]): If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs.
- component (hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to include in this message.
- components (hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects to include in this message.
- embed (hikari.undefined.UndefinedOr[hikari.embeds.Embed]): If provided, the message embed.
- embeds (hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the message embeds.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, whether the message should parse @everyone/@here mentions.
- user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all mentions will be parsed. If provided, andFalse
, no mentions will be parsed. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all mentions will be parsed. If provided, andFalse
, no mentions will be parsed. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles. - flags (typing.Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag]): The flags to set for this webhook message.
Returns
- hikari.messages.Message: The created message object.
Raises
- hikari.errors.NotFoundError: If the current webhook is not found.
- hikari.errors.BadRequestError: This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than
2000
characters; if neither content, file or embeds are specified. If any invalid snowflake IDs are passed; a snowflake may be invalid due to it being outside of the range of a 64 bit integer. - hikari.errors.UnauthorizedError: If you pass a token that's invalid for the target webhook.
- ValueError: If either
ExecutableWebhook.token
isNone
or more than 100 unique objects/entities are passed forrole_mentions
oruser_mentions or if
token` is not available. - TypeError: If both
attachment
andattachments
,component
andcomponents
orembed
andembeds
are specified.
View Source
async def fetch_channel(self) -> channels.TextableChannel: """Fetch the guild channel this was triggered in. Returns ------- hikari.channels.TextableChannel The requested partial channel derived object of the channel this was triggered in. Raises ------ hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.ForbiddenError If you are missing the `READ_MESSAGES` permission in the channel. hikari.errors.NotFoundError If the channel is not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ channel = await self.app.rest.fetch_channel(self.channel_id) assert isinstance(channel, channels.TextableChannel) return channel
Fetch the guild channel this was triggered in.
Returns
- hikari.channels.TextableChannel: The requested partial channel derived object of the channel this was triggered in.
Raises
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.ForbiddenError: If you are missing the
READ_MESSAGES
permission in the channel. - hikari.errors.NotFoundError: If the channel is not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def fetch_command(self) -> commands.PartialCommand: """Fetch the command which triggered this interaction. Returns ------- hikari.commands.PartialCommand Object of this interaction's command. Raises ------ hikari.errors.ForbiddenError If you cannot access the target command. hikari.errors.NotFoundError If the command isn't found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ return await self.app.rest.fetch_application_command( application=self.application_id, command=self.id, guild=self.guild_id or undefined.UNDEFINED )
Fetch the command which triggered this interaction.
Returns
- hikari.commands.PartialCommand: Object of this interaction's command.
Raises
- hikari.errors.ForbiddenError: If you cannot access the target command.
- hikari.errors.NotFoundError: If the command isn't found.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def fetch_guild(self) -> typing.Optional[guilds.RESTGuild]: """Fetch the guild this interaction happened in. Returns ------- typing.Optional[hikari.guilds.RESTGuild] Object of the guild this interaction happened in or `None` if this occurred within a DM channel. Raises ------ hikari.errors.ForbiddenError If you are not part of the guild. hikari.errors.NotFoundError If the guild is not found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if not self.guild_id: return None return await self.app.rest.fetch_guild(self.guild_id)
Fetch the guild this interaction happened in.
Returns
- typing.Optional[hikari.guilds.RESTGuild]: Object of the guild this interaction happened in or
None
if this occurred within a DM channel.
Raises
- hikari.errors.ForbiddenError: If you are not part of the guild.
- hikari.errors.NotFoundError: If the guild is not found.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int]
) -> hikari.messages.Message:
View Source
async def fetch_message(self, message: snowflakes.SnowflakeishOr[messages_.Message]) -> messages_.Message: """Fetch an old message sent by the webhook. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to fetch. This may be the object or the ID of an existing channel. Returns ------- hikari.messages.Message The requested message. Raises ------ ValueError If `token` is not available. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook is not found or the webhook's message wasn't found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if self.token is None: raise ValueError("Cannot fetch a message using a webhook where we don't know the token") return await self.app.rest.fetch_webhook_message(self.webhook_id, token=self.token, message=message)
Fetch an old message sent by the webhook.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to fetch. This may be the object or the ID of an existing channel.
Returns
- hikari.messages.Message: The requested message.
Raises
- ValueError: If
token
is not available. - hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook is not found or the webhook's message wasn't found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
def get_channel(self) -> typing.Optional[channels.TextableGuildChannel]: """Get the guild channel this was triggered in from the cache. .. note:: This will always return `None` for interactions triggered in a DM channel. Returns ------- typing.Optional[hikari.channels.TextableGuildChannel] The object of the guild channel that was found in the cache or `None`. """ if isinstance(self.app, traits.CacheAware): channel = self.app.cache.get_guild_channel(self.channel_id) assert isinstance(channel, channels.TextableGuildChannel) return channel return None
Get the guild channel this was triggered in from the cache.
Note: This will always return None
for interactions triggered in a DM channel.
Returns
- typing.Optional[hikari.channels.TextableGuildChannel]: The object of the guild channel that was found in the cache or
None
.
View Source
def get_guild(self) -> typing.Optional[guilds.GatewayGuild]: """Get the object of this interaction's guild guild from the cache. Returns ------- typing.Optional[hikari.guilds.GatewayGuild] The object of the guild if found, else `None`. """ if self.guild_id and isinstance(self.app, traits.CacheAware): return self.app.cache.get_guild(self.guild_id) return None
Get the object of this interaction's guild guild from the cache.
Returns
- typing.Optional[hikari.guilds.GatewayGuild]: The object of the guild if found, else
None
.
Set of the response types which are valid for a command interaction.
This includes:
View Source
@attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class CommandInteraction(BaseCommandInteraction, base_interactions.MessageResponseMixin[CommandResponseTypesT]): """Represents a command interaction on Discord.""" options: typing.Optional[typing.Sequence[CommandInteractionOption]] = attr.field(eq=False, hash=False, repr=True) """Parameter values provided by the user invoking this command.""" target_id: typing.Optional[snowflakes.Snowflake] = attr.field(default=None, eq=False, hash=False, repr=True) """The target of the command. Only available if the command is a context menu command.""" def build_response(self) -> special_endpoints.InteractionMessageBuilder: """Get a message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `CommandInteraction.create_initial_response` should be used to set the interaction response message. Examples -------- ```py async def handle_command_interaction(interaction: CommandInteraction) -> InteractionMessageBuilder: return ( interaction .build_response() .add_embed(Embed(description="Hi there")) .set_content("Konnichiwa") ) ``` Returns ------- hikari.api.special_endpoints.InteractionMessageBuilder Interaction message response builder object. """ return self.app.rest.interaction_message_builder(base_interactions.ResponseType.MESSAGE_CREATE) def build_deferred_response(self) -> special_endpoints.InteractionDeferredBuilder: """Get a deferred message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `CommandInteraction.create_initial_response` should be used to set the interaction response message. .. note:: Unlike `hikari.api.special_endpoints.InteractionMessageBuilder`, the result of this call can be returned as is without any modifications being made to it. Returns ------- hikari.api.special_endpoints.InteractionMessageBuilder Deferred interaction message response builder object. """ return self.app.rest.interaction_deferred_builder(base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE)
Represents a command interaction on Discord.
Variables and properties
The client application that models may use for procedures.
ID of the application this interaction belongs to.
ID of the channel this command interaction event was triggered in.
ID of the command being invoked.
Name of the command being invoked.
The type of the command.
When the object was created.
ID of the guild this command interaction event was triggered in.
This will be None
for command interactions triggered in DMs.
The preferred language of the guild this command interaction was triggered in.
This will be None
for command interactions triggered in DMs.
Note: This value can usually only be changed if COMMUNITY
is in hikari.guilds.Guild.features
for the guild and will otherwise default to en-US
.
The selected language of the user who triggered this command interaction.
The member who triggered this command interaction.
This will be None
for command interactions triggered in DMs.
Note: This member object comes with the extra field permissions
which contains the member's permissions in the current channel.
Parameter values provided by the user invoking this command.
Mappings of the objects resolved for the provided command options.
The target of the command. Only available if the command is a context menu command.
The interaction's token.
The type of interaction this is.
The user who triggered this command interaction.
Version of the interaction system this interaction is under.
ID used to execute this entity as a webhook.
Methods
self,
*,
app: hikari.traits.RESTAware,
id: hikari.snowflakes.Snowflake,
application_id: hikari.snowflakes.Snowflake,
type: 'typing.Union[InteractionType, int]',
token: str,
version: int,
channel_id: hikari.snowflakes.Snowflake,
guild_id: Optional[hikari.snowflakes.Snowflake],
guild_locale: Optional[str],
member: Optional[hikari.interactions.base_interactions.InteractionMember],
user: hikari.users.User,
locale: str,
command_id: hikari.snowflakes.Snowflake,
command_name: str,
command_type: Union[hikari.commands.CommandType, int],
resolved: Optional[hikari.interactions.command_interactions.ResolvedOptionData],
options: Optional[Sequence[hikari.interactions.command_interactions.CommandInteractionOption]],
target_id: Optional[hikari.snowflakes.Snowflake] = None
):
View Source
def __init__(self, *, app, id, application_id, type, token, version, channel_id, guild_id, guild_locale, member, user, locale, command_id, command_name, command_type, resolved, options, target_id=attr_dict['target_id'].default): self.app = app self.id = id self.application_id = application_id self.type = type self.token = token self.version = version self.channel_id = channel_id self.guild_id = guild_id self.guild_locale = guild_locale self.member = member self.user = user self.locale = locale self.command_id = command_id self.command_name = command_name self.command_type = command_type self.resolved = resolved self.options = options self.target_id = target_id
Method generated by attrs for class CommandInteraction.
View Source
def build_deferred_response(self) -> special_endpoints.InteractionDeferredBuilder: """Get a deferred message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `CommandInteraction.create_initial_response` should be used to set the interaction response message. .. note:: Unlike `hikari.api.special_endpoints.InteractionMessageBuilder`, the result of this call can be returned as is without any modifications being made to it. Returns ------- hikari.api.special_endpoints.InteractionMessageBuilder Deferred interaction message response builder object. """ return self.app.rest.interaction_deferred_builder(base_interactions.ResponseType.DEFERRED_MESSAGE_CREATE)
Get a deferred message response builder for use in the REST server flow.
Note: For interactions received over the gateway CommandInteraction.create_initial_response
should be used to set the interaction response message.
Note: Unlike hikari.api.special_endpoints.InteractionMessageBuilder
, the result of this call can be returned as is without any modifications being made to it.
Returns
- hikari.api.special_endpoints.InteractionMessageBuilder: Deferred interaction message response builder object.
View Source
def build_response(self) -> special_endpoints.InteractionMessageBuilder: """Get a message response builder for use in the REST server flow. .. note:: For interactions received over the gateway `CommandInteraction.create_initial_response` should be used to set the interaction response message. Examples -------- ```py async def handle_command_interaction(interaction: CommandInteraction) -> InteractionMessageBuilder: return ( interaction .build_response() .add_embed(Embed(description="Hi there")) .set_content("Konnichiwa") ) ``` Returns ------- hikari.api.special_endpoints.InteractionMessageBuilder Interaction message response builder object. """ return self.app.rest.interaction_message_builder(base_interactions.ResponseType.MESSAGE_CREATE)
Get a message response builder for use in the REST server flow.
Note: For interactions received over the gateway CommandInteraction.create_initial_response
should be used to set the interaction response message.
Examples
async def handle_command_interaction(interaction: CommandInteraction) -> InteractionMessageBuilder:
return (
interaction
.build_response()
.add_embed(Embed(description="Hi there"))
.set_content("Konnichiwa")
)
Returns
- hikari.api.special_endpoints.InteractionMessageBuilder: Interaction message response builder object.
self,
response_type: ~_CommandResponseTypesT,
content: Union[Any, hikari.undefined.UndefinedType] = UNDEFINED,
*,
flags: Union[int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType] = UNDEFINED,
tts: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType] = UNDEFINED,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED
) -> None:
View Source
async def create_initial_response( self, response_type: _CommandResponseTypesT, content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED, *, flags: typing.Union[int, messages.MessageFlag, undefined.UndefinedType] = undefined.UNDEFINED, tts: undefined.UndefinedOr[bool] = undefined.UNDEFINED, attachment: undefined.UndefinedOr[files.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED, embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds.PartialRole], bool] ] = undefined.UNDEFINED, ) -> None: """Create the initial response for this interaction. .. warning:: Calling this on an interaction which already has an initial response will result in this raising a `hikari.errors.NotFoundError`. This includes if the REST interaction server has already responded to the request. Parameters ---------- response_type : typing.Union[int, CommandResponseTypesT] The type of interaction response this is. Other Parameters ---------------- content : hikari.undefined.UndefinedOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and no `embed` nor `embeds` kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone. attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish], If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]], If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs. component : hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to include in this message. components : hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects to include in this message. embed : hikari.undefined.UndefinedOr[hikari.embeds.Embed] If provided, the message embed. embeds : hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]] If provided, the message embeds. flags : typing.Union[int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType] If provided, the message flags this response should have. As of writing the only message flag which can be set here is `hikari.messages.MessageFlag.EPHEMERAL`. tts : hikari.undefined.UndefinedOr[bool] If provided, whether the message will be read out by a screen reader using Discord's TTS (text-to-speech) system. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, whether the message should parse @everyone/@here mentions. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all user mentions will be detected. If provided, and `False`, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all role mentions will be detected. If provided, and `False`, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. Raises ------ ValueError If more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions`. TypeError If both `embed` and `embeds` are specified. hikari.errors.BadRequestError This may be raised in several discrete situations, such as messages being empty with no embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; invalid image URLs in embeds. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the interaction is not found or if the interaction's initial response has already been created. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ # noqa: E501 - Line too long await self.app.rest.create_interaction_response( self.id, self.token, response_type, content, tts=tts, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, flags=flags, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, )
Create the initial response for this interaction.
Warning: Calling this on an interaction which already has an initial response will result in this raising a hikari.errors.NotFoundError
. This includes if the REST interaction server has already responded to the request.
Parameters
- response_type (typing.Union[int, CommandResponseTypesT]): The type of interaction response this is.
Other Parameters
content (hikari.undefined.UndefinedOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and noembed
norembeds
kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish],): If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL.
- attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]],): If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs.
- component (hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to include in this message.
- components (hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects to include in this message.
- embed (hikari.undefined.UndefinedOr[hikari.embeds.Embed]): If provided, the message embed.
- embeds (hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the message embeds.
flags (typing.Union[int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType]): If provided, the message flags this response should have.
As of writing the only message flag which can be set here is
hikari.messages.MessageFlag.EPHEMERAL
.- tts (hikari.undefined.UndefinedOr[bool]): If provided, whether the message will be read out by a screen reader using Discord's TTS (text-to-speech) system.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, whether the message should parse @everyone/@here mentions.
- user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all user mentions will be detected. If provided, andFalse
, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all role mentions will be detected. If provided, andFalse
, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles.
Raises
- ValueError: If more than 100 unique objects/entities are passed for
role_mentions
oruser_mentions
. - TypeError: If both
embed
andembeds
are specified. - hikari.errors.BadRequestError: This may be raised in several discrete situations, such as messages being empty with no embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; invalid image URLs in embeds.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the interaction is not found or if the interaction's initial response has already been created.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def delete_initial_response(self) -> None: """Delete the initial response of this interaction. Raises ------ hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the interaction or response is not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ await self.app.rest.delete_interaction_response(self.application_id, self.token)
Delete the initial response of this interaction.
Raises
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the interaction or response is not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int]
) -> None:
View Source
async def delete_message(self, message: snowflakes.SnowflakeishOr[messages_.Message]) -> None: """Delete a given message in a given channel. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to delete. This may be the object or the ID of an existing message. Raises ------ ValueError If `token` is not available. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook or the message are not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if self.token is None: raise ValueError("Cannot delete a message using a webhook where we don't know the token") await self.app.rest.delete_webhook_message(self.webhook_id, token=self.token, message=message)
Delete a given message in a given channel.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to delete. This may be the object or the ID of an existing message.
Raises
- ValueError: If
token
is not available. - hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook or the message are not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
content: Union[Any, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
*,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED
) -> hikari.messages.Message:
View Source
async def edit_initial_response( self, content: undefined.UndefinedNoneOr[typing.Any] = undefined.UNDEFINED, *, attachment: undefined.UndefinedOr[files.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedNoneOr[ typing.Sequence[special_endpoints.ComponentBuilder] ] = undefined.UNDEFINED, embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedNoneOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, replace_attachments: bool = False, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds.PartialRole], bool] ] = undefined.UNDEFINED, ) -> messages.Message: """Edit the initial response of this command interaction. .. note:: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however. .. warning:: If you specify a text `content`, `mentions_everyone`, `mentions_reply`, `user_mentions`, and `role_mentions` will default to `False` as the message will be re-parsed for mentions. This will also occur if only one of the four are specified This is a limitation of Discord's design. If in doubt, specify all four of them each time. Other Parameters ---------------- content : hikari.undefined.UndefinedNoneOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and neither the `embed` or `embeds` kwargs are provided or if this is a `hikari.files.Resourceish` and neither the `attachment` or `attachments` kwargs are provided, the values will be overwritten. This allows for simpler syntax when sending an embed or an attachment alone. Likewise, if this is a `hikari.files.Resource`, then the content is instead treated as an attachment if no `attachment` and no `attachments` kwargs are provided. attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish] If provided, the attachment to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachment, if present, is not changed. If this is `None`, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]] If provided, the attachments to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachments, if present, are not changed. If this is `None`, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. component : hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to set for this message. This component will replace any previously set components and passing `None` will remove all components. components : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing `None` or an empty sequence will remove all components. embed : hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed] If provided, the embed to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. embeds : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]] If provided, the embeds to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments: bool Whether to replace the attachments with the provided ones. Defaults to `False`. Note this will also overwrite the embed attachments. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, whether the message should parse @everyone/@here mentions. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all user mentions will be detected. If provided, and `False`, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all role mentions will be detected. If provided, and `False`, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. Returns ------- hikari.messages.Message The edited message. Raises ------ ValueError If more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions`. TypeError If both `embed` and `embeds` are specified. hikari.errors.BadRequestError This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; invalid image URLs in embeds; too many components. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the interaction or the message are not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ # noqa: E501 - Line too long return await self.app.rest.edit_interaction_response( self.application_id, self.token, content, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, replace_attachments=replace_attachments, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, )
Edit the initial response of this command interaction.
Note: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however.
Warning: If you specify a text content
, mentions_everyone
, mentions_reply
, user_mentions
, and role_mentions
will default to False
as the message will be re-parsed for mentions. This will also occur if only one of the four are specified
This is a limitation of Discord's design. If in doubt, specify all four of them each time.
Other Parameters
content (hikari.undefined.UndefinedNoneOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and neither theembed
orembeds
kwargs are provided or if this is ahikari.files.Resourceish
and neither theattachment
orattachments
kwargs are provided, the values will be overwritten. This allows for simpler syntax when sending an embed or an attachment alone.Likewise, if this is a
hikari.files.Resource
, then the content is instead treated as an attachment if noattachment
and noattachments
kwargs are provided.- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish]): If provided, the attachment to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachment, if present, is not changed. If this isNone
, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. - attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]]): If provided, the attachments to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachments, if present, are not changed. If this isNone
, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. - component (hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to set for this message. This component will replace any previously set components and passing
None
will remove all components. - components (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing
None
or an empty sequence will remove all components. - embed (hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed]): If provided, the embed to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. - embeds (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the embeds to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments (bool): Whether to replace the attachments with the provided ones. Defaults to
False
.Note this will also overwrite the embed attachments.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, whether the message should parse @everyone/@here mentions.
- user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all user mentions will be detected. If provided, andFalse
, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all role mentions will be detected. If provided, andFalse
, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles.
Returns
- hikari.messages.Message: The edited message.
Raises
- ValueError: If more than 100 unique objects/entities are passed for
role_mentions
oruser_mentions
. - TypeError: If both
embed
andembeds
are specified. - hikari.errors.BadRequestError: This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; invalid image URLs in embeds; too many components.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the interaction or the message are not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int],
content: Union[Any, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
*,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType, NoneType] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED
) -> hikari.messages.Message:
View Source
async def edit_message( self, message: snowflakes.SnowflakeishOr[messages_.Message], content: undefined.UndefinedNoneOr[typing.Any] = undefined.UNDEFINED, *, attachment: undefined.UndefinedOr[files.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedNoneOr[ typing.Sequence[special_endpoints.ComponentBuilder] ] = undefined.UNDEFINED, embed: undefined.UndefinedNoneOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedNoneOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, replace_attachments: bool = False, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool] ] = undefined.UNDEFINED, ) -> messages_.Message: """Edit a message sent by a webhook. .. note:: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however. .. warning:: If you specify a text `content`, `mentions_everyone`, `mentions_reply`, `user_mentions`, and `role_mentions` will default to `False` as the message will be re-parsed for mentions. This will also occur if only one of the four are specified This is a limitation of Discord's design. If in doubt, specify all four of them each time. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to delete. This may be the object or the ID of an existing message. content : hikari.undefined.UndefinedNoneOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and no `embed` nor no `embeds` kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone. Likewise, if this is a `hikari.files.Resource`, then the content is instead treated as an attachment if no `attachment` and no `attachments` kwargs are provided. Other Parameters ---------------- attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish] If provided, the attachment to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachment, if present, is not changed. If this is `None`, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]] If provided, the attachments to set on the message. If `hikari.undefined.UNDEFINED`, the previous attachments, if present, are not changed. If this is `None`, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. component : hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to set for this message. This component will replace any previously set components and passing `None` will remove all components. components : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing `None` or an empty sequence will remove all components. embed : hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed] If provided, the embed to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. embeds : hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]] If provided, the embeds to set on the message. If `hikari.undefined.UNDEFINED`, the previous embed(s) are not changed. If this is `None` then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments: bool Whether to replace the attachments with the provided ones. Defaults to `False`. Note this will also overwrite the embed attachments. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, sanitation for `@everyone` mentions. If `hikari.undefined.UNDEFINED`, then the previous setting is not changed. If `True`, then `@everyone`/`@here` mentions in the message content will show up as mentioning everyone that can view the chat. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all user mentions will be detected. If provided, and `False`, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all role mentions will be detected. If provided, and `False`, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. Returns ------- hikari.messages.Message The edited message. Raises ------ ValueError If more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions` or `token` is not available. TypeError If both `attachment` and `attachments` are specified or if both `embed` and `embeds` are specified. hikari.errors.BadRequestError This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; too many components. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook or the message are not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ # noqa: E501 - Line too long if self.token is None: raise ValueError("Cannot edit a message using a webhook where we don't know the token") return await self.app.rest.edit_webhook_message( self.webhook_id, token=self.token, message=message, content=content, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, replace_attachments=replace_attachments, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, )
Edit a message sent by a webhook.
Note: Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however.
Warning: If you specify a text content
, mentions_everyone
, mentions_reply
, user_mentions
, and role_mentions
will default to False
as the message will be re-parsed for mentions. This will also occur if only one of the four are specified
This is a limitation of Discord's design. If in doubt, specify all four of them each time.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to delete. This may be the object or the ID of an existing message.
content (hikari.undefined.UndefinedNoneOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and noembed
nor noembeds
kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.Likewise, if this is a
hikari.files.Resource
, then the content is instead treated as an attachment if noattachment
and noattachments
kwargs are provided.
Other Parameters
- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish]): If provided, the attachment to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachment, if present, is not changed. If this isNone
, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached. - attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]]): If provided, the attachments to set on the message. If
hikari.undefined.UNDEFINED
, the previous attachments, if present, are not changed. If this isNone
, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached. - component (hikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to set for this message. This component will replace any previously set components and passing
None
will remove all components. - components (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing
None
or an empty sequence will remove all components. - embed (hikari.undefined.UndefinedNoneOr[hikari.embeds.Embed]): If provided, the embed to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement. - embeds (hikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the embeds to set on the message. If
hikari.undefined.UNDEFINED
, the previous embed(s) are not changed. If this isNone
then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement. replace_attachments (bool): Whether to replace the attachments with the provided ones. Defaults to
False
.Note this will also overwrite the embed attachments.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, sanitation for
@everyone
mentions. Ifhikari.undefined.UNDEFINED
, then the previous setting is not changed. IfTrue
, then@everyone
/@here
mentions in the message content will show up as mentioning everyone that can view the chat. - user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all user mentions will be detected. If provided, andFalse
, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all role mentions will be detected. If provided, andFalse
, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles.
Returns
- hikari.messages.Message: The edited message.
Raises
- ValueError: If more than 100 unique objects/entities are passed for
role_mentions
oruser_mentions
ortoken
is not available. - TypeError: If both
attachment
andattachments
are specified or if bothembed
andembeds
are specified. - hikari.errors.BadRequestError: This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; too many components.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook or the message are not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
content: Union[Any, hikari.undefined.UndefinedType] = UNDEFINED,
*,
username: Union[str, hikari.undefined.UndefinedType] = UNDEFINED,
avatar_url: Union[hikari.undefined.UndefinedType, str, hikari.files.URL] = UNDEFINED,
tts: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
attachment: Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO, hikari.undefined.UndefinedType] = UNDEFINED,
attachments: Union[Sequence[Union[hikari.files.Resource[Any], os.PathLike[str], str, bytes, bytearray, memoryview, _io.BytesIO, _io.StringIO]], hikari.undefined.UndefinedType] = UNDEFINED,
component: Union[hikari.api.special_endpoints.ComponentBuilder, hikari.undefined.UndefinedType] = UNDEFINED,
components: Union[Sequence[hikari.api.special_endpoints.ComponentBuilder], hikari.undefined.UndefinedType] = UNDEFINED,
embed: Union[hikari.embeds.Embed, hikari.undefined.UndefinedType] = UNDEFINED,
embeds: Union[Sequence[hikari.embeds.Embed], hikari.undefined.UndefinedType] = UNDEFINED,
mentions_everyone: Union[bool, hikari.undefined.UndefinedType] = UNDEFINED,
user_mentions: Union[Sequence[Union[hikari.users.PartialUser, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
role_mentions: Union[Sequence[Union[hikari.guilds.PartialRole, hikari.snowflakes.Snowflake, int]], bool, hikari.undefined.UndefinedType] = UNDEFINED,
flags: Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag] = UNDEFINED
) -> hikari.messages.Message:
View Source
async def execute( self, content: undefined.UndefinedOr[typing.Any] = undefined.UNDEFINED, *, username: undefined.UndefinedOr[str] = undefined.UNDEFINED, avatar_url: typing.Union[undefined.UndefinedType, str, files.URL] = undefined.UNDEFINED, tts: undefined.UndefinedOr[bool] = undefined.UNDEFINED, attachment: undefined.UndefinedOr[files_.Resourceish] = undefined.UNDEFINED, attachments: undefined.UndefinedOr[typing.Sequence[files_.Resourceish]] = undefined.UNDEFINED, component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = undefined.UNDEFINED, components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED, embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED, embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED, mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED, user_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool] ] = undefined.UNDEFINED, role_mentions: undefined.UndefinedOr[ typing.Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool] ] = undefined.UNDEFINED, flags: typing.Union[undefined.UndefinedType, int, messages_.MessageFlag] = undefined.UNDEFINED, ) -> messages_.Message: """Execute the webhook to create a message. .. warning:: At the time of writing, `username` and `avatar_url` are ignored for interaction webhooks. Additionally, flags this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks. Parameters ---------- content : hikari.undefined.UndefinedOr[typing.Any] If provided, the message contents. If `hikari.undefined.UNDEFINED`, then nothing will be sent in the content. Any other value here will be cast to a `str`. If this is a `hikari.embeds.Embed` and no `embed` kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone. Likewise, if this is a `hikari.files.Resource`, then the content is instead treated as an attachment if no `attachment` and no `attachments` kwargs are provided. Other Parameters ---------------- username : hikari.undefined.UndefinedOr[str] If provided, the username to override the webhook's username for this request. avatar_url : typing.Union[hikari.undefined.UndefinedType, hikari.files.URL, str] If provided, the url of an image to override the webhook's avatar with for this request. tts : hikari.undefined.UndefinedOr[bool] If provided, whether the message will be sent as a TTS message. attachment : hikari.undefined.UndefinedOr[hikari.files.Resourceish] If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL. attachments : hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]] If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs. component : hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder] If provided, builder object of the component to include in this message. components : hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]] If provided, a sequence of the component builder objects to include in this message. embed : hikari.undefined.UndefinedOr[hikari.embeds.Embed] If provided, the message embed. embeds : hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]] If provided, the message embeds. mentions_everyone : hikari.undefined.UndefinedOr[bool] If provided, whether the message should parse @everyone/@here mentions. user_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]] If provided, and `True`, all mentions will be parsed. If provided, and `False`, no mentions will be parsed. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.users.PartialUser` derivatives to enforce mentioning specific users. role_mentions : hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]] If provided, and `True`, all mentions will be parsed. If provided, and `False`, no mentions will be parsed. Alternatively this may be a collection of `hikari.snowflakes.Snowflake`, or `hikari.guilds.PartialRole` derivatives to enforce mentioning specific roles. flags : typing.Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag] The flags to set for this webhook message. Returns ------- hikari.messages.Message The created message object. Raises ------ hikari.errors.NotFoundError If the current webhook is not found. hikari.errors.BadRequestError This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than `2000` characters; if neither content, file or embeds are specified. If any invalid snowflake IDs are passed; a snowflake may be invalid due to it being outside of the range of a 64 bit integer. hikari.errors.UnauthorizedError If you pass a token that's invalid for the target webhook. ValueError If either `ExecutableWebhook.token` is `None` or more than 100 unique objects/entities are passed for `role_mentions` or `user_mentions or if `token` is not available. TypeError If both `attachment` and `attachments`, `component` and `components` or `embed` and `embeds` are specified. """ # noqa: E501 - Line too long if not self.token: raise ValueError("Cannot send a message using a webhook where we don't know the token") return await self.app.rest.execute_webhook( webhook=self.webhook_id, token=self.token, content=content, username=username, avatar_url=avatar_url, tts=tts, attachment=attachment, attachments=attachments, component=component, components=components, embed=embed, embeds=embeds, mentions_everyone=mentions_everyone, user_mentions=user_mentions, role_mentions=role_mentions, flags=flags, )
Execute the webhook to create a message.
Warning: At the time of writing, username
and avatar_url
are ignored for interaction webhooks.
Additionally, flags this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks.
Parameters
content (hikari.undefined.UndefinedOr[typing.Any]): If provided, the message contents. If
hikari.undefined.UNDEFINED
, then nothing will be sent in the content. Any other value here will be cast to astr
.If this is a
hikari.embeds.Embed
and noembed
kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.Likewise, if this is a
hikari.files.Resource
, then the content is instead treated as an attachment if noattachment
and noattachments
kwargs are provided.
Other Parameters
- username (hikari.undefined.UndefinedOr[str]): If provided, the username to override the webhook's username for this request.
- avatar_url (typing.Union[hikari.undefined.UndefinedType, hikari.files.URL, str]): If provided, the url of an image to override the webhook's avatar with for this request.
- tts (hikari.undefined.UndefinedOr[bool]): If provided, whether the message will be sent as a TTS message.
- attachment (hikari.undefined.UndefinedOr[hikari.files.Resourceish]): If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL.
- attachments (hikari.undefined.UndefinedOr[typing.Sequence[hikari.files.Resourceish]]): If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs.
- component (hikari.undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder]): If provided, builder object of the component to include in this message.
- components (hikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]): If provided, a sequence of the component builder objects to include in this message.
- embed (hikari.undefined.UndefinedOr[hikari.embeds.Embed]): If provided, the message embed.
- embeds (hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]]): If provided, the message embeds.
- mentions_everyone (hikari.undefined.UndefinedOr[bool]): If provided, whether the message should parse @everyone/@here mentions.
- user_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]): If provided, and
True
, all mentions will be parsed. If provided, andFalse
, no mentions will be parsed. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.users.PartialUser
derivatives to enforce mentioning specific users. - role_mentions (hikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]): If provided, and
True
, all mentions will be parsed. If provided, andFalse
, no mentions will be parsed. Alternatively this may be a collection ofhikari.snowflakes.Snowflake
, orhikari.guilds.PartialRole
derivatives to enforce mentioning specific roles. - flags (typing.Union[hikari.undefined.UndefinedType, int, hikari.messages.MessageFlag]): The flags to set for this webhook message.
Returns
- hikari.messages.Message: The created message object.
Raises
- hikari.errors.NotFoundError: If the current webhook is not found.
- hikari.errors.BadRequestError: This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than
2000
characters; if neither content, file or embeds are specified. If any invalid snowflake IDs are passed; a snowflake may be invalid due to it being outside of the range of a 64 bit integer. - hikari.errors.UnauthorizedError: If you pass a token that's invalid for the target webhook.
- ValueError: If either
ExecutableWebhook.token
isNone
or more than 100 unique objects/entities are passed forrole_mentions
oruser_mentions or if
token` is not available. - TypeError: If both
attachment
andattachments
,component
andcomponents
orembed
andembeds
are specified.
View Source
async def fetch_channel(self) -> channels.TextableChannel: """Fetch the guild channel this was triggered in. Returns ------- hikari.channels.TextableChannel The requested partial channel derived object of the channel this was triggered in. Raises ------ hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.ForbiddenError If you are missing the `READ_MESSAGES` permission in the channel. hikari.errors.NotFoundError If the channel is not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ channel = await self.app.rest.fetch_channel(self.channel_id) assert isinstance(channel, channels.TextableChannel) return channel
Fetch the guild channel this was triggered in.
Returns
- hikari.channels.TextableChannel: The requested partial channel derived object of the channel this was triggered in.
Raises
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.ForbiddenError: If you are missing the
READ_MESSAGES
permission in the channel. - hikari.errors.NotFoundError: If the channel is not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def fetch_command(self) -> commands.PartialCommand: """Fetch the command which triggered this interaction. Returns ------- hikari.commands.PartialCommand Object of this interaction's command. Raises ------ hikari.errors.ForbiddenError If you cannot access the target command. hikari.errors.NotFoundError If the command isn't found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ return await self.app.rest.fetch_application_command( application=self.application_id, command=self.id, guild=self.guild_id or undefined.UNDEFINED )
Fetch the command which triggered this interaction.
Returns
- hikari.commands.PartialCommand: Object of this interaction's command.
Raises
- hikari.errors.ForbiddenError: If you cannot access the target command.
- hikari.errors.NotFoundError: If the command isn't found.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def fetch_guild(self) -> typing.Optional[guilds.RESTGuild]: """Fetch the guild this interaction happened in. Returns ------- typing.Optional[hikari.guilds.RESTGuild] Object of the guild this interaction happened in or `None` if this occurred within a DM channel. Raises ------ hikari.errors.ForbiddenError If you are not part of the guild. hikari.errors.NotFoundError If the guild is not found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if not self.guild_id: return None return await self.app.rest.fetch_guild(self.guild_id)
Fetch the guild this interaction happened in.
Returns
- typing.Optional[hikari.guilds.RESTGuild]: Object of the guild this interaction happened in or
None
if this occurred within a DM channel.
Raises
- hikari.errors.ForbiddenError: If you are not part of the guild.
- hikari.errors.NotFoundError: If the guild is not found.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
async def fetch_initial_response(self) -> messages.Message: """Fetch the initial response of this interaction. Returns ------- hikari.messages.Message Message object of the initial response. Raises ------ hikari.errors.ForbiddenError If you cannot access the target interaction. hikari.errors.NotFoundError If the initial response isn't found. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ return await self.app.rest.fetch_interaction_response(self.application_id, self.token)
Fetch the initial response of this interaction.
Returns
- hikari.messages.Message: Message object of the initial response.
Raises
- hikari.errors.ForbiddenError: If you cannot access the target interaction.
- hikari.errors.NotFoundError: If the initial response isn't found.
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
self,
message: Union[hikari.messages.Message, hikari.snowflakes.Snowflake, int]
) -> hikari.messages.Message:
View Source
async def fetch_message(self, message: snowflakes.SnowflakeishOr[messages_.Message]) -> messages_.Message: """Fetch an old message sent by the webhook. Parameters ---------- message : hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage] The message to fetch. This may be the object or the ID of an existing channel. Returns ------- hikari.messages.Message The requested message. Raises ------ ValueError If `token` is not available. hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.NotFoundError If the webhook is not found or the webhook's message wasn't found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ if self.token is None: raise ValueError("Cannot fetch a message using a webhook where we don't know the token") return await self.app.rest.fetch_webhook_message(self.webhook_id, token=self.token, message=message)
Fetch an old message sent by the webhook.
Parameters
- message (hikari.snowflakes.SnowflakeishOr[hikari.messages.PartialMessage]): The message to fetch. This may be the object or the ID of an existing channel.
Returns
- hikari.messages.Message: The requested message.
Raises
- ValueError: If
token
is not available. - hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.NotFoundError: If the webhook is not found or the webhook's message wasn't found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
def get_channel(self) -> typing.Optional[channels.TextableGuildChannel]: """Get the guild channel this was triggered in from the cache. .. note:: This will always return `None` for interactions triggered in a DM channel. Returns ------- typing.Optional[hikari.channels.TextableGuildChannel] The object of the guild channel that was found in the cache or `None`. """ if isinstance(self.app, traits.CacheAware): channel = self.app.cache.get_guild_channel(self.channel_id) assert isinstance(channel, channels.TextableGuildChannel) return channel return None
Get the guild channel this was triggered in from the cache.
Note: This will always return None
for interactions triggered in a DM channel.
Returns
- typing.Optional[hikari.channels.TextableGuildChannel]: The object of the guild channel that was found in the cache or
None
.
View Source
def get_guild(self) -> typing.Optional[guilds.GatewayGuild]: """Get the object of this interaction's guild guild from the cache. Returns ------- typing.Optional[hikari.guilds.GatewayGuild] The object of the guild if found, else `None`. """ if self.guild_id and isinstance(self.app, traits.CacheAware): return self.app.cache.get_guild(self.guild_id) return None
Get the object of this interaction's guild guild from the cache.
Returns
- typing.Optional[hikari.guilds.GatewayGuild]: The object of the guild if found, else
None
.
View Source
@attr_extensions.with_copy @attr.define(hash=False, kw_only=True, weakref_slot=False) class CommandInteractionOption: """Represents the options passed for a command interaction.""" name: str = attr.field(repr=True) """Name of this option.""" type: typing.Union[commands.OptionType, int] = attr.field(repr=True) """Type of this option.""" value: typing.Union[snowflakes.Snowflake, str, int, bool, None] = attr.field(repr=True) """Value provided for this option. Either `CommandInteractionOption.value` or `CommandInteractionOption.options` will be provided with `value` being provided when an option is provided as a parameter with a value and `options` being provided when an option donates a subcommand or group. """ # TODO: use typing.Self here options: typing.Optional[typing.Sequence[CommandInteractionOption]] = attr.field(repr=True) """Options provided for this option. Either `CommandInteractionOption.value` or `CommandInteractionOption.options` will be provided with `value` being provided when an option is provided as a parameter with a value and `options` being provided when an option donates a subcommand or group. """
Represents the options passed for a command interaction.
Variables and properties
Name of this option.
Options provided for this option.
Either CommandInteractionOption.value
or CommandInteractionOption.options
will be provided with value
being provided when an option is provided as a parameter with a value and options
being provided when an option donates a subcommand or group.
Type of this option.
Value provided for this option.
Either CommandInteractionOption.value
or CommandInteractionOption.options
will be provided with value
being provided when an option is provided as a parameter with a value and options
being provided when an option donates a subcommand or group.
Methods
self,
*,
name: str,
type: Union[hikari.commands.OptionType, int],
value: Union[hikari.snowflakes.Snowflake, str, int, bool, NoneType],
options: Optional[Sequence[hikari.interactions.command_interactions.CommandInteractionOption]]
):
View Source
def __init__(self, *, name, type, value, options): self.name = name self.type = type self.value = value self.options = options
Method generated by attrs for class CommandInteractionOption.
Type-hint of the response types which are valid for a command interaction.
The following types are valid for this:
View Source
@attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) class InteractionChannel(channels.PartialChannel): """Represents partial channels returned as resolved entities on interactions.""" permissions: permissions_.Permissions = attr.field(eq=False, hash=False, repr=True) """Permissions the command's executor has in this channel."""
Represents partial channels returned as resolved entities on interactions.
Variables and properties
The client application that models may use for procedures.
When the object was created.
The ID of this entity.
The channel's name. This will be missing for DM channels.
Permissions the command's executor has in this channel.
The channel's type.
Methods
self,
*,
app: hikari.traits.RESTAware,
id: hikari.snowflakes.Snowflake,
name: Optional[str],
type: 'typing.Union[ChannelType, int]',
permissions: hikari.permissions.Permissions
):
View Source
def __init__(self, *, app, id, name, type, permissions): self.app = app self.id = id self.name = name self.type = type self.permissions = permissions
Method generated by attrs for class InteractionChannel.
View Source
async def delete(self) -> PartialChannel: """Delete a channel in a guild, or close a DM. .. note:: For Public servers, the set 'Rules' or 'Guidelines' channels and the 'Public Server Updates' channel cannot be deleted. Returns ------- hikari.channels.PartialChannel Object of the channel that was deleted. Raises ------ hikari.errors.UnauthorizedError If you are unauthorized to make the request (invalid/missing token). hikari.errors.ForbiddenError If you are missing the `MANAGE_CHANNEL` permission in the channel. hikari.errors.NotFoundError If the channel is not found. hikari.errors.RateLimitTooLongError Raised in the event that a rate limit occurs that is longer than `max_rate_limit` when making a request. hikari.errors.RateLimitedError Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur. hikari.errors.InternalServerError If an internal error occurs on Discord while handling the request. """ return await self.app.rest.delete_channel(self.id)
Delete a channel in a guild, or close a DM.
Note: For Public servers, the set 'Rules' or 'Guidelines' channels and the 'Public Server Updates' channel cannot be deleted.
Returns
- hikari.channels.PartialChannel: Object of the channel that was deleted.
Raises
- hikari.errors.UnauthorizedError: If you are unauthorized to make the request (invalid/missing token).
- hikari.errors.ForbiddenError: If you are missing the
MANAGE_CHANNEL
permission in the channel. - hikari.errors.NotFoundError: If the channel is not found.
- hikari.errors.RateLimitTooLongError: Raised in the event that a rate limit occurs that is longer than
max_rate_limit
when making a request. - hikari.errors.RateLimitedError: Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.
- hikari.errors.InternalServerError: If an internal error occurs on Discord while handling the request.
View Source
@attr_extensions.with_copy @attr.define(hash=False, kw_only=True, weakref_slot=False) class ResolvedOptionData: """Represents the resolved objects of entities referenced in a command's options.""" attachments: typing.Mapping[snowflakes.Snowflake, messages_.Attachment] = attr.field(repr=False) """Mapping of snowflake IDs to the attachment objects.""" channels: typing.Mapping[snowflakes.Snowflake, InteractionChannel] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option partial channel objects.""" members: typing.Mapping[snowflakes.Snowflake, base_interactions.InteractionMember] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option member objects.""" messages: typing.Mapping[snowflakes.Snowflake, messages_.Message] """Mapping of snowflake IDs to the resolved option partial message objects.""" roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option role objects.""" users: typing.Mapping[snowflakes.Snowflake, users_.User] = attr.field(repr=False) """Mapping of snowflake IDs to the resolved option user objects."""
Represents the resolved objects of entities referenced in a command's options.
Variables and properties
Mapping of snowflake IDs to the attachment objects.
Mapping of snowflake IDs to the resolved option partial channel objects.
Mapping of snowflake IDs to the resolved option member objects.
Mapping of snowflake IDs to the resolved option partial message objects.
Mapping of snowflake IDs to the resolved option role objects.
Mapping of snowflake IDs to the resolved option user objects.
Methods
self,
*,
attachments: Mapping[hikari.snowflakes.Snowflake, hikari.messages.Attachment],
channels: Mapping[hikari.snowflakes.Snowflake, hikari.interactions.command_interactions.InteractionChannel],
members: Mapping[hikari.snowflakes.Snowflake, hikari.interactions.base_interactions.InteractionMember],
messages: Mapping[hikari.snowflakes.Snowflake, hikari.messages.Message],
roles: Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Role],
users: Mapping[hikari.snowflakes.Snowflake, hikari.users.User]
):
View Source
def __init__(self, *, attachments, channels, members, messages, roles, users): self.attachments = attachments self.channels = channels self.members = members self.messages = messages self.roles = roles self.users = users
Method generated by attrs for class ResolvedOptionData.