Models and enums used for Discord's Slash Commands interaction flow.
# -*- 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.List[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 locales
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."""
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 `builtins.None` for command interactions triggered in DMs.
"""
guild_locale: typing.Optional[typing.Union[str, locales.Locale]] = attr.field(eq=False, hash=False, repr=True)
"""The preferred language of the guild this command interaction was triggered in.
This will be `builtins.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 `builtins.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: typing.Union[str, locales.Locale] = 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 `builtins.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
`builtins.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 `builtins.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 `builtins.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,
)
const COMMAND_RESPONSE_TYPES : Final[AbstractSet[CommandResponseTypesT]]
Set of the response types which are valid for a command interaction.
This includes:
var CommandResponseTypesT
Type-hint of the response types which are valid for a command interaction.
The following types are valid for this:
class AutocompleteInteraction (
*,
app: traits.RESTAware,
id: snowflakes.Snowflake,
application_id: snowflakes.Snowflake,
type: Union[InteractionType, int],
token: str,
version: int,
channel_id: snowflakes.Snowflake,
guild_id: Optional[snowflakes.Snowflake],
guild_locale: Optional[Union[str, locales.Locale]],
member: Optional[base_interactions.InteractionMember],
user: users_.User,
locale: Union[str, locales.Locale],
command_id: snowflakes.Snowflake,
command_name: str,
command_type: Union[commands.CommandType, int],
resolved: Optional[ResolvedOptionData],
options: Sequence[AutocompleteInteractionOption],
): ...
Represents an autocomplete interaction on Discord.
Method generated by attrs for class AutocompleteInteraction.
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 a base command interaction on Discord …
The base model for all interaction models …
Mixin for a class that enforces uniqueness by a snowflake ID.
An abstract class with logic for executing entities as webhooks.
Helper class that provides a standard way to create an ABC using inheritance.
property app : traits.RESTAware
The client application that models may use for procedures.
property application_id : snowflakes.Snowflake
ID of the application this interaction belongs to.
property channel_id : snowflakes.Snowflake
ID of the channel this command interaction event was triggered in.
property command_id : snowflakes.Snowflake
ID of the command being invoked.
property command_name : str
Name of the command being invoked.
property command_type : Union[commands.CommandType, int]
The type of the command.
property created_at : datetime.datetime
When the object was created.
property guild_id : Optional[snowflakes.Snowflake]
ID of the guild this command interaction event was triggered in.
This will be None
for command interactions triggered in DMs.
property guild_locale : Optional[Union[str, locales.Locale]]
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 features
for the guild and will otherwise default to en-US
.
property id : snowflakes.Snowflake
Return the ID of this entity.
Snowflake
property locale : Union[str, locales.Locale]
The selected language of the user who triggered this command interaction.
property member : Optional[base_interactions.InteractionMember]
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.
property options : Sequence[AutocompleteInteractionOption]
Parameter values provided by the user invoking this command.
property resolved : Optional[ResolvedOptionData]
Mappings of the objects resolved for the provided command options.
property type : Union[InteractionType, int]
The type of interaction this is.
property user : users_.User
The user who triggered this command interaction.
property webhook_id : Snowflake
ID used to execute this entity as a webhook.
Snowflake
def build_response(
choices: 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
create_response
should be used to set
the interaction response.
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"),
]
)
)
InteractionAutocompleteBuilder
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(
choices: Sequence[commands.CommandChoice],
) -> None: ...
Create a response for this autocomplete interaction.
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,
)
async def delete_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
) -> None: ...
Inherited from:
BaseCommandInteraction
.delete_message
Delete a given message in a given channel.
message
: SnowflakeishOr[PartialMessage]
ValueError
token
is not available.UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def edit_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
content: undefined.UndefinedNoneOr[Any] = UNDEFINED,
*,
attachment: undefined.UndefinedOr[files.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files.Resourceish]] = UNDEFINED,
component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedNoneOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedNoneOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedNoneOr[Sequence[embeds_.Embed]] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool]] = UNDEFINED,
) -> messages_.Message: ...
Inherited from:
BaseCommandInteraction
.edit_message
Edit a message sent by a webhook.
message
: SnowflakeishOr[PartialMessage]
content
: UndefinedNoneOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a 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 Resource
, then the
content is instead treated as an attachment if no attachment
and
no attachments
kwargs are provided.
attachment
: UndefinedOr[Resourceish]
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
: UndefinedOr[Sequence[Resourceish]]
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
: UndefinedNoneOr[ComponentBuilder]
None
will remove all components.components
: UndefinedNoneOr[Sequence[ComponentBuilder]]
None
or an empty sequence will
remove all components.embed
: UndefinedNoneOr[Embed]
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
: UndefinedNoneOr[Sequence[Embed]]
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
: UndefinedOr[bool]
@everyone
mentions. If
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
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
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
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
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
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.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 non-embed content
, mentions_everyone
,
mentions_reply
, user_mentions
, and role_mentions
will default
to False
as the message will be re-parsed for mentions.
This is a limitation of Discord's design. If in doubt, specify all three of them each time.
Warning
If you specify one of mentions_everyone
, mentions_reply
,
user_mentions
, or role_mentions
, then all others will default to
False
, even if they were enabled previously.
This is a limitation of Discord's design. If in doubt, specify all three of them each time.
Message
ValueError
role_mentions
or user_mentions
or token
is not available.TypeError
attachment
and attachments
are specified or if both
embed
and embeds
are specified.BadRequestError
UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def execute(
content: undefined.UndefinedOr[Any] = UNDEFINED,
*,
username: undefined.UndefinedOr[str] = UNDEFINED,
avatar_url: Union[undefined.UndefinedType, str, files.URL] = UNDEFINED,
tts: undefined.UndefinedOr[bool] = UNDEFINED,
attachment: undefined.UndefinedOr[files_.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files_.Resourceish]] = UNDEFINED,
component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedOr[Sequence[embeds_.Embed]] = UNDEFINED,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool]] = UNDEFINED,
flags: Union[undefined.UndefinedType, int, messages_.MessageFlag] = UNDEFINED,
) -> messages_.Message: ...
Inherited from:
BaseCommandInteraction
.execute
Execute the webhook to create a message.
content
: UndefinedOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a 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 Resource
, then the
content is instead treated as an attachment if no attachment
and
no attachments
kwargs are provided.
username
: UndefinedOr[str]
avatar_url
: Union[UndefinedType, str, URL]
tts
: UndefinedOr[bool]
attachment
: UndefinedOr[Resourceish]
attachments
: UndefinedOr[Sequence[Resourceish]]
component
: UndefinedOr[ComponentBuilder]
components
: UndefinedOr[Sequence[ComponentBuilder]]
embed
: UndefinedOr[Embed]
embeds
: UndefinedOr[Sequence[Embed]]
mentions_everyone
: UndefinedOr[bool]
user_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
True
, all mentions will be parsed.
If provided, and False
, no mentions will be parsed.
Alternatively this may be a collection of
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
True
, all mentions will be parsed.
If provided, and False
, no mentions will be parsed.
Alternatively this may be a collection of
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.flags
: Union[UndefinedType, int, MessageFlag]
The flags to set for this webhook message.
Warning
As of writing this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks.
Warning
As of writing, username
and avatar_url
are ignored for
interaction webhooks.
Message
NotFoundError
BadRequestError
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.UnauthorizedError
ValueError
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
attachment
and attachments
are specified.async def fetch_channel() -> TextableChannel: ...
Inherited from:
BaseCommandInteraction
.fetch_channel
Fetch the guild channel this was triggered in.
TextableChannel
UnauthorizedError
ForbiddenError
READ_MESSAGES
permission in the channel.NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def fetch_command() -> PartialCommand: ...
Inherited from:
BaseCommandInteraction
.fetch_command
Fetch the command which triggered this interaction.
PartialCommand
ForbiddenError
NotFoundError
UnauthorizedError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def fetch_guild() -> Optional[guilds.RESTGuild]: ...
Inherited from:
BaseCommandInteraction
.fetch_guild
Fetch the guild this interaction happened in.
Optional[RESTGuild]
None
if this occurred within a DM channel.ForbiddenError
NotFoundError
UnauthorizedError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def fetch_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
) -> messages_.Message: ...
Inherited from:
BaseCommandInteraction
.fetch_message
Fetch an old message sent by the webhook.
message
: SnowflakeishOr[PartialMessage]
Message
ValueError
token
is not available.UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
def get_channel() -> Optional[TextableGuildChannel]: ...
Inherited from:
BaseCommandInteraction
.get_channel
Get the guild channel this was triggered in from the cache.
Note
This will always return None
for interactions triggered
in a DM channel.
Optional[TextableGuildChannel]
None
.def get_guild() -> Optional[guilds.GatewayGuild]: ...
Inherited from:
BaseCommandInteraction
.get_guild
Get the object of this interaction's guild guild from the cache.
Optional[GatewayGuild]
None
.class AutocompleteInteractionOption (
*,
name: str,
type: Union[commands.OptionType, int],
value: Union[snowflakes.Snowflake, str, int, bool, None],
is_focused: bool = False,
options: Optional[Sequence[AutocompleteInteractionOption]],
): ...
Represents the options passed for a command autocomplete interaction.
Method generated by attrs for class AutocompleteInteractionOption.
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 interaction …
property is_focused : bool
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.
property options : Optional[Sequence[AutocompleteInteractionOption]]
Options provided for this option.
Either value
or 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.
is_focused
will be True
for the value being
autocompleted.
property type : Union[OptionType, int]
Type of this option.
class BaseCommandInteraction (
*,
app: traits.RESTAware,
id: snowflakes.Snowflake,
application_id: snowflakes.Snowflake,
type: Union[InteractionType, int],
token: str,
version: int,
channel_id: snowflakes.Snowflake,
guild_id: Optional[snowflakes.Snowflake],
guild_locale: Optional[Union[str, locales.Locale]],
member: Optional[base_interactions.InteractionMember],
user: users_.User,
locale: Union[str, locales.Locale],
command_id: snowflakes.Snowflake,
command_name: str,
command_type: Union[commands.CommandType, int],
resolved: Optional[ResolvedOptionData],
): ...
Represents a base command interaction on Discord.
Method generated by attrs for class BaseCommandInteraction.
class BaseCommandInteraction(base_interactions.PartialInteraction):
"""Represents a base command interaction on Discord."""
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 `builtins.None` for command interactions triggered in DMs.
"""
guild_locale: typing.Optional[typing.Union[str, locales.Locale]] = attr.field(eq=False, hash=False, repr=True)
"""The preferred language of the guild this command interaction was triggered in.
This will be `builtins.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 `builtins.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: typing.Union[str, locales.Locale] = 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 `builtins.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
`builtins.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 `builtins.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 `builtins.None`.
"""
if self.guild_id and isinstance(self.app, traits.CacheAware):
return self.app.cache.get_guild(self.guild_id)
return None
Represents an autocomplete interaction on Discord …
Represents a command interaction on Discord …
The base model for all interaction models …
Mixin for a class that enforces uniqueness by a snowflake ID.
An abstract class with logic for executing entities as webhooks.
Helper class that provides a standard way to create an ABC using inheritance.
property app : traits.RESTAware
The client application that models may use for procedures.
property application_id : snowflakes.Snowflake
ID of the application this interaction belongs to.
property channel_id : snowflakes.Snowflake
ID of the channel this command interaction event was triggered in.
property command_id : snowflakes.Snowflake
ID of the command being invoked.
property command_name : str
Name of the command being invoked.
property command_type : Union[commands.CommandType, int]
The type of the command.
property created_at : datetime.datetime
When the object was created.
property guild_id : Optional[snowflakes.Snowflake]
ID of the guild this command interaction event was triggered in.
This will be None
for command interactions triggered in DMs.
property guild_locale : Optional[Union[str, locales.Locale]]
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 features
for the guild and will otherwise default to en-US
.
property id : snowflakes.Snowflake
Return the ID of this entity.
Snowflake
property locale : Union[str, locales.Locale]
The selected language of the user who triggered this command interaction.
property member : Optional[base_interactions.InteractionMember]
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.
property resolved : Optional[ResolvedOptionData]
Mappings of the objects resolved for the provided command options.
property type : Union[InteractionType, int]
The type of interaction this is.
property user : users_.User
The user who triggered this command interaction.
property webhook_id : Snowflake
ID used to execute this entity as a webhook.
Snowflake
async def delete_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
) -> None: ...
Inherited from:
PartialInteraction
.delete_message
Delete a given message in a given channel.
message
: SnowflakeishOr[PartialMessage]
ValueError
token
is not available.UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def edit_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
content: undefined.UndefinedNoneOr[Any] = UNDEFINED,
*,
attachment: undefined.UndefinedOr[files.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files.Resourceish]] = UNDEFINED,
component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedNoneOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedNoneOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedNoneOr[Sequence[embeds_.Embed]] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool]] = UNDEFINED,
) -> messages_.Message: ...
Inherited from:
PartialInteraction
.edit_message
Edit a message sent by a webhook.
message
: SnowflakeishOr[PartialMessage]
content
: UndefinedNoneOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a 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 Resource
, then the
content is instead treated as an attachment if no attachment
and
no attachments
kwargs are provided.
attachment
: UndefinedOr[Resourceish]
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
: UndefinedOr[Sequence[Resourceish]]
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
: UndefinedNoneOr[ComponentBuilder]
None
will remove all components.components
: UndefinedNoneOr[Sequence[ComponentBuilder]]
None
or an empty sequence will
remove all components.embed
: UndefinedNoneOr[Embed]
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
: UndefinedNoneOr[Sequence[Embed]]
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
: UndefinedOr[bool]
@everyone
mentions. If
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
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
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
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
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
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.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 non-embed content
, mentions_everyone
,
mentions_reply
, user_mentions
, and role_mentions
will default
to False
as the message will be re-parsed for mentions.
This is a limitation of Discord's design. If in doubt, specify all three of them each time.
Warning
If you specify one of mentions_everyone
, mentions_reply
,
user_mentions
, or role_mentions
, then all others will default to
False
, even if they were enabled previously.
This is a limitation of Discord's design. If in doubt, specify all three of them each time.
Message
ValueError
role_mentions
or user_mentions
or token
is not available.TypeError
attachment
and attachments
are specified or if both
embed
and embeds
are specified.BadRequestError
UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def execute(
content: undefined.UndefinedOr[Any] = UNDEFINED,
*,
username: undefined.UndefinedOr[str] = UNDEFINED,
avatar_url: Union[undefined.UndefinedType, str, files.URL] = UNDEFINED,
tts: undefined.UndefinedOr[bool] = UNDEFINED,
attachment: undefined.UndefinedOr[files_.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files_.Resourceish]] = UNDEFINED,
component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedOr[Sequence[embeds_.Embed]] = UNDEFINED,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool]] = UNDEFINED,
flags: Union[undefined.UndefinedType, int, messages_.MessageFlag] = UNDEFINED,
) -> messages_.Message: ...
Inherited from:
PartialInteraction
.execute
Execute the webhook to create a message.
content
: UndefinedOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a 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 Resource
, then the
content is instead treated as an attachment if no attachment
and
no attachments
kwargs are provided.
username
: UndefinedOr[str]
avatar_url
: Union[UndefinedType, str, URL]
tts
: UndefinedOr[bool]
attachment
: UndefinedOr[Resourceish]
attachments
: UndefinedOr[Sequence[Resourceish]]
component
: UndefinedOr[ComponentBuilder]
components
: UndefinedOr[Sequence[ComponentBuilder]]
embed
: UndefinedOr[Embed]
embeds
: UndefinedOr[Sequence[Embed]]
mentions_everyone
: UndefinedOr[bool]
user_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
True
, all mentions will be parsed.
If provided, and False
, no mentions will be parsed.
Alternatively this may be a collection of
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
True
, all mentions will be parsed.
If provided, and False
, no mentions will be parsed.
Alternatively this may be a collection of
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.flags
: Union[UndefinedType, int, MessageFlag]
The flags to set for this webhook message.
Warning
As of writing this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks.
Warning
As of writing, username
and avatar_url
are ignored for
interaction webhooks.
Message
NotFoundError
BadRequestError
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.UnauthorizedError
ValueError
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
attachment
and attachments
are specified.async def fetch_channel() -> TextableChannel: ...
Fetch the guild channel this was triggered in.
TextableChannel
UnauthorizedError
ForbiddenError
READ_MESSAGES
permission in the channel.NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
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
async def fetch_command() -> PartialCommand: ...
Fetch the command which triggered this interaction.
PartialCommand
ForbiddenError
NotFoundError
UnauthorizedError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
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() -> Optional[guilds.RESTGuild]: ...
Fetch the guild this interaction happened in.
Optional[RESTGuild]
None
if this occurred within a DM channel.ForbiddenError
NotFoundError
UnauthorizedError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
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 `builtins.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)
async def fetch_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
) -> messages_.Message: ...
Inherited from:
PartialInteraction
.fetch_message
Fetch an old message sent by the webhook.
message
: SnowflakeishOr[PartialMessage]
Message
ValueError
token
is not available.UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
def get_channel() -> Optional[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.
Optional[TextableGuildChannel]
None
.def get_channel(self) -> typing.Optional[channels.TextableGuildChannel]:
"""Get the guild channel this was triggered in from the cache.
!!! note
This will always return `builtins.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
`builtins.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
def get_guild() -> Optional[guilds.GatewayGuild]: ...
Get the object of this interaction's guild guild from the cache.
Optional[GatewayGuild]
None
.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 `builtins.None`.
"""
if self.guild_id and isinstance(self.app, traits.CacheAware):
return self.app.cache.get_guild(self.guild_id)
return None
class CommandInteraction (
*,
app: traits.RESTAware,
id: snowflakes.Snowflake,
application_id: snowflakes.Snowflake,
type: Union[InteractionType, int],
token: str,
version: int,
channel_id: snowflakes.Snowflake,
guild_id: Optional[snowflakes.Snowflake],
guild_locale: Optional[Union[str, locales.Locale]],
member: Optional[base_interactions.InteractionMember],
user: users_.User,
locale: Union[str, locales.Locale],
command_id: snowflakes.Snowflake,
command_name: str,
command_type: Union[commands.CommandType, int],
resolved: Optional[ResolvedOptionData],
options: Optional[Sequence[CommandInteractionOption]],
target_id: Optional[snowflakes.Snowflake] = None,
): ...
Represents a command interaction on Discord.
Method generated by attrs for class CommandInteraction.
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 base command interaction on Discord …
Mixin' class for all interaction types which can be responded to with a message …
The base model for all interaction models …
Mixin for a class that enforces uniqueness by a snowflake ID.
An abstract class with logic for executing entities as webhooks.
Helper class that provides a standard way to create an ABC using inheritance.
Abstract base class for generic types …
property app : traits.RESTAware
The client application that models may use for procedures.
property application_id : snowflakes.Snowflake
ID of the application this interaction belongs to.
property channel_id : snowflakes.Snowflake
ID of the channel this command interaction event was triggered in.
property command_id : snowflakes.Snowflake
ID of the command being invoked.
property command_name : str
Name of the command being invoked.
property command_type : Union[commands.CommandType, int]
The type of the command.
property created_at : datetime.datetime
When the object was created.
property guild_id : Optional[snowflakes.Snowflake]
ID of the guild this command interaction event was triggered in.
This will be None
for command interactions triggered in DMs.
property guild_locale : Optional[Union[str, locales.Locale]]
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 features
for the guild and will otherwise default to en-US
.
property id : snowflakes.Snowflake
Return the ID of this entity.
Snowflake
property locale : Union[str, locales.Locale]
The selected language of the user who triggered this command interaction.
property member : Optional[base_interactions.InteractionMember]
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.
property options : Optional[Sequence[CommandInteractionOption]]
Parameter values provided by the user invoking this command.
property resolved : Optional[ResolvedOptionData]
Mappings of the objects resolved for the provided command options.
property target_id : Optional[snowflakes.Snowflake]
The target of the command. Only available if the command is a context menu command.
property type : Union[InteractionType, int]
The type of interaction this is.
property user : users_.User
The user who triggered this command interaction.
property webhook_id : Snowflake
ID used to execute this entity as a webhook.
Snowflake
def build_deferred_response() -> special_endpoints.InteractionDeferredBuilder: ...
Get a deferred message response builder for use in the REST server flow.
Note
For interactions received over the gateway
create_initial_response
should be used to set
the interaction response message.
Note
Unlike InteractionMessageBuilder
,
the result of this call can be returned as is without any modifications
being made to it.
InteractionMessageBuilder
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)
def build_response() -> special_endpoints.InteractionMessageBuilder: ...
Get a message response builder for use in the REST server flow.
Note
For interactions received over the gateway
create_initial_response
should be used to set
the interaction response message.
async def handle_command_interaction(interaction: CommandInteraction) -> InteractionMessageBuilder:
return (
interaction
.build_response()
.add_embed(Embed(description="Hi there"))
.set_content("Konnichiwa")
)
InteractionMessageBuilder
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)
async def create_initial_response(
response_type: _CommandResponseTypesT,
content: undefined.UndefinedOr[Any] = UNDEFINED,
*,
flags: Union[int, messages.MessageFlag, undefined.UndefinedType] = UNDEFINED,
tts: undefined.UndefinedOr[bool] = UNDEFINED,
attachment: undefined.UndefinedOr[files.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files.Resourceish]] = UNDEFINED,
component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedOr[Sequence[embeds_.Embed]] = UNDEFINED,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds.PartialRole], bool]] = UNDEFINED,
) -> None: ...
Inherited from:
MessageResponseMixin
.create_initial_response
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 NotFoundError
.
This includes if the REST interaction server has already responded
to the request.
response_type
: Union[int, CommandResponseTypesT]
content
: UndefinedOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a 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
: UndefinedOr[Resourceish],
attachments
: UndefinedOr[Sequence[Resourceish]],
component
: UndefinedOr[ComponentBuilder]
components
: UndefinedOr[Sequence[ComponentBuilder]]
embed
: UndefinedOr[Embed]
embeds
: UndefinedOr[Sequence[Embed]]
flags
: Union[int, MessageFlag, UndefinedType]
If provided, the message flags this response should have.
As of writing the only message flag which can be set here is
EPHEMERAL
.
tts
: UndefinedOr[bool]
mentions_everyone
: UndefinedOr[bool]
user_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
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
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
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
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.ValueError
role_mentions
or user_mentions
.TypeError
embed
and embeds
are specified.BadRequestError
UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def delete_initial_response() -> None: ...
Inherited from:
MessageResponseMixin
.delete_initial_response
Delete the initial response of this interaction.
UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def delete_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
) -> None: ...
Inherited from:
BaseCommandInteraction
.delete_message
Delete a given message in a given channel.
message
: SnowflakeishOr[PartialMessage]
ValueError
token
is not available.UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def edit_initial_response(
content: undefined.UndefinedNoneOr[Any] = UNDEFINED,
*,
attachment: undefined.UndefinedOr[files.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files.Resourceish]] = UNDEFINED,
component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedNoneOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedNoneOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedNoneOr[Sequence[embeds_.Embed]] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds.PartialRole], bool]] = UNDEFINED,
) -> messages.Message: ...
Inherited from:
MessageResponseMixin
.edit_initial_response
Edit the initial response of this command interaction.
content
: UndefinedNoneOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a Embed
and neither the
embed
or embeds
kwargs are provided or if this is a
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 Resource
, then the
content is instead treated as an attachment if no attachment
and
no attachments
kwargs are provided.
attachment
: UndefinedOr[Resourceish]
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
: UndefinedOr[Sequence[Resourceish]]
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
: UndefinedNoneOr[ComponentBuilder]
None
will remove all components.components
: UndefinedNoneOr[Sequence[ComponentBuilder]]
None
or an empty sequence will
remove all components.embed
: UndefinedNoneOr[Embed]
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
: UndefinedNoneOr[Sequence[Embed]]
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
: UndefinedOr[bool]
user_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
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
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
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
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.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 one of mentions_everyone
, user_mentions
, or
role_mentions
, then all others will default to False
,
even if they were enabled previously.
This is a limitation of Discord's design. If in doubt, specify all three of them each time.
Message
ValueError
role_mentions
or user_mentions
.TypeError
embed
and embeds
are specified.BadRequestError
UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def edit_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
content: undefined.UndefinedNoneOr[Any] = UNDEFINED,
*,
attachment: undefined.UndefinedOr[files.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files.Resourceish]] = UNDEFINED,
component: undefined.UndefinedNoneOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedNoneOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedNoneOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedNoneOr[Sequence[embeds_.Embed]] = UNDEFINED,
replace_attachments: bool = False,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool]] = UNDEFINED,
) -> messages_.Message: ...
Inherited from:
BaseCommandInteraction
.edit_message
Edit a message sent by a webhook.
message
: SnowflakeishOr[PartialMessage]
content
: UndefinedNoneOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a 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 Resource
, then the
content is instead treated as an attachment if no attachment
and
no attachments
kwargs are provided.
attachment
: UndefinedOr[Resourceish]
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
: UndefinedOr[Sequence[Resourceish]]
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
: UndefinedNoneOr[ComponentBuilder]
None
will remove all components.components
: UndefinedNoneOr[Sequence[ComponentBuilder]]
None
or an empty sequence will
remove all components.embed
: UndefinedNoneOr[Embed]
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
: UndefinedNoneOr[Sequence[Embed]]
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
: UndefinedOr[bool]
@everyone
mentions. If
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
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
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
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
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
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.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 non-embed content
, mentions_everyone
,
mentions_reply
, user_mentions
, and role_mentions
will default
to False
as the message will be re-parsed for mentions.
This is a limitation of Discord's design. If in doubt, specify all three of them each time.
Warning
If you specify one of mentions_everyone
, mentions_reply
,
user_mentions
, or role_mentions
, then all others will default to
False
, even if they were enabled previously.
This is a limitation of Discord's design. If in doubt, specify all three of them each time.
Message
ValueError
role_mentions
or user_mentions
or token
is not available.TypeError
attachment
and attachments
are specified or if both
embed
and embeds
are specified.BadRequestError
UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def execute(
content: undefined.UndefinedOr[Any] = UNDEFINED,
*,
username: undefined.UndefinedOr[str] = UNDEFINED,
avatar_url: Union[undefined.UndefinedType, str, files.URL] = UNDEFINED,
tts: undefined.UndefinedOr[bool] = UNDEFINED,
attachment: undefined.UndefinedOr[files_.Resourceish] = UNDEFINED,
attachments: undefined.UndefinedOr[Sequence[files_.Resourceish]] = UNDEFINED,
component: undefined.UndefinedOr[special_endpoints.ComponentBuilder] = UNDEFINED,
components: undefined.UndefinedOr[Sequence[special_endpoints.ComponentBuilder]] = UNDEFINED,
embed: undefined.UndefinedOr[embeds_.Embed] = UNDEFINED,
embeds: undefined.UndefinedOr[Sequence[embeds_.Embed]] = UNDEFINED,
mentions_everyone: undefined.UndefinedOr[bool] = UNDEFINED,
user_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[users_.PartialUser], bool]] = UNDEFINED,
role_mentions: undefined.UndefinedOr[Union[snowflakes.SnowflakeishSequence[guilds_.PartialRole], bool]] = UNDEFINED,
flags: Union[undefined.UndefinedType, int, messages_.MessageFlag] = UNDEFINED,
) -> messages_.Message: ...
Inherited from:
BaseCommandInteraction
.execute
Execute the webhook to create a message.
content
: UndefinedOr[Any]
If provided, the message contents. If
UNDEFINED
, then nothing will be sent
in the content. Any other value here will be cast to a
str
.
If this is a 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 Resource
, then the
content is instead treated as an attachment if no attachment
and
no attachments
kwargs are provided.
username
: UndefinedOr[str]
avatar_url
: Union[UndefinedType, str, URL]
tts
: UndefinedOr[bool]
attachment
: UndefinedOr[Resourceish]
attachments
: UndefinedOr[Sequence[Resourceish]]
component
: UndefinedOr[ComponentBuilder]
components
: UndefinedOr[Sequence[ComponentBuilder]]
embed
: UndefinedOr[Embed]
embeds
: UndefinedOr[Sequence[Embed]]
mentions_everyone
: UndefinedOr[bool]
user_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialUser], bool]]
True
, all mentions will be parsed.
If provided, and False
, no mentions will be parsed.
Alternatively this may be a collection of
Snowflake
, or
PartialUser
derivatives to enforce mentioning
specific users.role_mentions
: UndefinedOr[Union[SnowflakeishSequence[PartialRole], bool]]
True
, all mentions will be parsed.
If provided, and False
, no mentions will be parsed.
Alternatively this may be a collection of
Snowflake
, or
PartialRole
derivatives to enforce mentioning
specific roles.flags
: Union[UndefinedType, int, MessageFlag]
The flags to set for this webhook message.
Warning
As of writing this can only be set for interaction webhooks and the only settable flag is EPHEMERAL; this field is just ignored for non-interaction webhooks.
Warning
As of writing, username
and avatar_url
are ignored for
interaction webhooks.
Message
NotFoundError
BadRequestError
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.UnauthorizedError
ValueError
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
attachment
and attachments
are specified.async def fetch_channel() -> TextableChannel: ...
Inherited from:
BaseCommandInteraction
.fetch_channel
Fetch the guild channel this was triggered in.
TextableChannel
UnauthorizedError
ForbiddenError
READ_MESSAGES
permission in the channel.NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def fetch_command() -> PartialCommand: ...
Inherited from:
BaseCommandInteraction
.fetch_command
Fetch the command which triggered this interaction.
PartialCommand
ForbiddenError
NotFoundError
UnauthorizedError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def fetch_guild() -> Optional[guilds.RESTGuild]: ...
Inherited from:
BaseCommandInteraction
.fetch_guild
Fetch the guild this interaction happened in.
Optional[RESTGuild]
None
if this occurred within a DM channel.ForbiddenError
NotFoundError
UnauthorizedError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def fetch_initial_response() -> messages.Message: ...
Inherited from:
MessageResponseMixin
.fetch_initial_response
Fetch the initial response of this interaction.
Message
ForbiddenError
NotFoundError
UnauthorizedError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
async def fetch_message(
message: snowflakes.SnowflakeishOr[messages_.Message],
) -> messages_.Message: ...
Inherited from:
BaseCommandInteraction
.fetch_message
Fetch an old message sent by the webhook.
message
: SnowflakeishOr[PartialMessage]
Message
ValueError
token
is not available.UnauthorizedError
NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
def get_channel() -> Optional[TextableGuildChannel]: ...
Inherited from:
BaseCommandInteraction
.get_channel
Get the guild channel this was triggered in from the cache.
Note
This will always return None
for interactions triggered
in a DM channel.
Optional[TextableGuildChannel]
None
.def get_guild() -> Optional[guilds.GatewayGuild]: ...
Inherited from:
BaseCommandInteraction
.get_guild
Get the object of this interaction's guild guild from the cache.
Optional[GatewayGuild]
None
.class CommandInteractionOption (
*,
name: str,
type: Union[commands.OptionType, int],
value: Union[snowflakes.Snowflake, str, int, bool, None],
options: Optional[Sequence[CommandInteractionOption]],
): ...
Represents the options passed for a command interaction.
Method generated by attrs for class CommandInteractionOption.
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 autocomplete interaction …
property options : Optional[Sequence[CommandInteractionOption]]
Options provided for this option.
Either value
or 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.
property type : Union[OptionType, int]
Type of this option.
class InteractionChannel (
*,
app: traits.RESTAware,
id: snowflakes.Snowflake,
name: Optional[str],
type: Union[ChannelType, int],
permissions: permissions_.Permissions,
): ...
Represents partial channels returned as resolved entities on interactions.
Method generated by attrs for class InteractionChannel.
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."""
Channel representation for cases where further detail is not provided …
Mixin for a class that enforces uniqueness by a snowflake ID.
Helper class that provides a standard way to create an ABC using inheritance.
property app : traits.RESTAware
The client application that models may use for procedures.
property created_at : datetime.datetime
When the object was created.
property id : snowflakes.Snowflake
The ID of this entity.
property permissions : permissions_.Permissions
Permissions the command's executor has in this channel.
property type : Union[ChannelType, int]
The channel's type.
async def delete() -> PartialChannel: ...
Inherited from:
PartialChannel
.delete
Delete a channel in a guild, or close a DM.
PartialChannel
UnauthorizedError
ForbiddenError
MANAGE_CHANNEL
permission in the channel.NotFoundError
RateLimitTooLongError
max_rate_limit
when making a request.RateLimitedError
InternalServerError
Note
For Public servers, the set 'Rules' or 'Guidelines' channels and the 'Public Server Updates' channel cannot be deleted.
class ResolvedOptionData (
*,
attachments: Mapping[snowflakes.Snowflake, messages_.Attachment],
channels: Mapping[snowflakes.Snowflake, InteractionChannel],
members: Mapping[snowflakes.Snowflake, base_interactions.InteractionMember],
messages: Mapping[snowflakes.Snowflake, messages_.Message],
roles: Mapping[snowflakes.Snowflake, guilds.Role],
users: Mapping[snowflakes.Snowflake, users_.User],
): ...
Represents the resolved objects of entities referenced in a command's options.
Method generated by attrs for class ResolvedOptionData.
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."""
property attachments : Mapping[snowflakes.Snowflake, messages_.Attachment]
Mapping of snowflake IDs to the attachment objects.
property channels : Mapping[snowflakes.Snowflake, InteractionChannel]
Mapping of snowflake IDs to the resolved option partial channel objects.
property members : Mapping[snowflakes.Snowflake, base_interactions.InteractionMember]
Mapping of snowflake IDs to the resolved option member objects.
property messages : Mapping[snowflakes.Snowflake, messages_.Message]
Mapping of snowflake IDs to the resolved option partial message objects.
property roles : Mapping[snowflakes.Snowflake, guilds.Role]
Mapping of snowflake IDs to the resolved option role objects.
property users : Mapping[snowflakes.Snowflake, users_.User]
Mapping of snowflake IDs to the resolved option user objects.