インタラクションAPIリファレンス¶
次のセクションでは、ライブラリによって実装されたインタラクションの API について概説します。
ライブラリの残りの部分のドキュメントについては、 APIリファレンス を参照してください。
モデル¶
Discordモデル と同様に、これらはユーザーが構築するものではありません。
Interaction¶
- asyncdelete_original_response
- asyncedit_original_response
- defis_expired
- defis_guild_integration
- defis_user_integration
- asyncoriginal_response
- asynctranslate
- class discord.Interaction¶
Discordのインタラクションを表します。
インタラクションは、ユーザーに返信をする必要のあるアクションが行われた際に発生します。現在の例はスラッシュコマンドとコンポーネントです。
バージョン 2.0 で追加.
- type¶
インタラクションの種類。
- channel¶
インタラクションが送信されたチャンネル。
Note that due to a Discord limitation, if sent from a DM channel
recipientisNone.- 型
Optional[Union[
abc.GuildChannel,abc.PrivateChannel,Thread]]
- entitlements¶
The entitlements that the guild or user has.
- 型
List[
Entitlement]
- message¶
このインタラクションを送信したメッセージ。
これは
InteractionType.componentインタラクションの場合にのみ使用できます。- 型
Optional[
Message]
- context¶
The context of the interaction.
バージョン 2.4 で追加.
- filesize_limit¶
The maximum number of bytes a file can have when responding to this interaction.
バージョン 2.6 で追加.
- 型
- property client¶
このインタラクションを処理するクライアント。
なお、
AutoShardedClient、Bot、AutoShardedBotはすべてClientのサブクラスです。- 型
- property permissions¶
権限の上書きを含むチャンネルでのメンバーの権限。
ギルド以外の文脈では権限が適用されないため、空の権限オブジェクトが返されます。
- property app_permissions¶
権限の上書きを含む、アプリケーションまたはボットの解決された権限。
- namespace¶
このインタラクションの解決された名前空間。
アプリケーションコマンドに関連したインタラクションでない場合、またはクライアントにツリーが関連付けられていない場合は、空の名前空間を返します。
- command¶
このインタラクションから呼び出されるコマンド。
アプリケーションコマンドに関連したインタラクションでない場合、またはコマンドがクライアントのアタッチされたツリーにない場合は、
Noneが返されます。- 型
Optional[Union[
app_commands.Command,app_commands.ContextMenu]]
- command_id¶
The ID of the command that triggered this interaction.
Only applicable if
typeis one of,InteractionType.application_commandorInteractionType.autocomplete.バージョン 2.7 で追加.
- 型
Optional[
int]
- response¶
インタラクションへの応答をするためのオブジェクトを返します。
応答は一度だけ行うことができます。複数回にわたってメッセージを送信する必要がある場合は、代わりに
followupを使用することを検討してください。
- property created_at¶
インタラクションが作成された時間を示します。
- property expires_at¶
インタラクションが期限切れになった時の時間を示します。
- custom_id¶
The custom ID of the component that triggered this interaction.
Only applicable if
typeis one of,InteractionType.componentorInteractionType.modal_submit.バージョン 2.7 で追加.
- 型
Optional[
str]
- is_guild_integration()¶
bool: ReturnsTrueif the interaction is a guild integration.バージョン 2.4 で追加.
- await original_response()¶
This function is a coroutine.
インタラクションに関連付けられた元のメッセージを取得します。
もしインタラクションの応答が新しく作成されたメッセージである場合(
InteractionResponse.send_message()やthinkingがTrueのInteractionResponse.defer()等)はそのメッセージを返します。それ以外の場合は、インタラクションが作成されたメッセージを返します。(コンポーネント 等)これを繰り返し呼び出すと、キャッシュされた値が返されます。
- 例外
HTTPException -- 元のインタラクションのメッセージの取得に失敗した場合。
ClientException -- メッセージのチャンネルの解決ができなかった場合。
NotFound -- インタラクションの応答のメッセージが存在しなかった場合。
- 戻り値
元のインタラクションの応答メッセージ。
- 戻り値の型
- await edit_original_response(*, content=..., embeds=..., embed=..., attachments=..., view=..., allowed_mentions=None, poll=...)¶
This function is a coroutine.
元のインタラクションの応答メッセージを編集します。
これは
InteractionMessage.edit()の下位互換のインターフェースで、メッセージを取得及び、HTTPリクエストを保存することが必要でない場合に使用します。また、一時的なメッセージを送った場合、この方法でのみメッセージを編集することができます。
- パラメータ
content (Optional[
str]) -- メッセージの内容を編集する場合はそのメッセージを、内容を削除する際は、Noneを指定します。embeds (List[
Embed]) -- メッセージを編集するための埋め込みのリスト。embed (Optional[
Embed]) -- メッセージを編集するための埋め込み。Noneを渡すと埋め込みが除去されます。embedsパラメータと同時に使用できません。attachments (List[Union[
Attachment,File]]) --メッセージ内で残す添付ファイルと、新規にアップロードする添付ファイルのリスト。
[]が渡された場合すべての添付ファイルが除去されます。注釈
新しいファイルは常に現在の添付ファイルのあとに表示されます。
allowed_mentions (
AllowedMentions) -- このメッセージで処理されるメンションを制御します。詳細はabc.Messageable.send()を参照してください。view (Optional[Union[
View,LayoutView]]) --このメッセージを更新するために更新されたビュー。
Noneが渡された場合、ビューは削除されます。注釈
If you want to update the message to have a
LayoutView, you must explicitly set thecontent,embed,embeds, andattachmentsparameters toNoneif the previous message had any.poll (
Poll) --The poll to create when editing the message.
バージョン 2.5 で追加.
注釈
This is only accepted when the response type is
InteractionResponseType.deferred_channel_message.
- 例外
HTTPException -- メッセージの編集に失敗した場合。
NotFound -- インタラクションの応答のメッセージが存在しなかった場合。
Forbidden -- 自分以外のメッセージを編集しようとした場合。
TypeError --
embedとembedsの両方を指定した場合。ValueError --
embedsの長さが無効だった場合。
- 戻り値
編集された新しいメッセージ。
- 戻り値の型
- await delete_original_response()¶
This function is a coroutine.
元のインタラクション応答メッセージを削除します。
これは
InteractionMessage.delete()の下位互換のインターフェースで、メッセージを取得及び、HTTPリクエストを保存することが必要でない場合に使用します。- 例外
HTTPException -- メッセージの削除に失敗した場合。
NotFound -- インタラクションの応答のメッセージが存在しなかった場合、または既に削除されていた場合。
Forbidden -- 自分以外のメッセージを削除しようとした場合。
- await translate(string, *, locale=..., data=...)¶
This function is a coroutine.
Translatorを使用して文字列を翻訳します。バージョン 2.1 で追加.
- パラメータ
string (Union[
str,locale_str]) -- 翻訳する文字列。locale_strを使用して、文脈、情報、または必要なメタデータを追加できます。locale (
Locale) -- 使用するロケール。特定のロケールの翻訳が必要な場合に便利です。既定値はユーザのlocaleです。data (Any) -- 翻訳される追加のデータ。指定されない場合は、
commandまたはmessageのうち利用できるものが渡されます。
- 戻り値
翻訳された文字列、またはトランスレータが設定されていない場合
None。- 戻り値の型
Optional[
str]
InteractionResponse¶
- asyncautocomplete
- asyncdefer
- asyncedit_message
- defis_done
- asynclaunch_activity
- asyncpong
- asyncsend_message
- asyncsend_modal
- class discord.InteractionResponse¶
Discordのインタラクション応答を表します。
この型は
Interaction.responseからアクセスできます。バージョン 2.0 で追加.
- property type¶
送信された応答の種類。まだ応答していない場合は
Noneです。
- await defer(*, ephemeral=False, thinking=False)¶
This function is a coroutine.
インタラクションの応答を遅らせます。
これは通常、インタラクションを認識した後、後で他のことを実行する場合に使われます。
以下のインタラクションでのみサポートされています:
バージョン 2.5 で変更: This now returns a
InteractionCallbackResponseinstance.- パラメータ
ephemeral (
bool) -- 遅延メッセージが一時的かどうか。InteractionType.application_commandのインタラクション、またはthinkingがTrueの場合にのみ適用されます。thinking (
bool) -- 遅延の種類を両方が利用可能の場合にデフォルトのInteractionResponseType.deferred_message_updateではなくInteractionResponseType.deferred_channel_messageにするか。Discordのアプリ上では考え中として表示されます。Interaction.followupで考え中の表示を解除できます。アプリケーションコマンド(スラッシュコマンド)はInteractionResponseType.deferred_message_updateを使えません。
- 例外
HTTPException -- インタラクションの遅延に失敗した場合。
InteractionResponded -- 既にインタラクションに応答していた場合。
- 戻り値
The interaction callback resource, or
None.- 戻り値の型
Optional[
InteractionCallbackResponse]
- await pong()¶
This function is a coroutine.
Pingのインタラクションに応答します。
ほとんどの場合使われません。
- 例外
HTTPException -- インタラクションの応答に失敗した場合。
InteractionResponded -- 既にインタラクションに応答していた場合。
- await send_message(content=None, *, embed=..., embeds=..., file=..., files=..., view=..., tts=False, ephemeral=False, allowed_mentions=..., suppress_embeds=False, silent=False, delete_after=None, poll=...)¶
This function is a coroutine.
インタラクションにメッセージで応答します。
バージョン 2.5 で変更: This now returns a
InteractionCallbackResponseinstance.- パラメータ
content (Optional[
str]) -- 送信するメッセージの内容。embeds (List[
Embed]) -- 送信するリッチな埋め込みのリスト。最大10個です。embedパラメータと同時に使用できません。embed (
Embed) -- 送信するリッチな埋め込み。embedsパラメータと同時に使用できません。file (
File) -- アップロードするファイル。files (List[
File]) -- アップロードするファイルのリスト。ファイル数は最大で10個まででなくてはいけません。tts (
bool) -- メッセージが音声合成で送信されるべきかどうかを示します。view (Union[
discord.ui.View,discord.ui.LayoutView]) -- 送信するビュー。ephemeral (
bool) -- メッセージがインタラクションを開始したユーザーだけに表示されるかどうか。もしビューが一時的なメッセージで送信されている、かつタイムアウトが設定されていない場合、タイムアウトは15分に設定されます。allowed_mentions (
AllowedMentions) -- このメッセージで処理されるメンションを制御します。詳細はabc.Messageable.send()を参照してください。suppress_embeds (
bool) -- メッセージの埋め込みを抑制するかどうか。これがTrueに設定されている場合、埋め込みなしでメッセージを送信します。silent (
bool) --Whether to suppress push and desktop notifications for the message. This will increment the mention counter in the UI, but will not actually send a notification.
バージョン 2.2 で追加.
delete_after (
float) --指定すると、これはメッセージを送信したあと削除するまでにバックグラウンドで待機する秒数となります。もし削除が失敗しても、それは静かに無視されます。
バージョン 2.1 で追加.
poll (
Poll) --The poll to send with this message.
バージョン 2.4 で追加.
- 例外
HTTPException -- メッセージの送信に失敗した場合。
TypeError --
embedとembedsまたはfileとfilesの両方を指定した場合。ValueError --
embedsの長さが無効だった場合。InteractionResponded -- 既にインタラクションに応答していた場合。
- 戻り値
The interaction callback data.
- 戻り値の型
- await edit_message(*, content=..., embed=..., embeds=..., attachments=..., view=..., allowed_mentions=..., delete_after=None, suppress_embeds=...)¶
This function is a coroutine.
コンポーネントまたはモーダルのインタラクションに編集で応答します。
バージョン 2.5 で変更: This now returns a
InteractionCallbackResponseinstance.- パラメータ
content (Optional[
str]) -- 現在のメッセージと置き換える新しい内容。Noneを指定すると内容が削除されます。embeds (List[
Embed]) -- メッセージを編集するための埋め込みのリスト。embed (Optional[
Embed]) -- メッセージを編集するための埋め込み。Noneを渡すと埋め込みが除去されます。embedsパラメータと同時に使用できません。attachments (List[Union[
Attachment,File]]) --メッセージ内で残す添付ファイルと、新規にアップロードする添付ファイルのリスト。
[]が渡された場合すべての添付ファイルが除去されます。注釈
新しいファイルは常に現在の添付ファイルのあとに表示されます。
view (Optional[Union[
View,LayoutView]]) --このメッセージを更新するために更新されたビュー。
Noneが渡された場合、ビューは削除されます。注釈
To update the message to add a
LayoutView, you must explicitly set thecontent,embed,embeds, andattachmentsparameters to eitherNoneor an empty array, as appropriate.allowed_mentions (Optional[
AllowedMentions]) -- このメッセージで処理されるメンションを制御します。詳細はMessage.edit()を参照してください。delete_after (
float) --もし指定したなら、これはメッセージを編集したあと待機し削除するまでの秒数です。もし削除が失敗しても、それは静かに無視されます。
バージョン 2.2 で追加.
suppress_embeds (
bool) --Whether to suppress embeds for the message. This removes all the embeds if set to
True. If set toFalsethis brings the embeds back if they were suppressed. Using this parameter requiresmanage_messages.バージョン 2.4 で追加.
- 例外
HTTPException -- メッセージの編集に失敗した場合。
TypeError --
embedとembedsの両方を指定した場合。InteractionResponded -- 既にインタラクションに応答していた場合。
- 戻り値
The interaction callback data, or
Noneif editing the message was not possible.- 戻り値の型
Optional[
InteractionCallbackResponse]
- await send_modal(modal, /)¶
This function is a coroutine.
インタラクションにモーダルで応答します。
バージョン 2.5 で変更: This now returns a
InteractionCallbackResponseinstance.- パラメータ
modal (
Modal) -- 送信するモーダル。- 例外
HTTPException -- モーダルの送信に失敗した場合。
InteractionResponded -- 既にインタラクションに応答していた場合。
- 戻り値
The interaction callback data.
- 戻り値の型
- await autocomplete(choices)¶
This function is a coroutine.
ユーザーが使用できる選択肢を与えることにより、このインタラクションに応答します。
- パラメータ
choices (List[
Choice]) -- 応答する選択肢。- 例外
HTTPException -- 選択肢の送信に失敗した場合。
ValueError -- このインタラクションに選択肢で応答できない場合。
InteractionResponded -- 既にインタラクションに応答していた場合。
- await launch_activity()¶
This function is a coroutine.
Responds to this interaction by launching the activity associated with the app. Only available for apps with activities enabled.
バージョン 2.6 で追加.
- 例外
HTTPException -- Launching the activity failed.
InteractionResponded -- 既にインタラクションに応答していた場合。
- 戻り値
The interaction callback data.
- 戻り値の型
InteractionCallbackResponse¶
- defis_ephemeral
- defis_thinking
- class discord.InteractionCallbackResponse¶
Represents an interaction response callback.
バージョン 2.5 で追加.
- type¶
The interaction callback response type.
- resource¶
The resource that the interaction response created. If a message was sent, this will be a
InteractionMessage. If an activity was launched this will be aInteractionCallbackActivityInstance. In any other case, this will beNone.- 型
Optional[Union[
InteractionMessage,InteractionCallbackActivityInstance]]
- message_id¶
The message ID of the resource. Only available if the resource is a
InteractionMessage.- 型
Optional[
int]
- activity_id¶
The activity ID of the resource. Only available if the resource is a
InteractionCallbackActivityInstance.- 型
Optional[
str]
InteractionCallbackActivityInstance¶
InteractionMessage¶
- asyncadd_files
- asyncadd_reaction
- asyncclear_reaction
- asyncclear_reactions
- asynccreate_thread
- asyncdelete
- asyncedit
- asyncend_poll
- asyncfetch
- asyncfetch_thread
- asyncforward
- defis_forwardable
- defis_system
- asyncpin
- asyncpublish
- asyncremove_attachments
- asyncremove_reaction
- asyncreply
- defto_reference
- asyncunpin
- class discord.InteractionMessage¶
元のインタラクション応答メッセージを表します。
このオブジェクトでインタラクションの応答のメッセージを編集、または削除できます。このオブジェクトを生成するには
Interaction.original_response()を参照して下さい。これは
edit()とdelete()が機能するように変更された上でdiscord.Messageを継承しています。バージョン 2.0 で追加.
- await add_reaction(emoji, /)¶
This function is a coroutine.
メッセージにリアクションを追加します。
絵文字はユニコード絵文字かカスタムギルド絵文字の
Emojiでないといけません。これを行うためには、そのチャンネルにて
read_message_historyが必要です。 もし、他の人がその絵文字でリアクションしていない場合、さらにadd_reactionsが必要です。バージョン 2.0 で変更:
emoji引数は位置限定引数になりました。バージョン 2.0 で変更: この関数は
InvalidArgumentの代わりにTypeErrorを送出します。- パラメータ
emoji (Union[
Emoji,Reaction,PartialEmoji,str]) -- リアクションとして追加する絵文字。- 例外
HTTPException -- リアクションの追加に失敗した場合。
Forbidden -- メッセージにリアクションを付けるのに必要な権限がない場合。
NotFound -- 指定された絵文字が見つからなかった場合。
TypeError -- emojiパラメータが無効の場合。
- clean_content¶
クリーンアップされたメッセージ内容を返すプロパティ。基本的に、これはメンションをクライアントが表示できるようにする、という意味です。例えば、
<#id>は#nameに変換されます。また、これは @everyone メンション や @here メンションを、メンション機能の無いメッセージに変換します。
注釈
これはマークダウンには影響 しません 。マークダウンをエスケープまたは削除したい場合は、この関数とともに
utils.escape_markdown()かutils.remove_markdown()を使用してください。- 型
- await clear_reaction(emoji)¶
This function is a coroutine.
メッセージから特定のリアクションを消去します。
絵文字はユニコード絵文字かカスタムギルド絵文字の
Emojiでないといけません。これを行うには、
manage_messagesが必要です。バージョン 1.3 で追加.
バージョン 2.0 で変更: この関数は
InvalidArgumentの代わりにTypeErrorを送出します。- パラメータ
emoji (Union[
Emoji,Reaction,PartialEmoji,str]) -- 消去された絵文字です。- 例外
HTTPException -- リアクションの除去に失敗した場合。
Forbidden -- リアクションを除去するのに必要な権限がない場合。
NotFound -- 指定された絵文字が見つからなかった場合。
TypeError -- emojiパラメータが無効の場合。
- await clear_reactions()¶
This function is a coroutine.
全てのリアクションをメッセージから消去します。
これを行うには、
manage_messagesが必要です。- 例外
HTTPException -- リアクションの除去に失敗した場合。
Forbidden -- リアクションの除去に必要な権限を持っていない場合。
- await create_thread(*, name, auto_archive_duration=..., slowmode_delay=None, reason=None)¶
This function is a coroutine.
メッセージからパブリックスレッドを作成します。
メッセージから公開スレッドを作成するには、
create_public_threads権限が必要です。このメッセージが属するチャンネルは、
TextChannelでなければなりません。バージョン 2.0 で追加.
- パラメータ
name (
str) -- スレッドの名前。auto_archive_duration (
int) --The duration in minutes before a thread is automatically hidden from the channel list. If not provided, the channel's default auto archive duration is used.
Must be one of
60,1440,4320, or10080, if provided.slowmode_delay (Optional[
int]) -- このチャンネルの秒単位での低速モードレート制限。 最大値は21600です。デフォルトはNoneでこの場合は低速モードレート制限が無しとなります。reason (Optional[
str]) -- スレッドを作成する理由。監査ログに表示されます。
- 例外
Forbidden -- スレッドを作成する権限を持っていない場合。
HTTPException -- スレッドの作成に失敗した場合。
ValueError -- メッセージがギルド情報を持っていない場合。
- 戻り値
作成されたスレッド
- 戻り値の型
- property created_at¶
UTCの、メッセージが作成された時刻。
- await edit(*, content=..., embeds=..., embed=..., attachments=..., view=..., allowed_mentions=None, delete_after=None, poll=...)¶
This function is a coroutine.
メッセージを編集します。
- パラメータ
content (Optional[
str]) -- メッセージの内容を編集する場合はそのメッセージを、内容を削除する際は、Noneを指定します。embeds (List[
Embed]) -- メッセージを編集するための埋め込みのリスト。embed (Optional[
Embed]) -- メッセージを編集するための埋め込み。Noneを渡すと埋め込みが除去されます。embedsパラメータと同時に使用できません。attachments (List[Union[
Attachment,File]]) --メッセージ内で残す添付ファイルと、新規にアップロードする添付ファイルのリスト。
[]が渡された場合すべての添付ファイルが除去されます。注釈
新しいファイルは常に現在の添付ファイルのあとに表示されます。
allowed_mentions (
AllowedMentions) -- このメッセージで処理されるメンションを制御します。詳細はabc.Messageable.send()を参照してください。view (Optional[Union[
View,LayoutView]]) --このメッセージを更新するために更新されたビュー。
Noneが渡された場合、ビューは削除されます。注釈
If you want to update the message to have a
LayoutView, you must explicitly set thecontent,embed,embeds, andattachmentsparameters toNoneif the previous message had any.delete_after (Optional[
float]) --指定すると、これはメッセージを送信したあと削除するまでにバックグラウンドで待機する秒数となります。もし削除が失敗しても、それは静かに無視されます。
バージョン 2.2 で追加.
poll (
Poll) --The poll to create when editing the message.
バージョン 2.5 で追加.
注釈
This is only accepted if the interaction response's
InteractionResponse.typeattribute isInteractionResponseType.deferred_channel_message.
- 例外
HTTPException -- メッセージの編集に失敗した場合。
Forbidden -- 自分以外のメッセージを編集しようとした場合。
TypeError --
embedとembedsの両方を指定した場合。ValueError --
embedsの長さが無効だった場合。
- 戻り値
編集された新しいメッセージ。
- 戻り値の型
- property edited_at¶
メッセージの編集時刻を含む、aware UTC datetime オブジェクト。
- 型
Optional[
datetime.datetime]
- await end_poll()¶
This function is a coroutine.
Ends the
Pollattached to this message.This can only be done if you are the message author.
If the poll was successfully ended, then it returns the updated
Message.- 例外
HTTPException -- Ending the poll failed.
- 戻り値
The updated message.
- 戻り値の型
- await fetch()¶
This function is a coroutine.
部分的なメッセージを完全な
Messageにフェッチします。- 例外
NotFound -- メッセージが見つからなかった場合。
Forbidden -- メッセージを取得するために必要な権限がありません。
HTTPException -- メッセージの取得に失敗しました。
- 戻り値
完全なメッセージ。
- 戻り値の型
- await fetch_thread()¶
This function is a coroutine.
Retrieves the public thread attached to this message.
注釈
This method is an API call. For general usage, consider
threadinstead.バージョン 2.4 で追加.
- 例外
InvalidData -- An unknown channel type was received from Discord or the guild the thread belongs to is not the same as the one in this object points to.
HTTPException -- スレッドの取得に失敗した場合。
NotFound -- There is no thread attached to this message.
Forbidden -- You do not have permission to fetch this channel.
- 戻り値
The public thread attached to this message.
- 戻り値の型
- await forward(destination, *, fail_if_not_exists=True)¶
This function is a coroutine.
Forwards this message to a channel.
バージョン 2.5 で追加.
- パラメータ
destination (
Messageable) -- The channel to forward this message to.fail_if_not_exists (
bool) -- メッセージ参照を使用して返信するとき、メッセージが存在しなくなった場合、またはDiscordがメッセージを取得できなかった場合、HTTPExceptionを送出させるかどうか。
- 例外
HTTPException -- Forwarding the message failed.
- 戻り値
The message sent to the channel.
- 戻り値の型
- property interaction¶
The interaction that this message is a response to.
バージョン 2.0 で追加.
バージョン 2.4 で非推奨: This attribute is deprecated and will be removed in a future version. Use
interaction_metadatainstead.- 型
Optional[
MessageInteraction]
- is_forwardable()¶
bool: Whether the message can be forwarded usingMessage.forward().A message is forwardable only if it is a basic message type and does not contain a poll, call, or activity, and is not a system message.
バージョン 2.7 で追加.
- is_system()¶
bool: メッセージがシステムメッセージであるかどうか。システムメッセージは、何かの応答としてDiscord APIによって構築されるメッセージです。
バージョン 1.3 で追加.
- await pin(*, reason=None)¶
This function is a coroutine.
メッセージをピン留めします。
You must have
pin_messagesto do this in a non-private channel context.- パラメータ
reason (Optional[
str]) --メッセージを固定した理由。監査ログに表示されます。
バージョン 1.4 で追加.
- 例外
Forbidden -- このメッセージをピン留めする権限を持っていない場合。
NotFound -- ピン留めするメッセージやチャンネルが見つからなかったか、既に削除されている場合。
HTTPException -- Pinning the message failed, probably due to the channel having more than 250 pinned messages.
- property pinned_at¶
An aware UTC datetime object containing the time when the message was pinned.
注釈
This is only set for messages that are returned by
abc.Messageable.pins().バージョン 2.6 で追加.
- 型
Optional[
datetime.datetime]
- await publish()¶
This function is a coroutine.
Publishes this message to the channel's followers.
The message must have been sent in a news channel. You must have
send_messagesto do this.自身のメッセージ以外の場合は
manage_messagesも必要です。- 例外
Forbidden -- You do not have the proper permissions to publish this message or the channel is not a news channel.
HTTPException -- メッセージの公開に失敗した場合。
- raw_mentions¶
メッセージのコンテンツにある
<#user_id>の構文にマッチするユーザ ID の配列を返すプロパティです。これによって、メッセージがプライベートチャンネル内のものであってもメンションされたユーザのIDを取得できます。
- 型
List[
int]
- await remove_reaction(emoji, member)¶
This function is a coroutine.
メッセージからメンバーによるリアクションを除去します。
絵文字はユニコード絵文字かカスタムギルド絵文字の
Emojiでないといけません。もしリアクションがあなたのものではなければ(つまり、
memberパラメーターがあなたでないなら)、manage_messagesも必要になります。memberパラメータはメンバーを示しabc.Snowflake抽象基底クラスを満たす必要があります。バージョン 2.0 で変更: この関数は
InvalidArgumentの代わりにTypeErrorを送出します。- パラメータ
emoji (Union[
Emoji,Reaction,PartialEmoji,str]) -- 除去する絵文字。member (
abc.Snowflake) -- リアクションを除去する対象のメンバー。
- 例外
HTTPException -- リアクションの除去に失敗した場合。
Forbidden -- リアクションの除去に必要な権限を持っていない場合。
NotFound -- 指定されたメンバーや絵文字が見つからなかった場合。
TypeError -- emojiパラメータが無効の場合。
- await reply(content=None, **kwargs)¶
This function is a coroutine.
Messageに返信するためのabc.Messageable.send()のショートカットメソッド。バージョン 1.6 で追加.
バージョン 2.0 で変更: この関数は
InvalidArgumentの代わりにTypeErrorまたはValueErrorを送出するようになりました。- 例外
HTTPException -- メッセージの送信に失敗した場合。
Forbidden -- メッセージを送信する適切な権限がない場合。
ValueError --
filesリストの大きさが適切でない場合。TypeError --
fileとfilessの両方を指定した場合。
- 戻り値
送信されたメッセージ。
- 戻り値の型
- system_content¶
Message.typeに関わらず、レンダリングされた際のメッセージ内容を返すプロパティ。MessageType.defaultとMessageType.replyの場合、これはMessage.contentと同じものを返すだけです。しかしそれ以外の場合は、システムメッセージの英語版を返します。- 型
- property thread¶
The public thread created from this message, if it exists.
注釈
For messages received via the gateway this does not retrieve archived threads, as they are not retained in the internal cache. Use
fetch_thread()instead.バージョン 2.4 で追加.
- 型
Optional[
Thread]
- to_reference(*, fail_if_not_exists=True, type=<MessageReferenceType.default: 0>)¶
現在のメッセージから
MessageReferenceを作成します。バージョン 1.6 で追加.
- パラメータ
fail_if_not_exists (
bool) --Whether the referenced message should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.バージョン 1.7 で追加.
type (
MessageReferenceType) --The type of message reference.
バージョン 2.5 で追加.
- 戻り値
メッセージへの参照。
- 戻り値の型
- await unpin(*, reason=None)¶
This function is a coroutine.
メッセージのピン留めを外します。
You must have
pin_messagesto do this in a non-private channel context.- パラメータ
reason (Optional[
str]) --メッセージのピン留めを解除した理由。監査ログに表示されます。
バージョン 1.4 で追加.
- 例外
Forbidden -- このメッセージのピン留めを外す権限を持っていない場合。
NotFound -- ピン留めするメッセージやチャンネルが見つからなかったか、既に削除されている場合。
HTTPException -- メッセージのピン留め解除に失敗した場合。
- await add_files(*files)¶
This function is a coroutine.
メッセージの添付ファイルの末尾に新しいファイルを追加します。
バージョン 2.0 で追加.
- パラメータ
*files (
File) -- メッセージに追加する新しいファイル。- 例外
HTTPException -- メッセージの編集に失敗した場合。
Forbidden -- 自分以外のメッセージを編集しようとした場合。
- 戻り値
編集された新しいメッセージ。
- 戻り値の型
- await remove_attachments(*attachments)¶
This function is a coroutine.
メッセージの添付ファイルを削除します。
バージョン 2.0 で追加.
- パラメータ
*attachments (
Attachment) -- メッセージから削除する添付ファイル。- 例外
HTTPException -- メッセージの編集に失敗した場合。
Forbidden -- 自分以外のメッセージを編集しようとした場合。
- 戻り値
編集された新しいメッセージ。
- 戻り値の型
MessageInteraction¶
MessageInteractionMetadata¶
- class discord.MessageInteractionMetadata¶
Represents the interaction metadata of a
Messageif it was sent in response to an interaction.バージョン 2.4 で追加.
- x == y
二つのメッセージインタラクションが等しいかを比較します。
- x != y
二つのメッセージインタラクションが等しくないかを比較します。
- hash(x)
メッセージインタラクションのハッシュ値を返します。
- type¶
インタラクションの種類。
- original_response_message_id¶
The ID of the original response message if the message is a follow-up.
- 型
Optional[
int]
- interacted_message_id¶
The ID of the message that containes the interactive components, if applicable.
- 型
Optional[
int]
- modal_interaction¶
The metadata of the modal submit interaction that triggered this interaction, if applicable.
- 型
Optional[
MessageInteractionMetadata]
- target_user¶
The user the command was run on, only applicable to user context menus.
バージョン 2.5 で追加.
- 型
Optional[
User]
- target_message_id¶
The ID of the message the command was run on, only applicable to message context menus.
バージョン 2.5 で追加.
- 型
Optional[
int]
- property created_at¶
UTCの、インタラクションが作成された時刻。
- property original_response_message¶
The original response message if the message is a follow-up and is found in cache.
- 型
Optional[
Message]
- property interacted_message¶
The message that containes the interactive components, if applicable and is found in cache.
- 型
Optional[
Message]
Component¶
ActionRow¶
TextInput¶
- class discord.TextInput¶
Discord Bot UI Kitのテキスト入力。
注釈
テキスト入力を作成するためにユーザーが構築でき利用できる型はこれではなく
discord.ui.TextInputです。バージョン 2.0 で追加.
- property type¶
コンポーネントの種類。
LabelComponent¶
- class discord.LabelComponent¶
Represents a label component from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a label is
discord.ui.Labelnot this one.バージョン 2.6 で追加.
- property type¶
コンポーネントの種類。
SectionComponent¶
- class discord.SectionComponent¶
Represents a section from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type to create a section is
discord.ui.Sectionnot this one.バージョン 2.6 で追加.
- children¶
The components on this section.
- 型
List[
TextDisplay]
- property type¶
コンポーネントの種類。
ThumbnailComponent¶
- class discord.ThumbnailComponent¶
Represents a Thumbnail from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type to create a thumbnail is
discord.ui.Thumbnailnot this one.バージョン 2.6 で追加.
- media¶
The media for this thumbnail.
- property type¶
コンポーネントの種類。
TextDisplay¶
- class discord.TextDisplay¶
Represents a text display from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type to create a text display is
discord.ui.TextDisplaynot this one.バージョン 2.6 で追加.
- property type¶
コンポーネントの種類。
MediaGalleryComponent¶
- class discord.MediaGalleryComponent¶
Represents a Media Gallery component from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a media gallery is
discord.ui.MediaGallerynot this one.バージョン 2.6 で追加.
- items¶
The items this gallery has.
- 型
List[
MediaGalleryItem]
- property type¶
コンポーネントの種類。
FileComponent¶
- class discord.FileComponent¶
Represents a File component from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for create a file component is
discord.ui.Filenot this one.バージョン 2.6 で追加.
- media¶
The unfurled attachment contents of the file.
- property type¶
コンポーネントの種類。
SeparatorComponent¶
- class discord.SeparatorComponent¶
Represents a Separator from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a separator is
discord.ui.Separatornot this one.バージョン 2.6 で追加.
- spacing¶
The spacing size of the separator.
- property type¶
コンポーネントの種類。
Container¶
- class discord.Container¶
Represents a Container from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a container is
discord.ui.Containernot this one.バージョン 2.6 で追加.
- property type¶
コンポーネントの種類。
FileUploadComponent¶
- class discord.FileUploadComponent¶
Represents a file upload component from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a file upload is
discord.ui.FileUploadnot this one.バージョン 2.7 で追加.
- min_values¶
The minimum number of files that must be uploaded for this component. Defaults to 1 and must be between 0 and 10.
- 型
- max_values¶
The maximum number of files that must be uploaded for this component. Defaults to 1 and must be between 1 and 10.
- 型
- property type¶
コンポーネントの種類。
RadioGroupComponent¶
- class discord.RadioGroupComponent¶
Represents a radio group component from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a radio group is
discord.ui.RadioGroupnot this one.バージョン 2.7 で追加.
- options¶
A list of options that can be selected in this group.
- 型
List[
RadioGroupOption]
- property type¶
コンポーネントの種類。
CheckboxComponent¶
- class discord.CheckboxComponent¶
Represents a checkbox component from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a checkbox is
discord.ui.Checkboxnot this one.バージョン 2.7 で追加.
- property type¶
コンポーネントの種類。
CheckboxGroupComponent¶
- class discord.CheckboxGroupComponent¶
Represents a checkbox group component from the Discord Bot UI Kit.
これは
Componentから継承されます。注釈
The user constructible and usable type for creating a checkbox group is
discord.ui.CheckboxGroupnot this one.バージョン 2.7 で追加.
- min_values¶
The minimum number of options that must be selected in this component. Must be between 0 and 10. Defaults to 0.
- 型
- max_values¶
The maximum number of options that can be selected in this component. Must be between 1 and 10. Defaults to 1.
- 型
- options¶
A list of options that can be selected in this group.
- 型
List[
CheckboxGroupOption]
- property type¶
コンポーネントの種類。
AppCommand¶
- asyncdelete
- asyncedit
- asyncfetch_permissions
- class discord.app_commands.AppCommand¶
アプリケーションコマンドを表します。
一般的な用語では、これは「スラッシュコマンド」または「コンテキストメニューコマンド」と呼ばれます。
バージョン 2.0 で追加.
- x == y
アプリケーションコマンドが等しいか確認します。
- x != y
アプリケーションコマンドが等しくないか確認します。
- hash(x)
アプリケーションコマンドのハッシュを返します。
- str(x)
アプリケーションコマンドの名前を返します。
- type¶
アプリケーションコマンドのタイプ。
- options¶
オプションのリスト。
- 型
List[Union[
Argument,AppCommandGroup]]
- default_member_permissions¶
このコマンドを実行できるデフォルトのメンバー権限。
- 型
Optional[
Permissions]
- allowed_contexts¶
The contexts that this command is allowed to be used in. Overrides the
dm_permissionattribute.バージョン 2.4 で追加.
- 型
Optional[
AppCommandContext]
- allowed_installs¶
The installation contexts that this command is allowed to be installed in.
バージョン 2.4 で追加.
- 型
Optional[
AppInstallationType]
- await delete()¶
This function is a coroutine.
アプリケーションコマンドを削除します。
- 例外
NotFound -- アプリケーションコマンドが見つからなかった場合。
Forbidden -- アプリケーションコマンドを削除する権限がない場合。
HTTPException -- アプリケーションコマンドの削除に失敗した場合。
MissingApplicationID -- クライアントにアプリケーションIDがない場合。
- await edit(*, name=..., description=..., default_member_permissions=..., dm_permission=..., options=...)¶
This function is a coroutine.
アプリケーションコマンドを編集します。
- パラメータ
name (
str) -- アプリケーションコマンドの新しい名前。description (
str) -- アプリケーションコマンドの新しい説明。default_member_permissions (Optional[
Permissions]) -- このアプリケーションコマンドを使用するために必要な新しいデフォルトの権限。権限要件を削除するにはNoneの値を渡します。dm_permission (
bool) -- アプリケーションコマンドがDMで使用できるかどうかを示します。options (List[Union[
Argument,AppCommandGroup]]) -- このアプリケーションコマンドの新しいオプションのリスト。
- 例外
NotFound -- アプリケーションコマンドが見つからなかった場合。
Forbidden -- アプリケーションコマンドを編集する権限がない場合。
HTTPException -- アプリケーションコマンドの編集に失敗した場合。
MissingApplicationID -- クライアントにアプリケーションIDがない場合。
- 戻り値
新しく編集されたアプリケーションコマンド。
- 戻り値の型
- await fetch_permissions(guild)¶
This function is a coroutine.
コマンドのギルド内の権限を取得します。
- パラメータ
guild (
Snowflake) -- 権限を取得するギルド。- 例外
Forbidden -- アプリケーションコマンドの権限を取得する権限がない場合。
HTTPException -- アプリケーションコマンドの権限を取得するのに失敗した場合。
MissingApplicationID -- クライアントにアプリケーションIDがない場合。
NotFound -- アプリケーションコマンドの権限が見つからなかった場合。これは、権限が同期されている(つまり、デフォルトのまま変わっていない)ことも示します。
- 戻り値
ギルド内のアプリケーションコマンドの権限を表すオブジェクト。
- 戻り値の型
AppCommandGroup¶
- class discord.app_commands.AppCommandGroup¶
アプリケーションコマンドのサブコマンドを表します。
バージョン 2.0 で追加.
- type¶
サブコマンドのタイプ。
- options¶
オプションのリスト。
- 型
List[Union[
Argument,AppCommandGroup]]
- parent¶
親アプリケーションコマンド。
- 型
Union[
AppCommand,AppCommandGroup]
- property qualified_name¶
完全修飾されたコマンド名を返します。
修飾名には親の名前も含まれています。例えば、
/foo barのようなコマンドでは修飾名はfoo barです。- 型
AppCommandChannel¶
- class discord.app_commands.AppCommandChannel¶
アプリケーションコマンドの部分的に解決されたチャンネルオブジェクトを表します。
バージョン 2.0 で追加.
- x == y
二つのチャンネルが等しいかを比較します。
- x != y
二つのチャンネルが等しいものではないか比較します。
- hash(x)
チャンネルのハッシュ値を返します。
- str(x)
チャンネルの名前を返します。
- type¶
チャンネルの種類。
- permissions¶
アプリケーションコマンドを呼び出したユーザーのチャンネル内の解決済み権限。
- category_id¶
The category channel ID this channel belongs to, if applicable.
バージョン 2.6 で追加.
- 型
Optional[
int]
- position¶
The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0.
バージョン 2.6 で追加.
- 型
- last_message_id¶
The last message ID of the message sent to this channel. It may not point to an existing or valid message.
バージョン 2.6 で追加.
- 型
Optional[
int]
- slowmode_delay¶
The number of seconds a member must wait between sending messages in this channel. A value of
0denotes that it is disabled. Bots and users withbypass_slowmodebypass slowmode.バージョン 2.6 で追加.
- 型
- property flags¶
The flags associated with this channel object.
バージョン 2.6 で追加.
- resolve()¶
見つかった場合、アプリケーションコマンドチャンネルを適切なキャッシュからのチャンネルに解決します。
- 戻り値
解決したギルドチャンネル。キャッシュ内に見つからない場合は
Noneが返されます。- 戻り値の型
Optional[
abc.GuildChannel]
- await fetch()¶
This function is a coroutine.
部分的なチャンネルから
abc.GuildChannelを取得します。- 例外
NotFound -- チャンネルが見つからなかった場合。
Forbidden -- チャンネルを取得するために必要な権限がない場合。
HTTPException -- チャンネルの取得に失敗した時。
- 戻り値
完全なチャンネル。
- 戻り値の型
- property jump_url¶
Returns a URL that allows the client to jump to the channel.
バージョン 2.6 で追加.
- 型
- property created_at¶
チャンネルが作成されたときのUTC aware タイムスタンプ。
AppCommandThread¶
- class discord.app_commands.AppCommandThread¶
アプリケーションコマンドの部分的に解決されたスレッドオブジェクトを表します。
バージョン 2.0 で追加.
- x == y
二つのスレッドが等しいかを比較します。
- x != y
二つのスレッドが等しいものではないか比較します。
- hash(x)
スレッドのハッシュを返します。
- str(x)
スレッドの名前を返します。
- type¶
スレッドの種類。
- last_message_id¶
The last message ID of the message sent to this thread. It may not point to an existing or valid message.
バージョン 2.6 で追加.
- 型
Optional[
int]
- slowmode_delay¶
The number of seconds a member must wait between sending messages in this thread. A value of
0denotes that it is disabled. Bots and users withbypass_slowmodebypass slowmode.バージョン 2.6 で追加.
- 型
- member_count¶
An approximate number of members in this thread. This caps at 50.
バージョン 2.6 で追加.
- 型
- total_message_sent¶
The total number of messages sent, including deleted messages.
バージョン 2.6 で追加.
- 型
- permissions¶
アプリケーションコマンドを呼び出したユーザーのスレッド内の解決済み権限。
- auto_archive_duration¶
The duration in minutes until the thread is automatically hidden from the channel list. Usually a value of 60, 1440, 4320 and 10080.
- 型
- archive_timestamp¶
スレッドのアーカイブ状態が最後に更新されたときのawareなタイムスタンプ。
- property parent¶
このスレッドが属する親チャンネル。
- 型
Optional[Union[
ForumChannel,TextChannel]]
- property flags¶
The flags associated with this thread.
バージョン 2.6 で追加.
- property created_at¶
UTCで表されたスレッドが作成されたときのタイムスタンプ。
注釈
このタイムスタンプは、2022 年1 月 9 日以降に作成されたスレッドにのみ存在します。それ以外の場合は
Noneを返します。
- resolve()¶
見つかった場合、アプリケーションコマンドチャンネルを適切なキャッシュからのチャンネルに解決します。
- 戻り値
解決したギルドチャンネル。キャッシュ内に見つからない場合は
Noneが返されます。- 戻り値の型
Optional[
abc.GuildChannel]
AppCommandPermissions¶
- class discord.app_commands.AppCommandPermissions¶
アプリケーションコマンドの権限を表します。
バージョン 2.0 で追加.
- target¶
この権限に関連付けられたロール、ユーザー、またはチャンネル。これは
AllChannelsセンチネル型である可能性もあります。これは対象がキャッシュ内に見つからない場合はObjectとなります。- 型
Any
- type¶
権限の種類。
AppCommandContext¶
AppInstallationType¶
- class discord.app_commands.AppInstallationType(*, guild=None, user=None)¶
Represents the installation location of an application command.
バージョン 2.4 で追加.
- パラメータ
GuildAppCommandPermissions¶
- class discord.app_commands.GuildAppCommandPermissions¶
ギルド内のアプリケーションコマンドの権限を示します。
バージョン 2.0 で追加.
- command¶
権限に紐づけられたアプリケーションコマンド。
- permissions¶
権限ら。最大で100個の制限があります。
- 型
List[
AppCommandPermissions]
Argument¶
- class discord.app_commands.Argument¶
アプリケーションコマンドの引数を表します。
バージョン 2.0 で追加.
- type¶
引数のタイプ。
- parent¶
この引数を持つ親アプリケーションコマンド。
- 型
Union[
AppCommand,AppCommandGroup]
- channel_types¶
このパラメータにて利用できるチャンネルの種類。
- 型
List[
ChannelType]
AllChannels¶
データクラス¶
データクラス と同様に、これらは受け取ることもあれば、ユーザーによって構築することもできます。
SelectOption¶
- class discord.SelectOption(*, label, value=..., description=None, emoji=None, default=False)¶
選択メニューのオプションを表します。
これらはユーザーによって作成することができます。
バージョン 2.0 で追加.
- パラメータ
label (
str) -- オプションのラベル。これはユーザーに表示されます。最大 100 文字まで可能です。value (
str) -- オプションの値。これはユーザーには表示されません。 構築時に指定されていない場合は、ラベル値が既定で使用されます。最大 100 文字まで可能です。description (Optional[
str]) -- 存在する場合、オプションの追加の説明。最大 100 文字まで可能です。emoji (Optional[Union[
str,Emoji,PartialEmoji]]) -- 利用可能な場合、オプションの絵文字。default (
bool) -- このオプションがデフォルトで選択されているかどうか。
- value¶
The value of the option. This is not displayed to users. If not provided when constructed then it defaults to the label.
- 型
- property emoji¶
利用可能な場合、オプションの絵文字。
- 型
Optional[
PartialEmoji]
SelectDefaultValue¶
- class discord.SelectDefaultValue(*, id, type)¶
Represents a select menu's default value.
これらはユーザーによって作成することができます。
バージョン 2.4 で追加.
- パラメータ
id (
int) -- The id of a role, user, or channel.type (
SelectDefaultValueType) -- The type of value thatidrepresents.
- property type¶
The type of value that
idrepresents.
- classmethod from_channel(channel, /)¶
Creates a
SelectDefaultValuewith the type set tochannel.- パラメータ
channel (
Snowflake) -- The channel to create the default value for.- 戻り値
The default value created with the channel.
- 戻り値の型
- classmethod from_role(role, /)¶
Creates a
SelectDefaultValuewith the type set torole.- パラメータ
role (
Snowflake) -- The role to create the default value for.- 戻り値
The default value created with the role.
- 戻り値の型
- classmethod from_user(user, /)¶
Creates a
SelectDefaultValuewith the type set touser.- パラメータ
user (
Snowflake) -- The user to create the default value for.- 戻り値
The default value created with the user.
- 戻り値の型
Choice¶
- class discord.app_commands.Choice(*, name, value)¶
アプリケーションコマンドの引数の選択肢を表します。
バージョン 2.0 で追加.
- x == y
二つの選択肢が等しいかを比較します。
- x != y
二つの選択肢が等しいものではないか比較します。
- hash(x)
選択肢のハッシュ値を返します。
UnfurledMediaItem¶
- class discord.UnfurledMediaItem(url)¶
Represents an unfurled media item.
バージョン 2.6 で追加.
- パラメータ
url (
str) -- The URL of this media item. This can be an arbitrary url or a reference to a local file uploaded as an attachment within the message, which can be accessed with theattachment://<filename>format.
- proxy_url¶
The proxy URL. This is a cached version of the
urlin the case of images. When the message is deleted, this URL might be valid for a few minutes or not valid at all.- 型
Optional[
str]
- content_type¶
The media item's media type
- 型
Optional[
str]
- loading_state¶
The loading state of this media item.
- 型
Optional[
MediaItemLoadingState]
- attachment_id¶
The attachment id this media item points to, only available if the url points to a local file uploaded within the component message.
- 型
Optional[
int]
- property flags¶
This media item's flags.
MediaGalleryItem¶
- class discord.MediaGalleryItem(media, *, description=..., spoiler=...)¶
Represents a
MediaGalleryComponentmedia item.バージョン 2.6 で追加.
- パラメータ
media (Union[
str,discord.File,UnfurledMediaItem]) -- The media item data. This can be a string representing a local file uploaded as an attachment in the message, which can be accessed using theattachment://<filename>format, or an arbitrary url.description (Optional[
str]) -- The description to show within this item. Up to 256 characters. Defaults toNone.spoiler (
bool) -- Whether this item should be flagged as a spoiler.
- property media¶
This item's media data.
RadioGroupOption¶
CheckboxGroupOption¶
列挙型¶
- class discord.InteractionType¶
Interactionのタイプを指定します。バージョン 2.0 で追加.
- ping¶
インタラクション応答サーバーが利用可能かを確認するためのDiscordのping。
- application_command¶
スラッシュコマンドのインタラクション。
- component¶
コンポーネントベースのインタラクション、つまり Discord Bot UI Kitの使用。
- autocomplete¶
オートコンプリートのインタラクション。
- modal_submit¶
モーダル送信のインタラクション。
- class discord.InteractionResponseType¶
インタラクションの応答タイプを示します。
バージョン 2.0 で追加.
- pong¶
pingインタラクションにpongします。
InteractionResponse.pong()も参照してください。
- channel_message¶
インタラクションにメッセージで応答します。
InteractionResponse.send_message()も参照してください。
- deferred_channel_message¶
後でインタラクションにメッセージで応答します。
InteractionResponse.defer()も参照してください。
- deferred_message_update¶
メッセージが後で更新されると約束してコンポーネントインタラクションを確認します。(実際には、メッセージを更新する必要はありません。)
InteractionResponse.defer()も参照してください。
- message_update¶
インタラクションにメッセージを編集して応答します。
InteractionResponse.edit_message()も参照してください。
- autocomplete_result¶
オートコンプリートインタラクションに対し提案された選択肢で応答します。
InteractionResponse.autocomplete()も参照してください。
- modal¶
インタラクションにモーダルで応答します。
InteractionResponse.send_modal()も参照してください。
- class discord.ComponentType¶
コンポーネントのコンポーネントタイプを表します。
バージョン 2.0 で追加.
- action_row¶
Represents a component which holds different components in a row.
- button¶
ボタンコンポーネント。
- text_input¶
テキストボックスコンポーネント。
- select¶
選択メニューコンポーネント。
- user_select¶
ユーザー選択メニューコンポーネント。
- role_select¶
ロール選択メニューコンポーネント。
- mentionable_select¶
ユーザとロールの両方を選択できる選択メニュー。
- channel_select¶
Represents a channel select component.
- section¶
Represents a component which holds different components in a section.
バージョン 2.6 で追加.
- text_display¶
Represents a text display component.
バージョン 2.6 で追加.
- thumbnail¶
Represents a thumbnail component.
バージョン 2.6 で追加.
- media_gallery¶
Represents a media gallery component.
バージョン 2.6 で追加.
- file¶
Represents a file component.
バージョン 2.6 で追加.
- separator¶
Represents a separator component.
バージョン 2.6 で追加.
- container¶
Represents a component which holds different components in a container.
バージョン 2.6 で追加.
- label¶
Represents a label container component, usually in a modal.
バージョン 2.6 で追加.
- file_upload¶
Represents a file upload component, usually in a modal.
バージョン 2.7 で追加.
- radio_group¶
Represents a radio group component.
バージョン 2.7 で追加.
- checkbox_group¶
Represents a checkbox group component.
バージョン 2.7 で追加.
- checkbox¶
Represents a checkbox component.
バージョン 2.7 で追加.
- class discord.ButtonStyle¶
ボタンコンポーネントのスタイルを表します。
バージョン 2.0 で追加.
- primary¶
主なアクションのためのブループル色のボタンを表します。
- secondary¶
主でないアクションのための灰色のボタンを表します。
- success¶
成功したアクションを意味する緑色のボタンを表します。
- danger¶
危険な操作を意味する赤いボタンを表します。
- link¶
リンクボタンを表します。
Represents a button denoting that buying a SKU is required to perform this action.
バージョン 2.4 で追加.
- class discord.TextStyle¶
テキストボックスコンポーネントのスタイルを表します。
バージョン 2.0 で追加.
- short¶
短いテキストボックスを表します。
- paragraph¶
長いフォームのテキストボックスを表します。
- class discord.AppCommandOptionType¶
アプリケーションコマンドのオプションタイプ。これは通常アプリケーションコマンドがとるパラメータの型です。
バージョン 2.0 で追加.
- subcommand¶
サブコマンド。
- subcommand_group¶
サブコマンドグループ。
- string¶
文字列パラメータ。
- integer¶
整数パラメータ。
- boolean¶
真偽値パラメータ。
- user¶
ユーザーパラメータ。
- channel¶
チャンネルパラメータ。
- role¶
ロールパラメータ。
- mentionable¶
メンション可能なもののパラメータ。
- number¶
数値のパラメータ。
- attachment¶
添付ファイルのパラメータ。
- class discord.AppCommandType¶
アプリケーションコマンドの種類。
バージョン 2.0 で追加.
- chat_input¶
スラッシュコマンド。
- user¶
ユーザーコンテキストメニューコマンド。
- message¶
メッセージコンテキストメニューコマンド。
Bot UIキット¶
ライブラリにはコンポーネントベースの UI の作成を支援するヘルパーがあります。これらはすべて discord.ui パッケージにあります。
View¶
- clsView.from_message
- defadd_item
- defclear_items
- deffind_item
- asyncinteraction_check
- defis_dispatching
- defis_finished
- defis_persistent
- asyncon_error
- asyncon_timeout
- defremove_item
- defstop
- asyncwait
- defwalk_children
- class discord.ui.View(*, timeout=180.0)¶
UIビューを表します。
Discord内でUIを作成するには、このオブジェクトを継承する必要があります。
バージョン 2.0 で追加.
- パラメータ
timeout (Optional[
float]) -- UIの最後のインタラクションから起算した、入力を受け付けなくなるまでの秒単位のタイムアウト。Noneの場合タイムアウトはありません。
- classmethod from_message(message, /, *, timeout=180.0)¶
Converts a message's components into a
VieworLayoutView.The
Message.componentsof a message are read-only and separate types from those in thediscord.uinamespace. In order to modify and edit message components they must be converted into aVieworLayoutViewfirst.If the message has any v2 components, then you must use
LayoutViewin order for them to be converted into their respective items.Viewdoes not support v2 components.- パラメータ
message (
discord.Message) -- ビューに変換するコンポーネントを含むメッセージ。timeout (Optional[
float]) -- 変換されたビューのタイムアウト。
- 戻り値
The converted view. This will always return one of
VieworLayoutView, and not one of its subclasses.- 戻り値の型
Union[
View,LayoutView]
- add_item(item)¶
ビューに項目を追加します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- ビューに追加する項目。- 例外
ValueError -- Maximum number of children has been exceeded, the row the item is trying to be added to is full or the item you tried to add is not allowed in this View.
- remove_item(item)¶
ビューから項目を除去します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- ビューから除去する項目。
- clear_items()¶
ビューから項目をすべて除去します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- find_item(id, /)¶
Gets an item with
Item.idset asid, orNoneif not found.警告
This is not the same as
custom_id.バージョン 2.6 で追加.
- await interaction_check(interaction, /)¶
This function is a coroutine.
ビュー内でインタラクションが発生したときに呼び出される、インタラクションのコールバックを処理すべきかを確認するコールバック。
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
この中で例外が発生した場合はチェックは失敗したとみなされ
on_error()が呼び出されます。- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
ビューの子のコールバックを呼び出すべきか。
- 戻り値の型
- is_persistent()¶
bool: ビューが永続的と設定されているかどうか。永続的なビューは、すべてのコンポーネントに
custom_idが設定されており、timeoutがNoneに設定されています。
- await on_error(interaction, error, item, /)¶
This function is a coroutine.
項目のコールバックや
interaction_check()がエラーで失敗したときに呼び出されるコールバック。デフォルトの実装はライブラリロガーに記録します。
- パラメータ
interaction (
Interaction) -- 失敗したインタラクション。error (
Exception) -- 発生した例外。item (
Item) -- 実行に失敗した項目。
- stop()¶
このビューのインタラクションイベントを受け取るのを止めます。
この操作を元に戻すことはできません。
- property timeout¶
UIの最後のインタラクションから起算した、入力を受け付けなくなるまでの秒単位のタイムアウト。
Noneの場合タイムアウトはありません。- 型
Optional[
float]
- property total_children_count¶
The total number of children in this view, including those from nested items.
バージョン 2.6 で追加.
- 型
LayoutView¶
- clsLayoutView.from_message
- defadd_item
- defclear_items
- defcontent_length
- deffind_item
- asyncinteraction_check
- defis_dispatching
- defis_finished
- defis_persistent
- asyncon_error
- asyncon_timeout
- defremove_item
- defstop
- asyncwait
- defwalk_children
- class discord.ui.LayoutView(*, timeout=180.0)¶
Represents a layout view for components.
Discord内でUIを作成するには、このオブジェクトを継承する必要があります。
This differs from a
Viewin that it supports all component types and uses what Discord refers to as "v2 components".You can find usage examples in the repository
バージョン 2.6 で追加.
- パラメータ
timeout (Optional[
float]) -- UIの最後のインタラクションから起算した、入力を受け付けなくなるまでの秒単位のタイムアウト。Noneの場合タイムアウトはありません。
- classmethod from_message(message, /, *, timeout=180.0)¶
Converts a message's components into a
VieworLayoutView.The
Message.componentsof a message are read-only and separate types from those in thediscord.uinamespace. In order to modify and edit message components they must be converted into aVieworLayoutViewfirst.If the message has any v2 components, then you must use
LayoutViewin order for them to be converted into their respective items.Viewdoes not support v2 components.- パラメータ
message (
discord.Message) -- ビューに変換するコンポーネントを含むメッセージ。timeout (Optional[
float]) -- 変換されたビューのタイムアウト。
- 戻り値
The converted view. This will always return one of
VieworLayoutView, and not one of its subclasses.- 戻り値の型
Union[
View,LayoutView]
- add_item(item)¶
ビューに項目を追加します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- ビューに追加する項目。- 例外
ValueError -- Maximum number of children has been exceeded, the row the item is trying to be added to is full or the item you tried to add is not allowed in this View.
- content_length()¶
int: Returns the total length of all text content in the view's items.A view is allowed to have a maximum of 4000 display characters across all its items.
- clear_items()¶
ビューから項目をすべて除去します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- find_item(id, /)¶
Gets an item with
Item.idset asid, orNoneif not found.警告
This is not the same as
custom_id.バージョン 2.6 で追加.
- await interaction_check(interaction, /)¶
This function is a coroutine.
ビュー内でインタラクションが発生したときに呼び出される、インタラクションのコールバックを処理すべきかを確認するコールバック。
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
この中で例外が発生した場合はチェックは失敗したとみなされ
on_error()が呼び出されます。- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
ビューの子のコールバックを呼び出すべきか。
- 戻り値の型
- is_persistent()¶
bool: ビューが永続的と設定されているかどうか。永続的なビューは、すべてのコンポーネントに
custom_idが設定されており、timeoutがNoneに設定されています。
- await on_error(interaction, error, item, /)¶
This function is a coroutine.
項目のコールバックや
interaction_check()がエラーで失敗したときに呼び出されるコールバック。デフォルトの実装はライブラリロガーに記録します。
- パラメータ
interaction (
Interaction) -- 失敗したインタラクション。error (
Exception) -- 発生した例外。item (
Item) -- 実行に失敗した項目。
- remove_item(item)¶
ビューから項目を除去します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- ビューから除去する項目。
- stop()¶
このビューのインタラクションイベントを受け取るのを止めます。
この操作を元に戻すことはできません。
- property timeout¶
UIの最後のインタラクションから起算した、入力を受け付けなくなるまでの秒単位のタイムアウト。
Noneの場合タイムアウトはありません。- 型
Optional[
float]
- property total_children_count¶
The total number of children in this view, including those from nested items.
バージョン 2.6 で追加.
- 型
Modal¶
- defadd_item
- defclear_items
- deffind_item
- asyncinteraction_check
- defis_dispatching
- defis_finished
- defis_persistent
- asyncon_error
- asyncon_submit
- asyncon_timeout
- defremove_item
- defstop
- asyncwait
- defwalk_children
- class discord.ui.Modal(*, title=..., timeout=None, custom_id=...)¶
UIモーダルを表します。
Discord内でモーダルポップアップウィンドウを作成するには、このオブジェクトを継承する必要があります。
バージョン 2.0 で追加.
サンプル
import discord from discord import ui class Questionnaire(ui.Modal, title='Questionnaire Response'): name = ui.Label(text='Name', component=ui.TextInput()) answer = ui.Label(text='Answer', component=ui.TextInput(style=discord.TextStyle.paragraph)) async def on_submit(self, interaction: discord.Interaction): await interaction.response.send_message(f'Thanks for your response, {self.name.component.value}!', ephemeral=True)
- パラメータ
- await on_submit(interaction, /)¶
This function is a coroutine.
モーダルが送信されたときに呼び出されます。
- パラメータ
interaction (
Interaction) -- このモーダルを送信したインタラクション。
- await on_error(interaction, error, /)¶
This function is a coroutine.
on_submit()がエラーで失敗したときに呼び出されるコールバック。デフォルトの実装はライブラリロガーに記録します。
- パラメータ
interaction (
Interaction) -- 失敗したインタラクション。error (
Exception) -- 発生した例外。
- add_item(item)¶
ビューに項目を追加します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- ビューに追加する項目。- 例外
ValueError -- Maximum number of children has been exceeded, the row the item is trying to be added to is full or the item you tried to add is not allowed in this View.
- clear_items()¶
ビューから項目をすべて除去します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- find_item(id, /)¶
Gets an item with
Item.idset asid, orNoneif not found.警告
This is not the same as
custom_id.バージョン 2.6 で追加.
- await interaction_check(interaction, /)¶
This function is a coroutine.
ビュー内でインタラクションが発生したときに呼び出される、インタラクションのコールバックを処理すべきかを確認するコールバック。
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
この中で例外が発生した場合はチェックは失敗したとみなされ
on_error()が呼び出されます。- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
ビューの子のコールバックを呼び出すべきか。
- 戻り値の型
- is_persistent()¶
bool: ビューが永続的と設定されているかどうか。永続的なビューは、すべてのコンポーネントに
custom_idが設定されており、timeoutがNoneに設定されています。
- remove_item(item)¶
ビューから項目を除去します。
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- ビューから除去する項目。
- stop()¶
このビューのインタラクションイベントを受け取るのを止めます。
この操作を元に戻すことはできません。
- property timeout¶
UIの最後のインタラクションから起算した、入力を受け付けなくなるまでの秒単位のタイムアウト。
Noneの場合タイムアウトはありません。- 型
Optional[
float]
- property total_children_count¶
The total number of children in this view, including those from nested items.
バージョン 2.6 で追加.
- 型
Item¶
- asynccallback
- asyncinteraction_check
- class discord.ui.Item¶
すべての UI コンポーネントが継承する基本の UI 項目を表します。
現在サポートされているUI項目は次のとおりです。
バージョン 2.0 で追加.
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- await callback(interaction)¶
This function is a coroutine.
このUI 項目に関連付けられたコールバック。
これはサブクラスによって上書きできます。
- パラメータ
interaction (
Interaction) -- このUI項目を呼び出したインタラクション。
- await interaction_check(interaction, /)¶
This function is a coroutine.
A callback that is called when an interaction happens within this item that checks whether the callback should be processed.
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
If an exception occurs within the body then the check is considered a failure and
View.on_error()(orLayoutView.on_error()) is called.For
DynamicItemthis does not call theon_errorhandler.バージョン 2.4 で追加.
- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
Whether the callback should be called.
- 戻り値の型
DynamicItem¶
- clsDynamicItem.from_custom_id
- asynccallback
- asyncinteraction_check
- class discord.ui.DynamicItem(item, *, row=None)¶
Represents an item with a dynamic
custom_idthat can be used to store state within thatcustom_id.The
custom_idparsing is done using theremodule by passing atemplateparameter to the class parameter list.This item is generated every time the component is dispatched. This means that any variable that holds an instance of this class will eventually be out of date and should not be used long term. Their only purpose is to act as a "template" for the actual dispatched item.
When this item is generated,
viewis set to a regularViewinstance, but to aLayoutViewif the component was sent with one, this is obtained from the original message given from the interaction. This means that custom view subclasses cannot be accessed from this item.バージョン 2.4 で追加.
- パラメータ
item (
Item) -- The item to wrap with dynamic custom ID parsing.template (Union[
str,re.Pattern]) -- The template to use for parsing thecustom_id. This can be a string or a compiled regular expression. This must be passed as a keyword argument to the class creation.row (Optional[
int]) -- このボタンが属する相対的な行。Discordコンポーネントは5行しか持てません。デフォルトでは、項目は自動的にこの5行に配置されます。 行の相対位置を制御したい場合は、インデックスを渡すことをお勧めします。 例えば、row=1 は row=2 の前に表示されます。デフォルトはNoneです。これは自動順序です。 行番号は 0 から 4 の間(つまり、0始まり)でなければなりません。
- property template¶
The compiled regular expression that is used to parse the
custom_id.- 型
re.Pattern
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
- classmethod await from_custom_id(interaction, item, match, /)¶
This function is a coroutine.
A classmethod that is called when the
custom_idof a component matches thetemplateof the class. This is called when the component is dispatched.It must return a new instance of the
DynamicItem.Subclasses must implement this method.
Exceptions raised in this method are logged and ignored.
警告
This method is called before the callback is dispatched, therefore it means that it is subject to the same timing restrictions as the callback. Ergo, you must reply to an interaction within 3 seconds of it being dispatched.
- パラメータ
interaction (
Interaction) -- The interaction that the component belongs to.item (
Item) -- The base item that is being dispatched.match (
re.Match) -- The match object that was created from thetemplatematching thecustom_id.
- 戻り値
The new instance of the
DynamicItemwith information from thematchobject.- 戻り値の型
- await callback(interaction)¶
This function is a coroutine.
このUI 項目に関連付けられたコールバック。
これはサブクラスによって上書きできます。
- パラメータ
interaction (
Interaction) -- このUI項目を呼び出したインタラクション。
- await interaction_check(interaction, /)¶
This function is a coroutine.
A callback that is called when an interaction happens within this item that checks whether the callback should be processed.
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
If an exception occurs within the body then the check is considered a failure and
View.on_error()(orLayoutView.on_error()) is called.For
DynamicItemthis does not call theon_errorhandler.バージョン 2.4 で追加.
- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
Whether the callback should be called.
- 戻り値の型
Button¶
- asynccallback
- asyncinteraction_check
- class discord.ui.Button(*, style=<ButtonStyle.secondary: 2>, label=None, disabled=False, custom_id=None, url=None, emoji=None, row=None, sku_id=None, id=None)¶
UIボタンを表します。
バージョン 2.0 で追加.
- パラメータ
style (
discord.ButtonStyle) -- ボタンのスタイル。custom_id (Optional[
str]) -- The ID of the button that gets received during an interaction. If this button is for a URL, it does not have a custom ID. Can only be up to 100 characters.url (Optional[
str]) -- ボタンの行き先のURL。disabled (
bool) -- ボタンが無効化されているかどうか。label (Optional[
str]) -- The label of the button, if any. Can only be up to 80 characters.emoji (Optional[Union[
PartialEmoji,Emoji,str]]) -- 利用可能な場合、ボタンの絵文字。row (Optional[
int]) --このボタンが属する相対的な行。Discordコンポーネントは5行しか持てません。デフォルトでは、項目は自動的にこの5行に配置されます。 行の相対位置を制御したい場合は、インデックスを渡すことをお勧めします。 例えば、row=1 は row=2 の前に表示されます。デフォルトは
Noneです。これは自動順序です。 行番号は 0 から 4 の間(つまり、0始まり)でなければなりません。注釈
This parameter is ignored when used in a
ActionRowor v2 component.sku_id (Optional[
int]) --The SKU ID this button sends you to. Can't be combined with
url,label,emojinorcustom_id.バージョン 2.4 で追加.
id (Optional[
int]) --The ID of this component. This must be unique across the view.
バージョン 2.6 で追加.
- property style¶
ボタンのスタイル。
- property emoji¶
利用可能な場合、ボタンの絵文字。
- 型
Optional[
PartialEmoji]
- await callback(interaction)¶
This function is a coroutine.
このUI 項目に関連付けられたコールバック。
これはサブクラスによって上書きできます。
- パラメータ
interaction (
Interaction) -- このUI項目を呼び出したインタラクション。
- await interaction_check(interaction, /)¶
This function is a coroutine.
A callback that is called when an interaction happens within this item that checks whether the callback should be processed.
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
If an exception occurs within the body then the check is considered a failure and
View.on_error()(orLayoutView.on_error()) is called.For
DynamicItemthis does not call theon_errorhandler.バージョン 2.4 で追加.
- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
Whether the callback should be called.
- 戻り値の型
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
- @discord.ui.button(*, label=None, custom_id=None, disabled=False, style=<ButtonStyle.secondary: 2>, emoji=None, row=None, id=None)¶
コンポーネントにボタンを付属させるデコレータ。
デコレートされる関数には、
discord.ui.Viewを表すself、受け取ったdiscord.Interactionと押されたdiscord.ui.Buttonの3つのパラメータが必要です。注釈
Buttons with a URL or an SKU cannot be created with this function. Consider creating a
Buttonmanually instead. This is because these buttons cannot have a callback associated with them since Discord does not do any processing with them.- パラメータ
label (Optional[
str]) -- The label of the button, if any. Can only be up to 80 characters.custom_id (Optional[
str]) -- The ID of the button that gets received during an interaction. It is recommended not to set this parameter to prevent conflicts. Can only be up to 100 characters.style (
ButtonStyle) -- ボタンのスタイル。デフォルトはButtonStyle.greyです。disabled (
bool) -- ボタンを無効にするかどうか。デフォルトはFalseです。emoji (Optional[Union[
str,Emoji,PartialEmoji]]) -- ボタンの絵文字。文字列形式またはPartialEmojiまたは完全なEmojiが渡せます。row (Optional[
int]) --このボタンが属する相対的な行。Discordコンポーネントは5行しか持てません。デフォルトでは、項目は自動的にこの5行に配置されます。 行の相対位置を制御したい場合は、インデックスを渡すことをお勧めします。 例えば、row=1 は row=2 の前に表示されます。デフォルトは
Noneです。これは自動順序です。 行番号は 0 から 4 の間(つまり、0始まり)でなければなりません。注釈
This parameter is ignored when used in a
ActionRowor v2 component.id (Optional[
int]) --The ID of this component. This must be unique across the view.
バージョン 2.6 で追加.
TextInput¶
- class discord.ui.TextInput(*, label=None, style=<TextStyle.short: 1>, custom_id=..., placeholder=None, default=None, required=True, min_length=None, max_length=None, row=None, id=None)¶
UI のテキスト入力を表します。
This a top-level layout component that can only be used in
Label.- str(x)
テキスト入力の値、または
Noneの場合空文字列を返します。
バージョン 2.0 で追加.
- パラメータ
label (Optional[
str]) --The label to display above the text input. Can only be up to 45 characters.
バージョン 2.6 で非推奨: This parameter is deprecated, use
discord.ui.Labelinstead.バージョン 2.6 で変更: This parameter is now optional and defaults to
None.custom_id (
str) -- The ID of the text input that gets received during an interaction. If not given then one is generated for you. Can only be up to 100 characters.style (
discord.TextStyle) -- テキスト入力のスタイル。placeholder (Optional[
str]) -- The placeholder text to display when the text input is empty. Can only be up to 100 characters.default (Optional[
str]) -- The default value of the text input. Can only be up to 4000 characters.required (
bool) -- テキスト入力が必須かどうか。min_length (Optional[
int]) -- The minimum length of the text input. Must be between 0 and 4000.max_length (Optional[
int]) -- The maximum length of the text input. Must be between 1 and 4000.row (Optional[
int]) -- このテキスト入力が属する相対的な行。Discordコンポーネントは5行しか持てません。デフォルトでは、項目は自動的にこの5行に配置されます。 行の相対位置を制御したい場合は、インデックスを渡すことをお勧めします。 例えば、row=1 は row=2 の前に表示されます。デフォルトはNoneです。これは自動順序です。 行番号は 0 から 4 の間(つまり、0始まり)でなければなりません。id (Optional[
int]) --The ID of the component. This must be unique across the view.
バージョン 2.6 で追加.
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property style¶
テキスト入力のスタイル。
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
Container¶
- defadd_item
- defclear_items
- defcontent_length
- deffind_item
- asyncinteraction_check
- defremove_item
- defwalk_children
- class discord.ui.Container(*children, accent_colour=None, accent_color=None, spoiler=False, id=None)¶
Represents a UI container.
This is a top-level layout component that can only be used on
LayoutViewand can containActionRows,TextDisplays,Sections,MediaGallerys,Files, andSeparators in it.This can be inherited.
バージョン 2.6 で追加.
サンプル
import discord from discord import ui # you can subclass it and add components as you would add them # in a LayoutView class MyContainer(ui.Container): action_row = ui.ActionRow() @action_row.button(label='A button in a container!') async def a_button(self, interaction: discord.Interaction, button: discord.ui.Button): await interaction.response.send_message('You clicked a button!') # or use it directly on LayoutView class MyView(ui.LayoutView): container = ui.Container(ui.TextDisplay('I am a text display on a container!')) # or you can use your subclass: # container = MyContainer()
- パラメータ
*children (
Item) -- The initial children of this container.accent_colour (Optional[Union[
Colour,int]]) -- The colour of the container. Defaults toNone.accent_color (Optional[Union[
Colour,int]]) -- The color of the container. Defaults toNone.spoiler (
bool) -- Whether to flag this container as a spoiler. Defaults toFalse.id (Optional[
int]) -- The ID of this component. This must be unique across the view.
- property accent_colour¶
The colour of the container, or
None.- 型
Optional[Union[
discord.Colour,int]]
- property accent_color¶
The colour of the container, or
None.- 型
Optional[Union[
discord.Colour,int]]
- for ... in walk_children()¶
An iterator that recursively walks through all the children of this container and its children, if applicable.
- 列挙
Item-- An item in the container.
- add_item(item)¶
Adds an item to this container.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- The item to append.- 例外
ValueError -- Maximum number of children has been exceeded (40) for the entire view.
- remove_item(item)¶
Removes an item from this container.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- The item to remove from the container.
- find_item(id, /)¶
Gets an item with
Item.idset asid, orNoneif not found.警告
This is not the same as
custom_id.
- clear_items()¶
Removes all the items from the container.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- await interaction_check(interaction, /)¶
This function is a coroutine.
A callback that is called when an interaction happens within this item that checks whether the callback should be processed.
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
If an exception occurs within the body then the check is considered a failure and
View.on_error()(orLayoutView.on_error()) is called.For
DynamicItemthis does not call theon_errorhandler.バージョン 2.4 で追加.
- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
Whether the callback should be called.
- 戻り値の型
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
File¶
- class discord.ui.File(media, *, spoiler=..., id=None)¶
Represents a UI file component.
This is a top-level layout component that can only be used on
LayoutView.バージョン 2.6 で追加.
サンプル
import discord from discord import ui class MyView(ui.LayoutView): file = ui.File('attachment://file.txt') # attachment://file.txt points to an attachment uploaded alongside this view
- パラメータ
media (Union[
str,UnfurledMediaItem,discord.File]) -- This file's media. If this is a string it must point to a local file uploaded within the parent view of this item, and must meet theattachment://<filename>format.spoiler (
bool) -- Whether to flag this file as a spoiler. Defaults toFalse.id (Optional[
int]) -- The ID of this component. This must be unique across the view.
- property media¶
Returns this file media.
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
Label¶
- class discord.ui.Label(*, text, component, description=None, id=None)¶
Represents a UI label within a modal.
This is a top-level layout component that can only be used on
Modal.バージョン 2.6 で追加.
- パラメータ
text (
str) -- The text to display above the input field. Can only be up to 45 characters.description (Optional[
str]) -- The description text to display right below the label text. Can only be up to 100 characters.component (
Item) -- The component to display below the label.id (Optional[
int]) -- The ID of the component. This must be unique across the view.
- description¶
The description text to display right below the label text. Can only be up to 100 characters.
- 型
Optional[
str]
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
MediaGallery¶
- defadd_item
- defappend_item
- defclear_items
- definsert_item_at
- defremove_item
- class discord.ui.MediaGallery(*items, id=None)¶
Represents a UI media gallery.
Can contain up to 10
MediaGalleryItems.This is a top-level layout component that can only be used on
LayoutView.バージョン 2.6 で追加.
- パラメータ
*items (
MediaGalleryItem) -- The initial items of this gallery.id (Optional[
int]) -- The ID of this component. This must be unique across the view.
- property items¶
Returns a read-only list of this gallery's items.
- 型
List[
MediaGalleryItem]
- add_item(*, media, description=..., spoiler=...)¶
Adds an item to this gallery.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
media (Union[
str,discord.File,UnfurledMediaItem]) -- The media item data. This can be a string representing a local file uploaded as an attachment in the message, which can be accessed using theattachment://<filename>format, or an arbitrary url.description (Optional[
str]) -- The description to show within this item. Up to 256 characters. Defaults toNone.spoiler (
bool) -- Whether this item should be flagged as a spoiler. Defaults toFalse.
- 例外
ValueError -- Maximum number of items has been exceeded (10).
- append_item(item)¶
Appends an item to this gallery.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
MediaGalleryItem) -- The item to add to the gallery.- 例外
TypeError -- A
MediaGalleryItemwas not passed.ValueError -- Maximum number of items has been exceeded (10).
- insert_item_at(index, *, media, description=..., spoiler=...)¶
Inserts an item before a specified index to the media gallery.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
index (
int) -- The index of where to insert the field.media (Union[
str,discord.File,UnfurledMediaItem]) -- The media item data. This can be a string representing a local file uploaded as an attachment in the message, which can be accessed using theattachment://<filename>format, or an arbitrary url.description (Optional[
str]) -- The description to show within this item. Up to 256 characters. Defaults toNone.spoiler (
bool) -- Whether this item should be flagged as a spoiler. Defaults toFalse.
- 例外
ValueError -- Maximum number of items has been exceeded (10).
- remove_item(item)¶
Removes an item from the gallery.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
MediaGalleryItem) -- The item to remove from the gallery.
- clear_items()¶
Removes all items from the gallery.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
Section¶
- defadd_item
- defclear_items
- defcontent_length
- deffind_item
- asyncinteraction_check
- defremove_item
- defwalk_children
- class discord.ui.Section(*children, accessory, id=None)¶
Represents a UI section.
This is a top-level layout component that can only be used on
LayoutView.バージョン 2.6 で追加.
- パラメータ
- for ... in walk_children()¶
An iterator that recursively walks through all the children of this section and its children, if applicable. This includes the accessory.
- 列挙
Item-- An item in this section.
- add_item(item)¶
Adds an item to this section.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (Union[
str,Item]) -- The item to append, if it is a string it automatically wrapped aroundTextDisplay.- 例外
ValueError -- Maximum number of children has been exceeded (3) or (40) for the entire view.
- remove_item(item)¶
Removes an item from this section.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- The item to remove from the section.
- find_item(id, /)¶
Gets an item with
Item.idset asid, orNoneif not found.警告
This is not the same as
custom_id.
- clear_items()¶
Removes all the items from the section.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- await interaction_check(interaction, /)¶
This function is a coroutine.
A callback that is called when an interaction happens within this item that checks whether the callback should be processed.
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
If an exception occurs within the body then the check is considered a failure and
View.on_error()(orLayoutView.on_error()) is called.For
DynamicItemthis does not call theon_errorhandler.バージョン 2.4 で追加.
- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
Whether the callback should be called.
- 戻り値の型
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
Separator¶
- class discord.ui.Separator(*, visible=True, spacing=<SeparatorSpacing.small: 1>, id=None)¶
Represents a UI separator.
This is a top-level layout component that can only be used on
LayoutView.バージョン 2.6 で追加.
- パラメータ
visible (
bool) -- Whether this separator is visible. On the client side this is whether a divider line should be shown or not.spacing (
SeparatorSpacing) -- The spacing of this separator.id (Optional[
int]) -- The ID of this component. This must be unique across the view.
- property visible¶
Whether this separator is visible.
On the client side this is whether a divider line should be shown or not.
- 型
- property spacing¶
The spacing of this separator.
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
TextDisplay¶
- class discord.ui.TextDisplay(content, *, id=None)¶
Represents a UI text display.
This is a top-level layout component that can only be used on
LayoutView,Section,Container, orModal.バージョン 2.6 で追加.
- パラメータ
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
Thumbnail¶
- class discord.ui.Thumbnail(media, *, description=..., spoiler=..., id=None)¶
Represents a UI Thumbnail. This currently can only be used as a
Section's accessory.バージョン 2.6 で追加.
- パラメータ
media (Union[
str,discord.File,discord.UnfurledMediaItem]) -- The media of the thumbnail. This can be a URL or a reference to an attachment that matches theattachment://filename.extensionstructure.description (Optional[
str]) -- The description of this thumbnail. Up to 256 characters. Defaults toNone.spoiler (
bool) -- Whether to flag this thumbnail as a spoiler. Defaults toFalse.id (Optional[
int]) -- The ID of this component. This must be unique across the view.
- property media¶
This thumbnail unfurled media data.
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
ActionRow¶
- defadd_item
- @button
- defclear_items
- defcontent_length
- deffind_item
- asyncinteraction_check
- defremove_item
- @select
- defwalk_children
- class discord.ui.ActionRow(*children, id=None)¶
Represents a UI action row.
This is a top-level layout component that can only be used on
LayoutViewand can containButtons andSelects in it.Action rows can only have 5 children. This can be inherited.
バージョン 2.6 で追加.
サンプル
import discord from discord import ui # you can subclass it and add components with the decorators class MyActionRow(ui.ActionRow): @ui.button(label='Click Me!') async def click_me(self, interaction: discord.Interaction, button: discord.ui.Button): await interaction.response.send_message('You clicked me!') # or use it directly on LayoutView class MyView(ui.LayoutView): row = ui.ActionRow() # or you can use your subclass: # row = MyActionRow() # you can add items with row.button and row.select @row.button(label='A button!') async def row_button(self, interaction: discord.Interaction, button: discord.ui.Button): await interaction.response.send_message('You clicked a button!')
- パラメータ
- for ... in walk_children()¶
An iterator that recursively walks through all the children of this action row and its children, if applicable.
- 列挙
Item-- An item in the action row.
- add_item(item)¶
Adds an item to this action row.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- The item to add to the action row.- 例外
ValueError -- Maximum number of children has been exceeded (5) or (40) for the entire view.
- remove_item(item)¶
Removes an item from the action row.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- パラメータ
item (
Item) -- The item to remove from the action row.
- find_item(id, /)¶
Gets an item with
Item.idset asid, orNoneif not found.警告
This is not the same as
custom_id.
- clear_items()¶
Removes all items from the action row.
この関数は、流暢なスタイルのチェーンを可能にするため、クラスインスタンスを返します。
- button(*, label=None, custom_id=None, disabled=False, style=<ButtonStyle.secondary: 2>, emoji=None, id=None)¶
A decorator that attaches a button to the action row.
The function being decorated should have three parameters,
selfrepresenting thediscord.ui.ActionRow, thediscord.Interactionyou receive and thediscord.ui.Buttonbeing pressed.注釈
Buttons with a URL or a SKU cannot be created with this function. Consider creating a
Buttonmanually and adding it viaActionRow.add_item()instead. This is beacuse these buttons cannot have a callback associated with them since Discord does not do any processing with them.- パラメータ
label (Optional[
str]) -- The label of the button, if any. Can only be up to 80 characters.custom_id (Optional[
str]) -- The ID of the button that gets received during an interaction. It is recommended to not set this parameters to prevent conflicts. Can only be up to 100 characters.style (
ButtonStyle) -- ボタンのスタイル。デフォルトはButtonStyle.greyです。disabled (
bool) -- ボタンを無効にするかどうか。デフォルトはFalseです。emoji (Optional[Union[
str,Emoji,PartialEmoji]]) -- ボタンの絵文字。文字列形式またはPartialEmojiまたは完全なEmojiが渡せます。id (Optional[
int]) --The ID of the component. This must be unique across the view.
バージョン 2.6 で追加.
- await interaction_check(interaction, /)¶
This function is a coroutine.
A callback that is called when an interaction happens within this item that checks whether the callback should be processed.
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
If an exception occurs within the body then the check is considered a failure and
View.on_error()(orLayoutView.on_error()) is called.For
DynamicItemthis does not call theon_errorhandler.バージョン 2.4 で追加.
- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
Whether the callback should be called.
- 戻り値の型
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
- select(*, cls=discord.ui.select.Select[typing.Any], options=..., channel_types=..., placeholder=None, custom_id=..., min_values=1, max_values=1, disabled=False, default_values=..., id=None)¶
A decorator that attaches a select menu to the action row.
The function being decorated should have three parameters,
selfrepresenting thediscord.ui.ActionRow, thediscord.Interactionyou receive and the chosen select class.コールバック内で選択した値を取得するには、コールバック内で選択したクラスの
values属性を使用します。 値のリストは、使用される選択メニューの種類によって異なります。詳細については、以下の表を参照してください。選択種類
解決された値
List[
str]List[Union[
discord.Member,discord.User]]List[
discord.Role]List[Union[
discord.Role,discord.Member,discord.User]]List[Union[
AppCommandChannel,AppCommandThread]]サンプル
class MyView(discord.ui.LayoutView): action_row = discord.ui.ActionRow() @action_row.select(cls=ChannelSelect, channel_types=[discord.ChannelType.text]) async def select_channels(self, interaction: discord.Interaction, select: ChannelSelect): return await interaction.response.send_message(f'You selected {select.values[0].mention}')
- パラメータ
cls (Union[Type[
discord.ui.Select], Type[discord.ui.UserSelect], Type[discord.ui.RoleSelect], Type[discord.ui.MentionableSelect], Type[discord.ui.ChannelSelect]]) -- 選択メニューに使用するクラス。デフォルトはdiscord.ui.Selectです。 他の選択メニューを使用して、ユーザーに対し異なる選択メニューを表示できます。 それぞれの選択メニューから得られる値については、上の表を参照してください。 サブクラスも同様に機能しますが、サブクラスのコールバックはオーバーライドされます。placeholder (Optional[
str]) -- The placeholder text that is shown if nothing is selected, if any. Can only be up to 150 characters.custom_id (
str) -- The ID of the select menu that gets received during an interaction. It is recommended not to set this parameter to prevent conflicts. Can only be up to 100 characters.min_values (
int) -- 選択メニューにて選択しないといけない最小の項目数。デフォルトは1で、値は0以上25以下でないといけません。max_values (
int) -- 選択メニューにて選択できる最大の項目数。デフォルトは1で、値は1以上25以下でないといけません。options (List[
discord.SelectOption]) -- A list of options that can be selected in this menu. This can only be used withSelectinstances. Can only contain up to 25 items.channel_types (List[
ChannelType]) -- 選択メニューに表示するチャンネルの種類。デフォルトはすべてのチャンネルです。これはChannelSelectインスタンスでのみ使用できます。disabled (
bool) -- 選択メニューを無効にするかどうか。デフォルトはFalseです。default_values (Sequence[
Snowflake]) -- A list of objects representing the default values for the select menu. This cannot be used with regularSelectinstances. IfclsisMentionableSelectandObjectis passed, then the type must be specified in the constructor. Number of items must be in range ofmin_valuesandmax_values.id (Optional[
int]) --The ID of the component. This must be unique across the view.
バージョン 2.6 で追加.
FileUpload¶
- class discord.ui.FileUpload(*, custom_id=..., required=True, min_values=None, max_values=None, id=None)¶
Represents a file upload component within a modal.
バージョン 2.7 で追加.
- パラメータ
id (Optional[
int]) -- The ID of the component. This must be unique across the view.custom_id (Optional[
str]) -- The custom ID of the file upload component.max_values (Optional[
int]) -- The maximum number of files that can be uploaded in this component. Must be between 1 and 10. Defaults to 1.min_values (Optional[
int]) -- The minimum number of files that must be uploaded in this component. Must be between 0 and 10. Defaults to 0.required (
bool) -- Whether this component is required to be filled before submitting the modal. Defaults toTrue.
- property values¶
The list of attachments uploaded by the user.
You can call
to_file()on each attachment to get aFilefor sending.- 型
List[
discord.Attachment]
- property min_values¶
The minimum number of files that must be user upload before submitting the modal.
- 型
- property max_values¶
The maximum number of files that the user must upload before submitting the modal.
- 型
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
RadioGroup¶
- defadd_option
- defappend_option
- class discord.ui.RadioGroup(*, custom_id=..., required=True, options=..., id=None)¶
Represents a radio group component within a modal.
バージョン 2.7 で追加.
- パラメータ
id (Optional[
int]) -- The ID of the component. This must be unique across the view.custom_id (Optional[
str]) -- The custom ID of the component.options (List[
discord.RadioGroupOption]) -- A list of options that can be selected in this radio group. Can contain between 2 and 10 items.required (
bool) -- Whether this component is required to be filled before submitting the modal. Defaults toTrue.
- property type¶
このコンポーネントの種類。
- property options¶
A list of options that can be selected in this radio group.
- 型
List[
discord.RadioGroupOption]
- add_option(*, label, value=..., description=None, default=False)¶
Adds an option to the group.
To append a pre-existing
discord.RadioGroupOptionuse theappend_option()method instead.- パラメータ
- 例外
ValueError -- The number of options exceeds 10.
- append_option(option)¶
Appends an option to the group.
- パラメータ
option (
discord.RadioGroupOption) -- The option to append to the group.- 例外
ValueError -- The number of options exceeds 10.
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
Checkbox¶
- class discord.ui.Checkbox(*, custom_id=..., default=False, id=None)¶
Represents a checkbox component within a modal.
バージョン 2.7 で追加.
- パラメータ
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
- property type¶
このコンポーネントの種類。
CheckboxGroup¶
- defadd_option
- defappend_option
- class discord.ui.CheckboxGroup(*, custom_id=..., required=True, min_values=None, max_values=None, options=..., id=None)¶
Represents a checkbox group component within a modal.
バージョン 2.7 で追加.
- パラメータ
id (Optional[
int]) -- The ID of the component. This must be unique across the view.custom_id (Optional[
str]) -- The custom ID of the component.options (List[
discord.CheckboxGroupOption]) -- A list of options that can be selected in this checkbox group. Can only contain up to 10 items.max_values (Optional[
int]) -- The maximum number of options that can be selected in this component. Must be between 1 and 10. Defaults to 1.min_values (Optional[
int]) -- The minimum number of options that must be selected in this component. Must be between 0 and 10. Defaults to 0.required (
bool) -- Whether this component is required to be filled before submitting the modal. Defaults toTrue.
- property type¶
このコンポーネントの種類。
- property options¶
このメニューで選択できるオプションのリスト。
- 型
- property min_values¶
The minimum number of options that must be selected before submitting the modal.
- 型
- property max_values¶
The maximum number of options that can be selected before submitting the modal.
- 型
- add_option(*, label, value=..., description=None, default=False)¶
Adds an option to the checkbox group.
To append a pre-existing
discord.CheckboxGroupOptionuse theappend_option()method instead.- パラメータ
- 例外
ValueError -- The number of options exceeds 10.
- append_option(option)¶
Appends an option to the checkbox group.
- パラメータ
option (
discord.CheckboxGroupOption) -- The option to append to the checkbox group.- 例外
ValueError -- The number of options exceeds 10.
- property parent¶
This item's parent, if applicable. Only available on items with children.
バージョン 2.6 で追加.
- 型
Optional[
Item]
- property view¶
この項目が属するビュー。
- 型
Optional[Union[
View,LayoutView]]
アプリケーションコマンド¶
ライブラリにはアプリケーションコマンドの作成を支援するヘルパーがあります。これらはすべて discord.app_commands パッケージにあります。
CommandTree¶
- defadd_command
- defclear_commands
- @command
- @context_menu
- defcopy_global_to
- @error
- asyncfetch_command
- asyncfetch_commands
- defget_command
- defget_commands
- asyncinteraction_check
- asyncon_error
- defremove_command
- asyncset_translator
- asyncsync
- defwalk_commands
- class discord.app_commands.CommandTree(client, *, fallback_to_global=True, allowed_contexts=..., allowed_installs=...)¶
アプリケーションコマンド情報を持つコンテナ。
- パラメータ
client (
Client) -- アプリケーションコマンドの情報を取得するためのクライアントインスタンス。fallback_to_global (
bool) -- ギルド固有のコマンドが呼び出されたときに見つからない場合は、ツリー内のグローバルコマンドを呼び出します。 例えば、ローカル環境でグローバル名前空間の下に/pingコマンドがあるが、ギルド本体ではギルド固有の/pingがある場合、ギルド固有の/pingコマンドを見つけるのに失敗せずに、グローバルの/pingコマンドをフォールバックとして使用します。 これはCommandSignatureMismatchエラーを通常より多く引き起こす可能性があります。デフォルトはTrueです。allowed_contexts (
AppCommandContext) --The default allowed contexts that applies to all commands in this tree. Note that you can override this on a per command basis.
バージョン 2.4 で追加.
allowed_installs (
AppInstallationType) --The default allowed install locations that apply to all commands in this tree. Note that you can override this on a per command basis.
バージョン 2.4 で追加.
- @command(*, name=..., description=..., nsfw=False, guild=..., guilds=..., auto_locale_strings=True, extras=...)¶
通常の関数からアプリケーションコマンドをこのツリーの下に直接作成するデコレータ。
- パラメータ
name (Union[
str,locale_str]) -- アプリケーションコマンドの名前。指定しない場合は、コールバック名を小文字化したものになります。description (Union[
str,locale_str]) -- アプリケーションコマンドの説明。これは、アプリケーションコマンドを説明するためにUIに表示されます。 指定されていない場合は、コールバックの docstring の最初の行を 100 文字以内に短縮したものが使用されます。nsfw (
bool) -- コマンドに年齢制限をかけて、年齢制限つきチャンネルでのみ利用できるようにすべきか。デフォルトではFalseです。Discordの制限により、サブコマンドでは利用できません。guild (Optional[
Snowflake]) --コマンドを追加するギルド。指定されていない場合や
Noneの場合これはグローバルコマンドになります。注釈
Due to a Discord limitation, this keyword argument cannot be used in conjunction with contexts (e.g.
app_commands.allowed_contexts()) or installation types (e.g.app_commands.allowed_installs()).guilds (List[
Snowflake]) --コマンドを追加するギルドのリスト。
guildパラメータと併用できません。指定されていない場合これは代わりにグローバルコマンドになります。注釈
Due to a Discord limitation, this keyword argument cannot be used in conjunction with contexts (e.g.
app_commands.allowed_contexts()) or installation types (e.g.app_commands.allowed_installs()).auto_locale_strings (
bool) -- これがTrueに設定されている場合、すべての翻訳可能な文字列がstrでなく:class:locale_str にラップされます。これを用いると、デフォルトのコマンド名、コマンド説明、パラメータ名などを繰り返し記述するのを避け、より使いやすくなるかもしれません。デフォルトはTrueです。extras (
dict) -- 追加のデータを保管できる辞書型。ライブラリは辞書型の中のキーや値を一切操作しません。
通常の関数からアプリケーションコマンドコンテキストメニューをこのツリーの下に直接作成するデコレータ。
関数は第一パラメータとして
Interactionを取り、第二パラメータとしてMember、User、Message、またはMemberとUserのtyping.Unionを取らないといけません。サンプル
@app_commands.context_menu() async def react(interaction: discord.Interaction, message: discord.Message): await interaction.response.send_message('Very cool message!', ephemeral=True) @app_commands.context_menu() async def ban(interaction: discord.Interaction, user: discord.Member): await interaction.response.send_message(f'Should I actually ban {user}...', ephemeral=True)
- パラメータ
name (Union[
str,locale_str]) -- コンテキストメニューコマンドの名前。指定しない場合はデフォルトでコールバック名をタイトルケース化したものになります。 通常のスラッシュコマンドとは異なり、名前にスペースと大文字を含めることができます。nsfw (
bool) -- コマンドに年齢制限をかけて、年齢制限つきチャンネルでのみ利用できるようにすべきか。デフォルトではFalseです。Discordの制限により、サブコマンドでは利用できません。guild (Optional[
Snowflake]) --コマンドを追加するギルド。指定されていない場合や
Noneの場合これはグローバルコマンドになります。注釈
Due to a Discord limitation, this keyword argument cannot be used in conjunction with contexts (e.g.
app_commands.allowed_contexts()) or installation types (e.g.app_commands.allowed_installs()).guilds (List[
Snowflake]) --コマンドを追加するギルドのリスト。
guildパラメータと併用できません。指定されていない場合これは代わりにグローバルコマンドになります。注釈
Due to a Discord limitation, this keyword argument cannot be used in conjunction with contexts (e.g.
app_commands.allowed_contexts()) or installation types (e.g.app_commands.allowed_installs()).auto_locale_strings (
bool) -- これがTrueに設定されている場合、すべての翻訳可能な文字列がstrでなく:class:locale_str にラップされます。これを用いると、デフォルトのコマンド名、コマンド説明、パラメータ名などを繰り返し記述するのを避け、より使いやすくなるかもしれません。デフォルトはTrueです。extras (
dict) -- 追加のデータを保管できる辞書型。ライブラリは辞書型の中のキーや値を一切操作しません。
- @error(coro)¶
コルーチンをローカルエラーハンドラとして登録するデコレータ。
on_error()コールバックのシグネチャと一致する必要があります。渡されたエラーは
AppCommandErrorを継承しています。
- await fetch_command(command_id, /, *, guild=None)¶
This function is a coroutine.
アプリケーションからアプリケーションコマンドを取得します。
- パラメータ
- 例外
HTTPException -- コマンドの取得に失敗した場合。
MissingApplicationID -- アプリケーションコマンドが見つからなかった場合。
NotFound -- アプリケーションコマンドが見つからなかった場合。 これは、コマンドがギルドコマンドであるのにギルドが指定されていない場合またはその逆を含みます。
- 戻り値
アプリケーションコマンド。
- 戻り値の型
- await fetch_commands(*, guild=None)¶
This function is a coroutine.
アプリケーションの現在のコマンドを取得します。
ギルドが渡されない場合、グローバルコマンドが取得されます。そうでなければ、代わりにギルドのコマンドが取得されます。
注釈
これにはコンテキストメニューコマンドが含まれます。
- パラメータ
guild (Optional[
Snowflake]) -- コマンドを取得するギルド。渡されない場合は、代わりにグローバルコマンドが取得されます。- 例外
HTTPException -- コマンドの取得に失敗した場合。
MissingApplicationID -- アプリケーションコマンドが見つからなかった場合。
- 戻り値
アプリケーションコマンド。
- 戻り値の型
List[
AppCommand]
- copy_global_to(*, guild)¶
指定したギルドにグローバルコマンドをすべてコピーします。
これは、グローバルコマンドをテスト用のギルドにコピーできるので、主に開発のために提供されています。
このメソッドは競合する既存のギルドコマンドを 上書き することに注意してください。
- パラメータ
guild (
Snowflake) -- コマンドをコピーするギルド。- 例外
CommandLimitReached -- The maximum number of commands was reached for that guild. This is currently 100 for slash commands and 15 for context menu commands.
- add_command(command, /, *, guild=..., guilds=..., override=False)¶
ツリーにアプリケーションコマンドを追加します。
これはコマンドをローカルに追加するだけです -- コマンドを同期してクライアントで有効にするには、
sync()を呼び出す必要があります。渡された種類に関係なく、コマンドの親も追加されます。
- パラメータ
guild (Optional[
Snowflake]) --コマンドを追加するギルド。指定されていない場合や
Noneの場合これはグローバルコマンドになります。注釈
Due to a Discord limitation, this keyword argument cannot be used in conjunction with contexts (e.g.
app_commands.allowed_contexts()) or installation types (e.g.app_commands.allowed_installs()).guilds (List[
Snowflake]) --コマンドを追加するギルドのリスト。
guildパラメータと併用できません。指定されていない場合これは代わりにグローバルコマンドになります。注釈
Due to a Discord limitation, this keyword argument cannot be used in conjunction with contexts (e.g.
app_commands.allowed_contexts()) or installation types (e.g.app_commands.allowed_installs()).override (
bool) -- 同じ名前のコマンドを上書きするかどうか。Falseの場合例外が発生します。デフォルトはFalseです。
- 例外
CommandAlreadyRegistered -- コマンドが既に登録されていて、上書きすると指定されていない場合。
TypeError -- 渡されたアプリケーションコマンドが有効でない場合、または
guildとguildsの両方が与えられた場合。CommandLimitReached -- The maximum number of commands was reached globally or for that guild. This is currently 100 for slash commands and 15 for context menu commands.
- remove_command(command, /, *, guild=None, type=<AppCommandType.chat_input: 1>)¶
ツリーからアプリケーションコマンドを除去します。
これはコマンドをローカルで除去するだけです -- コマンドを同期してクライアントで除去するには、
sync()を呼び出す必要があります。- パラメータ
command (
str) -- 除去するルートコマンドの名前。guild (Optional[
Snowflake]) -- コマンドを除去するギルド。指定されていない場合やNoneの場合グローバルコマンドを除去します。type (
AppCommandType) -- 除去するコマンドの種類。デフォルトはchat_input、すなわちスラッシュコマンドです。
- 戻り値
除去されたアプリケーションコマンド。何も除去されなかった場合は
Noneが返ります。- 戻り値の型
Optional[Union[
Command,ContextMenu,Group]]
- clear_commands(*, guild, type=None)¶
ツリーからアプリケーションコマンドをすべて除去します。
これはコマンドをローカルで除去するだけです -- コマンドを同期してクライアントで除去するには、
sync()を呼び出す必要があります。- パラメータ
guild (Optional[
Snowflake]) -- コマンドを除去するギルド。指定されていない場合やNoneの場合グローバルコマンドを除去します。type (
AppCommandType) -- 除去するコマンドの種類。指定されていない場合やNoneの場合種類にかかわらず除去します。
- get_command(command, /, *, guild=None, type=<AppCommandType.chat_input: 1>)¶
ツリーからアプリケーションコマンドを取得します。
- パラメータ
command (
str) -- 取得するルートコマンドの名前。guild (Optional[
Snowflake]) -- コマンドを取得するギルド。指定されていない場合やNoneの場合グローバルコマンドを取得します。type (
AppCommandType) -- 取得するコマンドの種類。デフォルトはchat_input、すなわちスラッシュコマンドです。
- 戻り値
見つかったアプリケーションコマンド。存在しない場合は
Noneが返ります。- 戻り値の型
Optional[Union[
Command,ContextMenu,Group]]
- get_commands(*, guild=None, type=None)¶
ツリーからアプリケーションコマンドをすべて取得します。
- パラメータ
guild (Optional[
Snowflake]) -- グローバルコマンドを含まないコマンドを取得するギルド。指定されていない場合やNoneの場合はグローバルコマンドが返ります。type (Optional[
AppCommandType]) -- 取得するコマンドの種類。指定されていない場合やNoneの場合はすべてのコマンドが返されます。
- 戻り値
ツリーのアプリケーションコマンド。
- 戻り値の型
List[Union[
ContextMenu,Command,Group]]
- for ... in walk_commands(*, guild=None, type=<AppCommandType.chat_input: 1>)¶
ツリーのすべてのアプリケーションコマンドと子コマンドを再帰的に網羅するイテレータ。
- パラメータ
guild (Optional[
Snowflake]) -- グローバルコマンドを含まないコマンドをイテレートするギルド。指定されていない場合やNoneの場合はグローバルコマンドがイテレートされます。type (
AppCommandType) -- イテレートするコマンドの種類。デフォルトはchat_input、すなわちスラッシュコマンドです。
- 列挙
Union[
ContextMenu,Command,Group] -- ツリーのアプリケーションコマンド。
- await on_error(interaction, error, /)¶
This function is a coroutine.
どれかのコマンドが
AppCommandErrorを送出したときに呼び出されるコールバック。デフォルトの実装ではコマンドにエラーハンドラーが付属したいない場合のみ例外をライブラリロガーを用いて記録します。
失敗したコマンドを取得するには、
discord.Interaction.commandを使用してください。- パラメータ
interaction (
Interaction) -- 処理中のインタラクション。error (
AppCommandError) -- 発生した例外。
- property translator¶
存在する場合、コマンドの翻訳を担当するトランスレータ。
トランスレータを変更するには、
set_translator()を使用してください。- 型
Optional[
Translator]
- await set_translator(translator)¶
This function is a coroutine.
コマンドの翻訳に使用するトランスレータを設定します。
以前にトランスレータが設定されていた場合は、
Translator.unload()メソッドを使用してアンロードされます。トランスレータが設定されると、
Translator.load()メソッドを使用して読み込まれます。- パラメータ
translator (Optional[
Translator]) -- 使用するトランスレータ。Noneの場合、トランスレータは単に除去され、アンロードされます。- 例外
TypeError -- トランスレータが
NoneまたはTranslatorインスタンスでない場合。
- await sync(*, guild=None)¶
This function is a coroutine.
アプリケーションコマンドをDiscordに同期します。
また、これは、トランスレータを実行し、Discordに提供する翻訳された文字列を取得します。
アプリケーションコマンドを表示するためには、これを呼び出さないといけません。
- パラメータ
guild (Optional[
Snowflake]) -- コマンドを同期するギルド。指定されていない場合やNoneの場合グローバルコマンドを同期します。- 例外
HTTPException -- コマンドの同期に失敗した場合。
CommandSyncFailure -- コマンドに不正なデータがあるなど、ユーザーによる誤りのためコマンドの同期が失敗した場合。これはHTTPステータスコード 400に相当します。
Forbidden -- クライアントがギルドで
applications.commandsスコープを有さない場合。MissingApplicationID -- クライアントにアプリケーションIDがない場合。
TranslationError -- コマンドの翻訳中にエラーが発生した場合。
- 戻り値
同期されたアプリケーションコマンド。
- 戻り値の型
List[
AppCommand]
- await interaction_check(interaction, /)¶
This function is a coroutine.
Interactionがツリーによって処理されるかどうかを判断するグローバルチェック。デフォルトの実装では、True が返されます (すべてのインタラクションが処理されます)が、カスタム動作が必要な場合は上書きできます。
コマンド¶
Command¶
- defadd_check
- @autocomplete
- @error
- defget_parameter
- defremove_check
- class discord.app_commands.Command(*, name, description, callback, nsfw=False, parent=None, guild_ids=None, allowed_contexts=None, allowed_installs=None, auto_locale_strings=True, extras=...)¶
アプリケーションコマンドを実装するクラス。
これは通常手動で作成されず、代わりに以下のデコレータを使用して作成されます。
バージョン 2.0 で追加.
- パラメータ
name (Union[
str,locale_str]) -- アプリケーションコマンドの名前。description (Union[
str,locale_str]) -- アプリケーションコマンドの説明。これは、アプリケーションコマンドを説明するためのUIに表示されます。callback (coroutine) -- コマンドが呼び出されたときに実行されるコルーチン。
auto_locale_strings (
bool) -- これがTrueに設定されている場合、すべての翻訳可能な文字列がstrでなく:class:locale_str にラップされます。これを用いると、デフォルトのコマンド名、コマンド説明、パラメータ名などを繰り返し記述するのを避け、より使いやすくなるかもしれません。デフォルトはTrueです。nsfw (
bool) -- コマンドに年齢制限をかけて、年齢制限つきチャンネルでのみ利用できるようにすべきか。デフォルトではFalseです。Discordの制限により、サブコマンドでは利用できません。parent (Optional[
Group]) -- 親アプリケーションコマンド。存在しない場合はNone。extras (
dict) -- 追加のデータを保管できる辞書型。ライブラリは辞書型の中のキーや値を一切操作しません。
- checks¶
コマンドコールバックが実行されるべきかを示す
Interactionパラメータを取るチェック関数の一覧。もし失敗を示すために例外を送出しないといけない場合は、AppCommandErrorを継承するものを使用すべきです。もしすべてのチェックが例外を送出せずに失敗した場合はCheckFailureが発生します。
- default_permissions¶
Discordでこのコマンドを実行できるデフォルトの権限。サーバー管理者はクライアントでこの値を上書きすることができます。 空の権限フィールドを設定すると、サーバー管理者以外はギルド内でそのコマンドを使用できなくなります。
Discord側の制限のため、サブコマンドでは動作しません。
- 型
Optional[
Permissions]
- allowed_contexts¶
The contexts that the command is allowed to be used in. Overrides
guild_onlyif this is set.バージョン 2.4 で追加.
- 型
Optional[
AppCommandContext]
- allowed_installs¶
The installation contexts that the command is allowed to be installed on.
バージョン 2.4 で追加.
- 型
Optional[
AppInstallationType]
- @autocomplete(name)¶
パラメータのオートコンプリートに使用されるコルーチンを登録するデコレータ。
コルーチンのコールバックは、
Interactionとユーザーが現在入力している値 (入力された文字列) の 2 つのパラメータを受け取らないといけません。入力される可能性のある他のパラメータの値を取得するには、
Interaction.namespaceにアクセスして、これらの値を持つNamespaceオブジェクトを取得できます。親の
チェックはオートコンプリート内で無視されます。 ただし、チェックはautocomplete コールバックに追加することができ、追加したものが呼び出されます。 何らかの理由でチェックに失敗した場合、インタラクションの応答として空のリストが送信されます。コルーチンのデコレータは
Choiceオブジェクトのリストを 返さないといけません 。オブジェクトは25個まで返すことができます。警告
このコルーチンから返される選択肢はあくまで提案であって、ユーザーはそれらを無視して自分の値を入力することができます。
例:
@app_commands.command() async def fruits(interaction: discord.Interaction, fruit: str): await interaction.response.send_message(f'Your favourite fruit seems to be {fruit}') @fruits.autocomplete('fruit') async def fruits_autocomplete( interaction: discord.Interaction, current: str, ) -> List[app_commands.Choice[str]]: fruits = ['Banana', 'Pineapple', 'Apple', 'Watermelon', 'Melon', 'Cherry'] return [ app_commands.Choice(name=fruit, value=fruit) for fruit in fruits if current.lower() in fruit.lower() ]
- @error(coro)¶
コルーチンをローカルエラーハンドラとして登録するデコレータ。
ローカルのエラーハンドラは、コマンドの本体やコマンドの処理中に例外が発生するたびに呼び出されます。 エラーハンドラは、インタラクションとエラーの2つのパラメータを取らないといけません。
渡されたエラーは
AppCommandErrorを継承しています。
- property parameters¶
このコマンドのパラメータのリストを返します。
これには
selfとinteractionパラメータは含まれていません。- 戻り値
このコマンドのパラメータ。
- 戻り値の型
List[
Parameter]
- get_parameter(name)¶
名前からパラメータを取得します。
名前は Discordで表示される改名後のものではなく、Pythonの識別子でないといけません。
- property qualified_name¶
完全修飾されたコマンド名を返します。
修飾名には親の名前も含まれています。例えば、
/foo barのようなコマンドでは修飾名はfoo barです。- 型
- add_check(func, /)¶
コマンドにチェックを追加します。
これは
check()に対する非デコレーターインターフェイスです。- パラメータ
func -- チェックとして使用される関数。
- remove_check(func, /)¶
コマンドからチェックを除去します。
この関数は冪等性を保持しており、関数がコマンドのチェックに含まれていない場合でも例外が発生しません。
- パラメータ
func -- チェックから除去する関数。
Parameter¶
- class discord.app_commands.Parameter¶
Commandコールバックのパラメータ情報を含むクラス。バージョン 2.0 で追加.
- locale_name¶
利用可能な場合、表示名のローカライズ可能な文字列。
- 型
Optional[
locale_str]
- locale_description¶
利用可能な場合、説明のローカライズ可能な文字列。
- 型
Optional[
locale_str]
- type¶
このパラメータの種類。
- channel_types¶
このパラメータにて利用できるチャンネルの種類。
- 型
List[
ChannelType]
Group¶
- defadd_command
- @command
- @error
- defget_command
- asyncinteraction_check
- asyncon_error
- defremove_command
- defwalk_commands
- class discord.app_commands.Group(*, name=..., description=..., parent=None, guild_ids=None, guild_only=..., allowed_contexts=..., allowed_installs=..., nsfw=..., auto_locale_strings=True, default_permissions=..., extras=...)¶
アプリケーションコマンドグループを実装するクラス。
これらは通常、手動で作成するのではなく継承されます。
guild_only()、guilds()、default_permissions()などのデコレータは、サブクラスの上に置かれている場合、グループに適用されます。例えば:from discord import app_commands @app_commands.guild_only() class MyGroup(app_commands.Group): pass
バージョン 2.0 で追加.
- パラメータ
name (Union[
str,locale_str]) -- グループ名。指定しない場合は、デフォルトでは小文字のケバブケース化したクラス名です。description (Union[
str,locale_str]) -- グループの説明。これは、グループを説明するためにUIに表示されます。 指定されていない場合は、クラスの docstring を 100 文字以内に短縮したものが使用されます。auto_locale_strings (
bool) -- これがTrueに設定されている場合、すべての翻訳可能な文字列がstrでなく:class:locale_str にラップされます。これを用いると、デフォルトのコマンド名、コマンド説明、パラメータ名などを繰り返し記述するのを避け、より使いやすくなるかもしれません。デフォルトはTrueです。default_permissions (Optional[
Permissions]) -- Discordでこのグループを実行できるデフォルトの権限。サーバー管理者はクライアントでこの値を上書きすることができます。 空の権限フィールドを設定すると、サーバー管理者以外はギルド内でそのコマンドを使用できなくなります。Discordの制限により、サブコマンドでは利用できません。guild_only (
bool) -- グループをギルド内でのみ使用できるようにするかどうか。デフォルトはFalseです。Discordの制限により、サブコマンドでは利用できません。nsfw (
bool) -- コマンドに年齢制限をかけて、年齢制限つきチャンネルでのみ利用できるようにすべきか。デフォルトではFalseです。Discordの制限により、サブコマンドでは利用できません。parent (Optional[
Group]) -- 親アプリケーションコマンド。存在しない場合はNone。extras (
dict) -- 追加のデータを保管できる辞書型。ライブラリは辞書型の中のキーや値を一切操作しません。
- default_permissions¶
Discordでこのグループを実行できるデフォルトの権限。サーバー管理者はクライアントでこの値を上書きすることができます。 空の権限フィールドを設定すると、サーバー管理者以外はギルド内でそのコマンドを使用できなくなります。
Discord側の制限のため、サブコマンドでは動作しません。
- 型
Optional[
Permissions]
- allowed_contexts¶
The contexts that this group is allowed to be used in. Overrides guild_only if set.
バージョン 2.4 で追加.
- 型
Optional[
AppCommandContext]
- allowed_installs¶
The installation contexts that the command is allowed to be installed on.
バージョン 2.4 で追加.
- 型
Optional[
AppInstallationType]
- @command(*, name=..., description=..., nsfw=False, auto_locale_strings=True, extras=...)¶
通常の関数からアプリケーションコマンドをこのグループの下に作成するデコレータ。
- パラメータ
name (Union[
str,locale_str]) -- アプリケーションコマンドの名前。指定しない場合は、コールバック名を小文字化したものになります。description (Union[
str,locale_str]) -- アプリケーションコマンドの説明。これは、アプリケーションコマンドを説明するためにUIに表示されます。 指定されていない場合は、コールバックの docstring の最初の行を 100 文字以内に短縮したものが使用されます。nsfw (
bool) -- コマンドに年齢制限をかけて、年齢制限つきチャンネルでのみ利用できるようにすべきか。auto_locale_strings (
bool) -- これがTrueに設定されている場合、すべての翻訳可能な文字列がstrでなく:class:locale_str にラップされます。これを用いると、デフォルトのコマンド名、コマンド説明、パラメータ名などを繰り返し記述するのを避け、より使いやすくなるかもしれません。デフォルトはTrueです。extras (
dict) -- 追加のデータを保管できる辞書型。ライブラリは辞書型の中のキーや値を一切操作しません。
- @error(coro)¶
コルーチンをローカルエラーハンドラとして登録するデコレータ。
ローカルのエラーハンドラは、子コマンドで例外が発生するたびに呼び出されます。 エラーハンドラは、インタラクションとエラーの2つのパラメータを取らないといけません。
渡されたエラーは
AppCommandErrorを継承しています。
- property qualified_name¶
完全修飾されたグループ名を返します。
修飾名には親の名前も含まれています。例えば、
/foo barのようなグループでは修飾名はfoo barです。- 型
- await on_error(interaction, error, /)¶
This function is a coroutine.
子コマンドが
AppCommandErrorを送出したときに呼び出されるコールバック。失敗したコマンドを取得するには、
discord.Interaction.commandを使用してください。デフォルトの実装では何もしません。
- パラメータ
interaction (
Interaction) -- 処理中のインタラクション。error (
AppCommandError) -- 発生した例外。
- await interaction_check(interaction, /)¶
This function is a coroutine.
グループ内でインタラクションが発生したときに、グループ内のコマンドを実行すべきかを確認するコールバック。
これは、インタラクションが特定のユーザーからかを確かめたい場合などに上書きすると便利です。
デフォルトの実装は
Trueを返します。注釈
この中で例外が発生した場合チェックが失敗したとみなされ
on_error()のようなエラーハンドラが呼び出されます。詳細はAppCommandErrorを参照してください。- パラメータ
interaction (
Interaction) -- 発生したインタラクション。- 戻り値
ビューの子のコールバックを呼び出すべきか。
- 戻り値の型
- add_command(command, /, *, override=False)¶
このグループの内部コマンドリストにコマンドまたはグループを追加します。
- パラメータ
- 例外
CommandAlreadyRegistered -- コマンドやグループがすでに登録されている場合。なお、この場合
CommandAlreadyRegistered.guild_idは常にNoneになります。ValueError -- 登録されたコマンド数が多すぎるか、グループが深くネストされすぎている場合。
TypeError -- 間違った種類のコマンドが渡された場合。
- remove_command(name, /)¶
内部のコマンドリストから該当するコマンドまたはグループを検索し、それを除去します。
デコレータ¶
- @discord.app_commands.command(*, name=..., description=..., nsfw=False, auto_locale_strings=True, extras=...)¶
通常の関数からアプリケーションコマンドを作成します。
- パラメータ
name (
str) -- アプリケーションコマンドの名前。指定しない場合は、コールバック名を小文字化したものになります。description (
str) -- アプリケーションコマンドの説明。これは、アプリケーションコマンドを説明するためにUIに表示されます。 指定されていない場合は、コールバックの docstring の最初の行を 100 文字以内に短縮したものが使用されます。nsfw (
bool) -- コマンドに年齢制限をかけて、年齢制限つきチャンネルでのみ利用できるようにすべきか。デフォルトではFalseです。Discordの制限により、サブコマンドでは利用できません。auto_locale_strings (
bool) -- これがTrueに設定されている場合、すべての翻訳可能な文字列がstrでなく:class:locale_str にラップされます。これを用いると、デフォルトのコマンド名、コマンド説明、パラメータ名などを繰り返し記述するのを避け、より使いやすくなるかもしれません。デフォルトはTrueです。extras (
dict) -- 追加のデータを保管できる辞書型。ライブラリは辞書型の中のキーや値を一切操作しません。
通常の関数からアプリケーションコマンドコンテキストメニューを作成します。
関数は第一パラメータとして
Interactionを取り、第二パラメータとしてMember、User、Message、またはMemberとUserのtyping.Unionを取らないといけません。サンプル
@app_commands.context_menu() async def react(interaction: discord.Interaction, message: discord.Message): await interaction.response.send_message('Very cool message!', ephemeral=True) @app_commands.context_menu() async def ban(interaction: discord.Interaction, user: discord.Member): await interaction.response.send_message(f'Should I actually ban {user}...', ephemeral=True)
- パラメータ
name (Union[
str,locale_str]) -- コンテキストメニューコマンドの名前。指定しない場合はデフォルトでコールバック名をタイトルケース化したものになります。 通常のスラッシュコマンドとは異なり、名前にスペースと大文字を含めることができます。nsfw (
bool) -- コマンドに年齢制限をかけて、年齢制限つきチャンネルでのみ利用できるようにすべきか。デフォルトではFalseです。Discordの制限により、サブコマンドでは利用できません。auto_locale_strings (
bool) -- これがTrueに設定されている場合、すべての翻訳可能な文字列がstrでなく:class:locale_str にラップされます。これを用いると、デフォルトのコマンド名、コマンド説明、パラメータ名などを繰り返し記述するのを避け、より使いやすくなるかもしれません。デフォルトはTrueです。extras (
dict) -- 追加のデータを保管できる辞書型。ライブラリは辞書型の中のキーや値を一切操作しません。
- @discord.app_commands.describe(**parameters)¶
キーワード引数のキーを名前として使用して与えられたパラメータを説明します。
例:
@app_commands.command(description='Bans a member') @app_commands.describe(member='the member to ban') async def ban(interaction: discord.Interaction, member: discord.Member): await interaction.response.send_message(f'Banned {member}')
または、Google、Sphinx、Numpy スタイルのドキュメント文字列を使用してパラメータを記述することもできます。
例:
@app_commands.command() async def ban(interaction: discord.Interaction, member: discord.Member): """Bans a member Parameters ----------- member: discord.Member the member to ban """ await interaction.response.send_message(f'Banned {member}')
- パラメータ
**parameters (Union[
str,locale_str]) -- パラメータの説明。- 例外
TypeError -- パラメータ名が見つからない場合。
- @discord.app_commands.rename(**parameters)¶
キーワード引数のキーを名前として使用して与えられたパラメータを改名します。
これはDiscord UI内のパラメータの名前を変更します。 他のデコレータでパラメータを参照する場合、改名先のものではなく関数内で使用されるパラメータ名を使用しないといけません。
例:
@app_commands.command() @app_commands.rename(the_member_to_ban='member') async def ban(interaction: discord.Interaction, the_member_to_ban: discord.Member): await interaction.response.send_message(f'Banned {the_member_to_ban}')
- パラメータ
**parameters (Union[
str,locale_str]) -- パラメータの名前。- 例外
ValueError -- パラメータ名がすでに他のパラメータによって使用されている場合。
TypeError -- パラメータ名が見つからない場合。
- @discord.app_commands.choices(**parameters)¶
与えられたパラメータに、与えられた選択肢を使用するように名前で指示します。
例:
@app_commands.command() @app_commands.describe(fruits='fruits to choose from') @app_commands.choices(fruits=[ Choice(name='apple', value=1), Choice(name='banana', value=2), Choice(name='cherry', value=3), ]) async def fruit(interaction: discord.Interaction, fruits: Choice[int]): await interaction.response.send_message(f'Your favourite fruit is {fruits.name}.')
注釈
これはコマンドに選択肢を提供する唯一の方法ではありません。より使いやすい方法が2つあります。 一つ目は、
typing.Literalアノテーションです。@app_commands.command() @app_commands.describe(fruits='fruits to choose from') async def fruit(interaction: discord.Interaction, fruits: Literal['apple', 'banana', 'cherry']): await interaction.response.send_message(f'Your favourite fruit is {fruits}.')
二つ目の方法は、
enum.Enumを使用することです。class Fruits(enum.Enum): apple = 1 banana = 2 cherry = 3 @app_commands.command() @app_commands.describe(fruits='fruits to choose from') async def fruit(interaction: discord.Interaction, fruits: Fruits): await interaction.response.send_message(f'Your favourite fruit is {fruits}.')
- パラメータ
**parameters -- パラメータの選択肢。
- 例外
TypeError -- パラメータ名が見つからないか、パラメータの型が正しくない場合。
- @discord.app_commands.autocomplete(**parameters)¶
与えられたパラメータと与えられたオートコンプリートコールバックを関連付けます。
オートコンプリートは、
str、int、またはfloatの値を持つ型でのみサポートされています。チェックはサポートされていますが、動作するためにはオートコンプリートコールバックに付属させる必要があります。 オートコンプリートコールバックを呼び出すと、コマンドに付属したチェックは無視されます。詳細については、
Command.autocomplete()ドキュメントを参照してください。警告
このコルーチンから返される選択肢はあくまで提案であって、ユーザーはそれらを無視して自分の値を入力することができます。
例:
async def fruit_autocomplete( interaction: discord.Interaction, current: str, ) -> List[app_commands.Choice[str]]: fruits = ['Banana', 'Pineapple', 'Apple', 'Watermelon', 'Melon', 'Cherry'] return [ app_commands.Choice(name=fruit, value=fruit) for fruit in fruits if current.lower() in fruit.lower() ] @app_commands.command() @app_commands.autocomplete(fruit=fruit_autocomplete) async def fruits(interaction: discord.Interaction, fruit: str): await interaction.response.send_message(f'Your favourite fruit seems to be {fruit}')
- パラメータ
**parameters -- オートコンプリートに登録するパラメータ。
- 例外
TypeError -- パラメータ名が見つからないか、パラメータの型が正しくない場合。
- @discord.app_commands.guilds(*guild_ids)¶
与えられたギルドをコマンドに関連付けます。
CommandTreeにコマンドインスタンスが追加されたとき、 コマンドはデフォルトでグローバルコマンドではなく、このデコレータで指定されたギルドのコマンドとなります。If no arguments are given, then the command will not be synced anywhere. This may be modified later using the
CommandTree.add_command()method.注釈
実装上の都合とPythonの制限のため、これを
CommandTree.command()やCommandTree.context_menu()デコレータと同時に使用する場合はこれはそのデコレータの下に置かないといけません。注釈
Due to a Discord limitation, this decorator cannot be used in conjunction with contexts (e.g.
app_commands.allowed_contexts()) or installation types (e.g.app_commands.allowed_installs()).例:
MY_GUILD_ID = discord.Object(...) # Guild ID here @app_commands.command() @app_commands.guilds(MY_GUILD_ID) async def bonk(interaction: discord.Interaction): await interaction.response.send_message('Bonk', ephemeral=True)
- @discord.app_commands.guild_only(func=None)¶
コマンドがギルド内でのみ利用できることを示すデコレータ。
これは
check()として実装されて おらず 、代わりにDiscordサーバー側で検証されます。 そのため、プライベートメッセージ内でコマンドが使用されたときに呼び出されるエラーハンドラはありません。このデコレータは括弧の有無にかかわらず呼び出すことができます。
Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
サンプル
@app_commands.command() @app_commands.guild_only() async def my_guild_only_command(interaction: discord.Interaction) -> None: await interaction.response.send_message('I am only available in guilds!')
- @discord.app_commands.dm_only(func=None)¶
A decorator that indicates this command can only be used in the context of bot DMs.
This is not implemented as a
check(), and is instead verified by Discord server side. Therefore, there is no error handler called when a command is used within a guild or group DM.このデコレータは括弧の有無にかかわらず呼び出すことができます。
Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
サンプル
@app_commands.command() @app_commands.dm_only() async def my_dm_only_command(interaction: discord.Interaction) -> None: await interaction.response.send_message('I am only available in DMs!')
- @discord.app_commands.private_channel_only(func=None)¶
A decorator that indicates this command can only be used in the context of DMs and group DMs.
This is not implemented as a
check(), and is instead verified by Discord server side. Therefore, there is no error handler called when a command is used within a guild.このデコレータは括弧の有無にかかわらず呼び出すことができます。
Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
バージョン 2.4 で追加.
サンプル
@app_commands.command() @app_commands.private_channel_only() async def my_private_channel_only_command(interaction: discord.Interaction) -> None: await interaction.response.send_message('I am only available in DMs and GDMs!')
- @discord.app_commands.allowed_contexts(guilds=..., dms=..., private_channels=...)¶
A decorator that indicates this command can only be used in certain contexts. Valid contexts are guilds, DMs and private channels.
This is not implemented as a
check(), and is instead verified by Discord server side.Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
バージョン 2.4 で追加.
サンプル
@app_commands.command() @app_commands.allowed_contexts(guilds=True, dms=False, private_channels=True) async def my_command(interaction: discord.Interaction) -> None: await interaction.response.send_message('I am only available in guilds and private channels!')
- @discord.app_commands.user_install(func=None)¶
A decorator that indicates this command should be installed for users.
This is not implemented as a
check(), and is instead verified by Discord server side.Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
バージョン 2.4 で追加.
サンプル
@app_commands.command() @app_commands.user_install() async def my_user_install_command(interaction: discord.Interaction) -> None: await interaction.response.send_message('I am installed in users by default!')
- @discord.app_commands.guild_install(func=None)¶
A decorator that indicates this command should be installed in guilds.
This is not implemented as a
check(), and is instead verified by Discord server side.Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
バージョン 2.4 で追加.
サンプル
@app_commands.command() @app_commands.guild_install() async def my_guild_install_command(interaction: discord.Interaction) -> None: await interaction.response.send_message('I am installed in guilds by default!')
- @discord.app_commands.allowed_installs(guilds=..., users=...)¶
A decorator that indicates this command should be installed in certain contexts. Valid contexts are guilds and users.
This is not implemented as a
check(), and is instead verified by Discord server side.Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
バージョン 2.4 で追加.
サンプル
@app_commands.command() @app_commands.allowed_installs(guilds=False, users=True) async def my_command(interaction: discord.Interaction) -> None: await interaction.response.send_message('I am installed in users by default!')
- @discord.app_commands.default_permissions(perms_obj=None, /, **perms)¶
このコマンドを実行するために必要なデフォルトの権限を設定するデコレータ。
このデコレータを使用すると、デフォルトではユーザーはコマンドを実行するためにこれらの権限を持っている必要があります。 ただし、管理者は公式クライアントを使用してこのコマンドを実行するために必要な権限を変更することができます。したがって、これはヒントとしてのみ機能します。
引数なしで呼び出すなどして空の権限フィールドを設定した場合は、このコマンドはギルド内ではサーバー管理者以外使用できなくなります。
これはDiscordサーバー側に送信され、
check()ではないため、エラーハンドラは呼び出されません。Discordの制限のため、このデコレータはサブコマンドでは動作せず無視されます。
警告
これは ヒント として機能し、メンバーはこれらのコマンドを実際に実行するのに権限を持つ必要は ありません 。メンバーが必要な権限を有することを確かめたい場合は、代わりに
has_permissions()を使用してみてください。- パラメータ
**perms (
bool) -- デフォルトとして設定する権限を示すキーワード引数。perms_obj (
Permissions) --A permissions object as positional argument. This can be used in combination with
**perms.バージョン 2.5 で追加.
サンプル
@app_commands.command() @app_commands.default_permissions(manage_messages=True) async def test(interaction: discord.Interaction): await interaction.response.send_message('You may or may not have manage messages.')
ADMIN_PERMS = discord.Permissions(administrator=True) @app_commands.command() @app_commands.default_permissions(ADMIN_PERMS, manage_messages=True) async def test(interaction: discord.Interaction): await interaction.response.send_message('You may or may not have manage messages.')
チェック¶
- @discord.app_commands.check(predicate)¶
アプリケーションコマンドにチェックを追加するデコレータ。
これらのチェックは唯一の引数
Interactionを取る関数であるべきです。もしチェックがFalseのような値を返せば、呼び出し中にCheckFailureが発生され適切なエラーハンドラに送られます。これらのチェックはコルーチンであってもなくてもよいです。
サンプル
コマンドを呼び出したのがあなたであるかどうかを確認するための基本的なチェックの作成。
def check_if_it_is_me(interaction: discord.Interaction) -> bool: return interaction.user.id == 85309593344815104 @tree.command() @app_commands.check(check_if_it_is_me) async def only_for_me(interaction: discord.Interaction): await interaction.response.send_message('I know you!', ephemeral=True)
一般的なチェックを独自のデコレータに変換します:
def is_me(): def predicate(interaction: discord.Interaction) -> bool: return interaction.user.id == 85309593344815104 return app_commands.check(predicate) @tree.command() @is_me() async def only_me(interaction: discord.Interaction): await interaction.response.send_message('Only you!')
- パラメータ
predicate (Callable[[
Interaction],bool]) -- コマンドが呼び出されるかどうかをチェックする関数。
- @discord.app_commands.checks.has_role(item, /)¶
コマンドを呼び出したメンバーが、指定された名前またはIDのロールを持っているかどうかのチェックを追加する
check()。文字列が指定された場合は、大文字やつづりを含めロールの名前を正確に指定する必要があります。
整数が指定されている場合は、ロールの正確なsnowflake IDを指定する必要があります。
このチェックは2つの特別な例外のうち1つ、もしユーザがロールを持っていないなら
MissingRoleを、プライベートメッセージで使用されたならNoPrivateMessageを発生します。どちらもCheckFailureを継承します。バージョン 2.0 で追加.
注釈
これはDiscordがアプリケーションコマンドに提供する権限システムとは異なります。これはDiscord側で処理されるものではなく、完全にローカルのプログラム内で行われます。
- @discord.app_commands.checks.has_any_role(*items)¶
コマンドを呼び出したメンバーが、指定された名前またはIDのロールのうちの どれか を持っているかをチェックを追加する
check()。 これは、指定された3つのうちのどのロールが指定されていても、このチェックがTrueを返すことを意味します。has_role()と同様に、渡された名前やIDは正確でなければなりません。このチェックは2つの特別な例外のうち1つ、もしユーザがロールをすべて持っていないなら
MissingAnyRoleを、プライベートメッセージで使用されたならNoPrivateMessageを発生します。どちらもCheckFailureを継承します。バージョン 2.0 で追加.
注釈
これはDiscordがアプリケーションコマンドに提供する権限システムとは異なります。これはDiscord側で処理されるものではなく、完全にローカルのプログラム内で行われます。
サンプル
@tree.command() @app_commands.checks.has_any_role('Library Devs', 'Moderators', 492212595072434186) async def cool(interaction: discord.Interaction): await interaction.response.send_message('You are cool indeed')
- @discord.app_commands.checks.has_permissions(**perms)¶
メンバーが必要なすべての権限を持っているかどうかのチェックを追加する
check()。このチェックは
discord.Interaction.permissionsによって与えられた権限で動作することに注意してください。渡された権限は、
discord.Permissionsのプロパティとまったく同じでなければなりません。このチェックは特別な例外であり、
CheckFailureから継承されているMissingPermissionsを発生します。バージョン 2.0 で追加.
注釈
これはDiscordがアプリケーションコマンドに提供する権限システムとは異なります。これはDiscord側で処理されるものではなく、完全にローカルのプログラム内で行われます。
- パラメータ
**perms (
bool) -- 確認する権限を示すキーワード引数。
サンプル
@tree.command() @app_commands.checks.has_permissions(manage_messages=True) async def test(interaction: discord.Interaction): await interaction.response.send_message('You can manage messages.')
- @discord.app_commands.checks.bot_has_permissions(**perms)¶
has_permissions()と似ていますが、ボット自体に列挙された権限が存在するかを確認します。これはdiscord.Interaction.app_permissionsを使用します。このチェックは特別な例外であり、
CheckFailureから継承されているBotMissingPermissionsを発生します。バージョン 2.0 で追加.
- @discord.app_commands.checks.cooldown(rate, per, *, key=...)¶
コマンドにクールダウンを追加するデコレータ。
クールダウンを使用すると、特定の時間枠の中でコマンドが使用できる回数を制限できます。このクールダウンは渡された
key関数に基づきます。もしkey関数が渡されない場合はユーザーレベルのクールダウンとなります。key関数は単一のパラメータとしてdiscord.Interactionを取り、内部のクールダウンマッピングのキーとして使用される値を返さないといけません。key関数は必要に応じてコルーチンにすることができます。クールダウンが発生した場合は、
CommandOnCooldownがエラーハンドラに送出されます。サンプル
コマンドに1メンバーにつき5秒あたり1回のクールダウンを設定します:
@tree.command() @app_commands.checks.cooldown(1, 5.0, key=lambda i: (i.guild_id, i.user.id)) async def test(interaction: discord.Interaction): await interaction.response.send_message('Hello') @test.error async def on_test_error(interaction: discord.Interaction, error: app_commands.AppCommandError): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True)
- パラメータ
rate (
int) -- クールダウンを発生させる前にコマンドを使用できる回数。per (
float) -- トリガーされたときにクールダウンを待つ秒数。key (Optional[Callable[[
discord.Interaction],collections.abc.Hashable]]) -- クールダウンの種類を示すキーを返す関数。これはコルーチンにすることもできます。もし渡されない場合既定でユーザーレベルのクールダウンとなります。Noneが渡された場合「グローバル」クールダウンと解釈されます。
- @discord.app_commands.checks.dynamic_cooldown(factory, *, key=...)¶
コマンドに動的なクールダウンを追加するデコレータ。
クールダウンを使用すると、特定の時間枠の中でコマンドが使用できる回数を制限できます。このクールダウンは渡された
key関数に基づきます。もしkey関数が渡されない場合はユーザーレベルのクールダウンとなります。key関数は単一のパラメータとしてdiscord.Interactionを取り、内部のクールダウンマッピングのキーとして使用される値を返さないといけません。factory関数が与えられた場合、それは単一のパラメータとしてdiscord.Interactionを取り、CooldownまたはNoneを返す関数でないといけません。もしNoneを返せば、クールダウンは事実上回避されます。必要に応じて、
keyとfactoryの両方をコルーチンにできます。クールダウンが発生した場合は、
CommandOnCooldownがエラーハンドラに送出されます。サンプル
所有者以外の全員にクールダウンを設定します。
def cooldown_for_everyone_but_me(interaction: discord.Interaction) -> Optional[app_commands.Cooldown]: if interaction.user.id == 80088516616269824: return None return app_commands.Cooldown(1, 10.0) @tree.command() @app_commands.checks.dynamic_cooldown(cooldown_for_everyone_but_me) async def test(interaction: discord.Interaction): await interaction.response.send_message('Hello') @test.error async def on_test_error(interaction: discord.Interaction, error: app_commands.AppCommandError): if isinstance(error, app_commands.CommandOnCooldown): await interaction.response.send_message(str(error), ephemeral=True)
- パラメータ
factory (Optional[Callable[[
discord.Interaction], Optional[Cooldown]]]) -- インタラクションを受け取り、このインタラクションに適用されるクールダウンまたはクールダウンを回避する場合Noneを返す関数。key (Optional[Callable[[
discord.Interaction],collections.abc.Hashable]]) -- クールダウンの種類を示すキーを返す関数。これはコルーチンにすることもできます。もし渡されない場合既定でユーザーレベルのクールダウンとなります。Noneが渡された場合「グローバル」クールダウンと解釈されます。
Cooldown¶
- defcopy
- defget_retry_after
- defget_tokens
- defreset
- defupdate_rate_limit
- class discord.app_commands.Cooldown(rate, per)¶
コマンドのクールダウンを表します。
バージョン 2.0 で追加.
- get_tokens(current=None)¶
レート制限が適用される前に利用可能なトークンの数を返します。
- パラメータ
current (Optional[
float]) -- トークンを計算するためのUnixエポックからの秒数。指定されていない場合はtime.time()が使用されます。- 戻り値
クールダウン前に利用可能なトークンの数。
- 戻り値の型
- get_retry_after(current=None)¶
クールダウンがリセットされるまでの時間を秒単位で返します。
- パラメータ
current (Optional[
float]) -- 現在のUnixエポックからの秒数。指定されていない場合はtime.time()が使用されます。- 戻り値
クールダウンがリセットされるまで待たないといけない秒数。
- 戻り値の型
- update_rate_limit(current=None, *, tokens=1)¶
クールダウンのレート制限を更新します。
- パラメータ
current (Optional[
float]) -- レート制限を更新するためのUnixエポックからの秒数。指定されていない場合はtime.time()が使用されます。tokens (
int) -- レート制限から差し引くトークンの量。
- 戻り値
レート制限中の場合の秒単位の再試行時間。
- 戻り値の型
Optional[
float]
- reset()¶
クールダウンを初期状態にリセットします。
Namespace¶
- class discord.app_commands.Namespace¶
ほとんど生の状態でコマンドに渡されるパラメータを保持するオブジェクト。
このクラスは意図的にシンプルで、オプション名と解決された値を単純なキーペアマッピングとして保持します。 これらの属性はドット表記を使用してアクセスできます。 例えば、
exampleという名前のオプションはns.exampleを使ってアクセスできます。 属性が見つからない場合は、属性エラーではなくNoneが返されます。警告
キー名はDiscordの生データから得られたものなので、パラメータの名前が変更された場合、関数のパラメータ名ではなく改名後のキーが使用されます。
バージョン 2.0 で追加.
- x == y
二つの名前空間が等しいかを、すべての属性が等しいかによって確認します。
- x != y
二つの名前空間が等しくないかを比較します。
- x[key]
見つかった場合は属性を返し、そうでなければ、
KeyErrorを送出します。
- key in x
属性が名前空間にあるかどうかを確認します。
- iter(x)
(name, value)ペアのイテレータを返します。これにより、例えば、辞書型やペアのリストに変換できます。
この名前空間オブジェクトは、種類により解決されたオブジェクトを適切な形式に変換します。変換情報については、以下の表を参照してください。
オプションの種類
解決される型
注釈
オートコンプリートのインタラクションでは、名前空間が検証されていないか、入力されていない可能性があります。 Discordは解決されたデータも送信しません。このため、特定のフィールドには解決されたデータではなくIDが存在することがあります。 この場合、代わりに
discord.Objectが返されます。これはDiscordの制限です。
トランスフォーマー¶
Transformer¶
- asyncautocomplete
- asynctransform
- class discord.app_commands.Transformer(*args, **kwds)¶
アプリケーションコマンドのパラメータの型アノテーションを
AppCommandOptionTypeに対応させ、生の値をその型の値に変換する基底クラス。このクラスは、クラス内のメソッドとプロパティを上書きして
Transformクラスの第二型パラメータとして渡すことによってカスタマイズできます。たとえば、文字列をカスタムのペア型に変換するには:class Point(typing.NamedTuple): x: int y: int class PointTransformer(app_commands.Transformer): async def transform(self, interaction: discord.Interaction, value: str) -> Point: (x, _, y) = value.partition(',') return Point(x=int(x.strip()), y=int(y.strip())) @app_commands.command() async def graph( interaction: discord.Interaction, point: app_commands.Transform[Point, PointTransformer], ): await interaction.response.send_message(str(point))
二番目の型パラメータにインスタンスの代わりにクラスが渡された場合、それが
__init__メソッドに何も渡さずに構築されます。バージョン 2.0 で追加.
- property channel_types¶
このパラメータにて利用できるチャンネルの種類のリスト。
type()がchannelを返す場合にのみ有効です。これは
propertyでなければなりません。既定値は空のリストです。
- 型
List[
ChannelType]
- property min_value¶
このパラメータがサポートする最小の値。
type()がnumber、integerまたはstringを返す場合にのみ有効です。これは
propertyでなければなりません。既定値は
Noneです。- 型
Optional[
int]
- property max_value¶
このパラメータがサポートする最大の値。
type()がnumber、integerまたはstringを返す場合にのみ有効です。これは
propertyでなければなりません。既定値は
Noneです。- 型
Optional[
int]
- property choices¶
このパラメータにて利用できる最大25個の選択肢のリスト。
type()がnumber、integerまたはstringを返す場合にのみ有効です。これは
propertyでなければなりません。既定値は
Noneです。- 型
Optional[List[
Choice]]
- await transform(interaction, value, /)¶
This function could be a coroutine.
解決されたオプション値を別の値に変換します。
この変換関数に渡される値は、
変換対応表の値と同じです。- パラメータ
interaction (
Interaction) -- 処理中のインタラクション。value (Any) -- 解決された引数値。どのオプションの種類がどの値に対応するかについては
変換対応表を参照してください。
Transform¶
- class discord.app_commands.Transform¶
パラメータに適用して与えられた特定の種類のオプションを
Transformerで変換するようその動作を変更できる型アノテーション。これを使用するときには二つのジェネリックパラメータが必要で、一つ目には変換先の型を、二つ目には実際に変換を行うTransformerの型を指定しないといけません。型チェック時には型チェッカがコードの意図を理解できるよう
typing.Annotatedと同様になります。使用例は、
Transformerを確認してください。バージョン 2.0 で追加.
Range¶
- class discord.app_commands.Range¶
与えられた範囲内に収まる数値または文字列型を必要とするパラメータに適用できる型アノテーション。
型チェック時には型チェッカがコードの意図を理解できるよう
typing.Annotatedと同様になります。範囲の例:
Range[int, 10]は最小値10、最大値なしを意味します。Range[int, None, 10]は最小値なし、最大値10を意味します。Range[int, 1, 10]は最小値1、最大値10を意味します。Range[float, 1.0, 5.0]は最小値1.0、最大値5.0を意味します。Range[str, 1, 10]は最小1文字、最大10文字を意味します。
バージョン 2.0 で追加.
サンプル
@app_commands.command() async def range(interaction: discord.Interaction, value: app_commands.Range[int, 10, 12]): await interaction.response.send_message(f'Your value is {value}', ephemeral=True)
Timestamp¶
- class discord.app_commands.Timestamp(*args, **kwds)¶
A type annotation that can be applied to a parameter for transforming a Discord style timestamp input to a
datetime.datetime.バージョン 2.7 で追加.
警告
Due to a Discord limitation, no timezone is provided with the input. The UTC timezone has been supplanted instead.
サンプル
@app_commands.command() async def datetime(interaction: discord.Interaction, value: app_commands.Timestamp): await interaction.response.send_message(value.isoformat())
- await transform(interaction, value, /)¶
This function could be a coroutine.
解決されたオプション値を別の値に変換します。
この変換関数に渡される値は、
変換対応表の値と同じです。- パラメータ
interaction (
Interaction) -- 処理中のインタラクション。value (Any) -- 解決された引数値。どのオプションの種類がどの値に対応するかについては
変換対応表を参照してください。
翻訳¶
Translator¶
- class discord.app_commands.Translator¶
コマンド、パラメータ、および選択肢の翻訳を処理するクラス。
非同期対応の翻訳を可能にし、また
gettextや Project Fluent のような幅広い翻訳システムをサポートするために、翻訳は遅延して行われます。トランスレータを使用するには、
CommandTree.set_translator()メソッドを使用して設定する必要があります。文字列の翻訳フローは次のとおりです。- 翻訳したいコマンドで
strの代わりにlocale_strを使用します。 現在、これらはコマンド名、コマンド説明、パラメータ名、パラメータ説明、選択肢名です。
これは
describe()デコレータ内でも使用できます。
- 翻訳したいコマンドで
翻訳を処理するトランスレータインスタンスに対し
CommandTree.set_translator()を呼び出します。CommandTree.sync()を呼び出します。ライブラリは翻訳可能なすべての対応する文字列に対し
Translator.translate()を呼び出します。
バージョン 2.0 で追加.
- await load()¶
This function is a coroutine.
翻訳システムを読み込むための非同期セットアップ関数。
デフォルトの実装では何もしません。
CommandTree.set_translator()が呼び出されたときに呼び出されます。
- await unload()¶
This function is a coroutine.
翻訳システムをアンロードするための非同期関数。
デフォルトの実装では何もしません。
これは、すでにツリーにトランスレータが存在する状態で
CommandTree.set_translator()を呼び出すか、discord.Client.close()が呼び出されたときに呼び出されます。
- await translate(string, locale, context)¶
This function is a coroutine.
指定した文字列を指定したロケールに翻訳します。
文字列を翻訳できない場合は、
Noneを返すべきです。デフォルトの実装では
Noneを返します。このメソッドで送出される例外は、
TranslationErrorから継承すべきです。 そうでない場合は、これが呼び出されたときに例外が代わりにチェーンされます。- パラメータ
string (
locale_str) -- 翻訳すべき文字列。locale (
Locale) -- 翻訳先のローケル。context (
TranslationContext) -- 文字列を翻訳するときの文脈。より良い型チェックのために、TranslationContextTypes型を使用して型の絞り込みを行うことができます。これはTranslationContextと機能的に同じです。
locale_str¶
- class discord.app_commands.locale_str(message, /, **kwargs)¶
文字列を翻訳できるものとマークします。
これは遅延して行われ、実際には
CommandTree.sync()が呼び出されるまで翻訳されません。syncメソッドは、翻訳を
CommandTreeが使用するTranslatorインスタンスに委任します。翻訳フローに関する詳細に関しては、Translatorのドキュメントを参照してください。- str(x)
文字列に渡されたメッセージを返します。
- x == y
文字列が他の文字列と等しいか確認します。
- x != y
文字列が他の文字列と等しくないか確認します。
- hash(x)
文字列の ハッシュを返します。
バージョン 2.0 で追加.
- message¶
翻訳すべきメッセージ。一度設定したら変更できません。
警告
これはDiscordに送信するデフォルトの「メッセージ」でなければなりません。 Discordはこのメッセージをライブラリに送信し、ライブラリはコマンドを実行するためのデータにアクセスするために使用します。
例えば、コマンド名の文脈において、コマンド名が
fooの場合、メッセージはfooでないと いけません 。 FluentのようなメッセージIDが必要な他の翻訳システムでは、キーワード引数を使用して渡すことを検討してください。- 型
TranslationContext¶
- class discord.app_commands.TranslationContext(location, data)¶
翻訳される
locale_strの文脈を提供するクラス。これは、文字列がどこにあるかを正確に特定し、実際の翻訳を取得するのに役立ちます。
- location¶
この文字列が存在する場所。
- data¶
翻訳されている追加のデータ。
- 型
Any
TranslationContextLocation¶
- class discord.app_commands.TranslationContextLocation¶
翻訳が要求されたときに、翻訳すべき場所を示す列挙型。
バージョン 2.0 で追加.
- command_name¶
コマンド名の翻訳。
- command_description¶
コマンドの説明の翻訳。
- group_name¶
グループ名の翻訳。
- group_description¶
グループの説明の翻訳。
- parameter_name¶
パラメータ名の翻訳。
- parameter_description¶
パラメータの説明の翻訳。
- choice_name¶
選択肢名の翻訳。
- other¶
その他の翻訳。これは他の目的で
Translator.translate()を実行するときに役立ちます。
例外¶
- exception discord.app_commands.AppCommandError¶
アプリケーションコマンドに関連するエラーすべての基礎となる例外。
これは
discord.DiscordExceptionを継承しています。この例外及び、ここから継承された例外は、以下の順で捕捉され様々なエラーハンドラに渡されるなど、特別な方法で処理されます。
バージョン 2.0 で追加.
- exception discord.app_commands.CommandInvokeError(command, e)¶
呼び出そうとしたコマンドが例外を送出した場合に発生する例外。
AppCommandErrorを継承します。バージョン 2.0 で追加.
- command¶
失敗したコマンド。
- 型
Union[
Command,ContextMenu]
- exception discord.app_commands.TransformerError(value, opt_type, transformer)¶
Transformerまたは型アノテーションがターゲット型に変換できない場合に発生する例外。AppCommandErrorを継承します。もし
AppCommandErrorを継承しない例外が変換中に送出された場合その例外はこれに包まれます。元の例外は__cause__属性から取得できます。もし例外がAppCommandErrorから派生したものであればそのまま伝播されます。バージョン 2.0 で追加.
- value¶
変換に失敗した値。
- 型
Any
- type¶
変換に失敗した引数の型。
- transformer¶
変換に失敗したトランスフォーマー。
- exception discord.app_commands.TranslationError(*msg, string=None, locale=None, context)¶
ライブラリが文字列の翻訳に失敗したときに発生する例外。
AppCommandErrorを継承します。もしこれを継承しない例外が
Translator.translate()の実行中に送出された場合その例外はこれに包まれます。元の例外は__cause__属性から取得できます。そうでなければ、例外はそのまま伝播されます。バージョン 2.0 で追加.
- string¶
存在する場合、エラーの原因となった文字列。
- 型
Optional[Union[
str,locale_str]]
- context¶
エラーを引き起こした翻訳の文脈。
- exception discord.app_commands.CheckFailure¶
コマンドのチェック関数が失敗した場合に発生する例外。
AppCommandErrorを継承します。バージョン 2.0 で追加.
- exception discord.app_commands.NoPrivateMessage(message=None)¶
コマンドがダイレクトメッセージで動作しない場合に発生する例外。
CheckFailureを継承します。バージョン 2.0 で追加.
- exception discord.app_commands.MissingRole(missing_role)¶
コマンド実行者がコマンドを実行するためのロールを持っていない場合に発生する例外。
CheckFailureを継承します。バージョン 2.0 で追加.
- missing_role¶
見つからなかった必須のロール。これは
has_role()に渡されたパラメータと同一です。
- exception discord.app_commands.MissingAnyRole(missing_roles)¶
コマンド実行者がコマンドを実行するためのロールをどれも持っていない場合に発生する例外。
CheckFailureを継承します。バージョン 2.0 で追加.
- missing_roles¶
見つからなかったロール。これは
has_any_role()に渡されたパラメータと同一です。
- exception discord.app_commands.MissingPermissions(missing_permissions, *args)¶
コマンド実行者がコマンドを実行する権限を持っていない場合に発生する例外。
CheckFailureを継承します。バージョン 2.0 で追加.
- exception discord.app_commands.BotMissingPermissions(missing_permissions, *args)¶
ボットのメンバーがコマンドを実行する権限を持っていない場合に発生する例外。
CheckFailureを継承します。バージョン 2.0 で追加.
- exception discord.app_commands.CommandOnCooldown(cooldown, retry_after)¶
呼び出そうとしたコマンドがクールダウン中の場合に発生する例外。
CheckFailureを継承します。バージョン 2.0 で追加.
- exception discord.app_commands.CommandLimitReached(guild_id, limit, type=<AppCommandType.chat_input: 1>)¶
グローバルまたはギルド内でアプリケーションコマンドの最大登録数に達したときに発生する例外。
AppCommandErrorを継承します。バージョン 2.0 で追加.
- type¶
制限に達したコマンドの種類。
- exception discord.app_commands.CommandAlreadyRegistered(name, guild_id)¶
コマンドがすでに登録されている場合に発生する例外。
AppCommandErrorを継承します。バージョン 2.0 で追加.
- exception discord.app_commands.CommandSignatureMismatch(command)¶
Discordからのアプリケーションコマンドがコード内のものとは異なるシグネチャを持つ場合に発生する例外。 これは、Discordに渡したコマンド定義と現在のコマンド定義が異なるときに発生します。 つまり、あなたのコードが古いものであるか、Discordのデータが同期されていません。
AppCommandErrorを継承します。バージョン 2.0 で追加.
- command¶
シグネチャが一致しないコマンド。
- 型
Union[
Command,ContextMenu,Group]
- exception discord.app_commands.CommandNotFound(name, parents, type=<AppCommandType.chat_input: 1>)¶
アプリケーションコマンドが見つからなかった場合に発生する例外。
AppCommandErrorを継承します。バージョン 2.0 で追加.
- type¶
見つからなかったコマンドの種類。
- exception discord.app_commands.CommandSyncFailure(child, commands)¶
CommandTree.sync()が失敗したときに発生する例外。これにより、同期の失敗に関する情報が少し読みやすい形式で提供されます。
これは
AppCommandErrorとHTTPExceptionを継承します。バージョン 2.0 で追加.