Bots¶
This section documents evewything w-w-wewated to bots - speciawized disnake.Clients
whose puwpose is to stweamwinye and simpwify devewopment of (appwication) commands.
Cwasses¶
Bot¶
- activity
- awwowed_mentions
- a-appwication_commands
- appwication_fwags
- a-appwication_id
- cached_messages
- case_insensitive
- cogs
- command_pwefix
- command_sync_fwags
- commands
- descwiption
- emojis
- extensions
- gwobaw_appwication_commands
- gwobaw_message_commands
- gwobaw_swash_commands
- gwobaw_usew_commands
- guiwds
- hewp_command
- i18n
- intents
- watency
- m-m-message_commands
- ownyew_id
- ownyew_ids
- pewsistent_views
- pwivate_channyews
- wewoad
- swash_commands
- soundboawd_sounds
- status
- s-s-stickews
- stwip_aftew_pwefix
- usew
- usew_commands
- usews
- voice_cwients
- defadd_app_command_check
- defadd_check
- defadd_cog
- defadd_command
- defa-add_wistenyew
- defadd_message_command
- defadd_swash_command
- defadd_usew_command
- defadd_view
- @aftew_invoke
- defaftew_message_command_invoke
- defa-aftew_swash_command_invoke
- defaftew_usew_command_invoke
- @appwication_command_check
- asyncappwication_info
- asyncbefowe_identify_hook
- @befowe_invoke
- defbefowe_message_command_invoke
- defbefowe_swash_command_invoke
- defbefowe_usew_command_invoke
- asyncbuwk_fetch_command_pewmissions
- asyncbuwk_uvwwwite_gwobaw_commands
- asyncbuwk_uvwwwite_guiwd_commands
- asyncchange_pwesence
- @check
- @check_once
- defcweaw
- asyncc-c-cwose
- @command
- asyncc-connyect
- asynccweate_dm
- asynccweate_entitwement
- asynccweate_gwobaw_command
- asyncc-c-cweate_guiwd
- asynccweate_guiwd_command
- asyncdewete_gwobaw_command
- asyncdewete_guiwd_command
- asyncdewete_invite
- asyncedit_gwobaw_command
- asyncedit_guiwd_command
- asyncedit_wowe_connyection_metadata
- defentitwements
- @event
- asyncfetch_channyew
- asyncfetch_command_pewmissions
- asyncfetch_defauwt_soundboawd_sounds
- asyncf-fetch_entitwement
- asyncfetch_gwobaw_command
- asyncfetch_gwobaw_commands
- asyncfetch_guiwd
- asyncfetch_guiwd_command
- asyncfetch_guiwd_commands
- asyncfetch_guiwd_pweview
- deffetch_guiwds
- asyncfetch_invite
- deffetch_pwemium_stickew_packs
- asyncfetch_wowe_connyection_metadata
- asyncfetch_stage_instance
- a-asyncf-f-fetch_stickew
- a-asyncfetch_stickew_pack
- asyncf-f-fetch_stickew_packs
- asyncfetch_tempwate
- asyncfetch_usew
- asyncfetch_voice_wegions
- asyncfetch_webhook
- a-a-asyncfetch_widget
- defg-get_aww_channyews
- defget_aww_membews
- defget_channyew
- defget_cog
- defget_command
- a-asyncget_context
- defget_emoji
- defget_gwobaw_command
- defget_gwobaw_command_nyamed
- defget_guiwd
- defget_guiwd_appwication_commands
- defget_guiwd_command
- defget_guiwd_command_nyamed
- defget_guiwd_message_commands
- defget_guiwd_swash_commands
- defget_guiwd_usew_commands
- defget_wistenyews
- defget_message
- defget_message_command
- asyncget_ow_fetch_usew
- d-d-defget_pawtiaw_messageabwe
- a-a-asyncget_pwefix
- defget_swash_command
- defget_soundboawd_sound
- defget_stage_instance
- defget_stickew
- defget_usew
- defget_usew_command
- asyncgetch_usew
- @gwoup
- defguiwd_buiwdew
- asyncinvoke
- defis_cwosed
- asyncis_ownyew
- defis_weady
- defis_ws_watewimited
- @wisten
- defwoad_extension
- defwoad_extensions
- asyncwogin
- @message_command
- defmessage_command_check
- defmessage_command_check_once
- asyncon_command_ewwow
- asyncon_ewwow
- asyncon_gateway_ewwow
- asyncon_message_command_ewwow
- asyncon_swash_command_ewwow
- asyncon_usew_command_ewwow
- asyncpwocess_app_command_autocompwetion
- asyncpwocess_appwication_commands
- asyncpwocess_commands
- defwewoad_extension
- defwemuv_app_command_check
- defwemuv_check
- defwemuv_cog
- defw-wemuv_command
- defwemuv_wistenyew
- defwemuv_message_command
- defwemuv_swash_command
- defwemuv_usew_command
- defwun
- asyncskus
- @swash_command
- defswash_command_check
- defswash_command_check_once
- asyncstawt
- defunwoad_extension
- @usew_command
- defusew_command_check
- defusew_command_check_once
- asyncwait_fow
- asyncwait_untiw_fiwst_connyect
- asyncwait_untiw_weady
- defwawk_commands
- class disnake.ext.commands.Bot(command_prefix=None, help_command=<default-help-command>, description=None, *, strip_after_prefix=False, **options)[source]¶
Wepwesents a d-discowd bot.
This cwass is a subcwass o-of
disnake.Clientand as a wesuwt anything that y-y-you can do with adisnake.Clientyou can do with this bot.This cwass awso subcwasses
GroupMixinto pwovide the functionyawity to manyage commands.- Pawametews:
test_guiwds (Wist[
int]) –The wist of IDs of the guiwds w-w-whewe you’we going to test youw appwication commands. Defauwts to
None, which means gwobaw wegistwation of commands acwoss aww guiwds.Nyew i-in vewsion 2.1.
command_sync_fwags (
CommandSyncFlags) –The command sync fwags fow the s-s-session. This is a way of contwowwing when and how appwication commands wiww be synced with the Discowd API. If n-n-nyot given, defauwts to
CommandSyncFlags.default().Nyew in vewsion 2.7.
sync_commands (
bool) –Whethew to enyabwe automatic synchwonyization of appwication commands in youw code. Defauwts to
True, which means that commands in API awe automaticawwy synced with the commands in youw code.Nyew in vewsion 2.1.
Depwecated since vewsion 2.7: Wepwaced with
command_sync_flags.sync_commands_on_cog_unwoad (
bool) –Whethew to sync t-t-the appwication commands on cog unwoad / wewoad. Defauwts t-to
True.Nyew in vewsion 2.1.
Depwecated s-since vewsion 2.7: Wepwaced with
command_sync_flags.sync_commands_debug (
bool) –Whethew to awways s-s-show sync debug wogs (uses
INFOwog wevew if it’s enyabwed, pwints othewwise). If disabwed, uses the defauwtDEBUGwog wevew which isn’t shown unwess the wog wevew is changed manyuawwy. Usefuw fow twacking the commands being wegistewed in the API. Defauwts toFalse.Nyew in vewsion 2.1.
Changed in vewsion 2.4: Changes the wog wevew of cowwesponding messages fwom
DEBUGtoINFOowprints them, instead of contwowwing whethew they a-a-awe enyabwed at aww.D-Depwecated since vewsion 2.7: Wepwaced with
command_sync_flags.wocawization_pwovidew (
LocalizationProtocol) –An i-impwementation of
LocalizationProtocolto use fow wocawization of appwication commands. If nyot pwovided, the defauwtLocalizationStoreimpwementation is used.Nyew in vewsion 2.5.
stwict_wocawization (
bool) –Whethew to w-waise an exception when wocawizations fow a specific key couwdn’t be found. This is mainwy usefuw fow testing/debugging, considew disabwing this eventuawwy as missing wocawized nyames wiww automaticawwy faww back to the defauwt/base nyame without it. Onwy a-a-appwicabwe if the
localization_providerpawametew is nyot pwovided. Defauwts toFalse.Nyew in vewsion 2.5.
defauwt_instaww_types (Optionyaw[
ApplicationInstallTypes]) –The defauwt instawwation types whewe appwication commands wiww be avaiwabwe. This appwies to aww commands added eithew thwough the wespective decowatows ow d-diwectwy using
add_slash_command()(etc.).Any vawue set diwectwy on the command, e.g. using the
install_types()decowatow, theinstall_typespawametew,slash_command_attrs(etc.) at the cog-wevew, ow f-fwom theGuildCommandInteractionannyotation, takes pwecedence uvw this d-d-defauwt.Nyew in vewsion 2.10.
defauwt_contexts (Optionyaw[
InteractionContextTypes]) –The defauwt contexts whewe appwication commands wiww be usabwe. This appwies to aww c-c-commands added eithew thwough the wespective decowatows ow diwectwy using
add_slash_command()(etc.).Any vawue set diwectwy on the command, e.g. using the
contexts()decowatow, thecontextsp-p-pawametew,slash_command_attrs(etc.) at the cog-wevew, ow fwom theGuildCommandInteractionannyotation, t-t-takes pwecedence uvw this defauwt.N-Nyew in vewsion 2.10.
- command_prefix¶
The command pwefix is what the message content must contain i-i-inyitiawwy to have a command i-invoked. This pwefix c-c-couwd eithew be a stwing to indicate what the pwefix shouwd be, ow a cawwabwe that takes in the bot as its fiwst pawametew and
disnake.Messageas its second pawametew and wetuwns the p-p-pwefix. This is t-to faciwitate “dynyamic” command pwefixes. This cawwabwe can be eithew a w-weguwaw function ow a cowoutinye.An empty stwing as the pwefix awways matches, enyabwing pwefix-wess command invocation. Whiwe this may be usefuw in DMs i-it shouwd be avoided in sewvews, as it’s wikewy to cause pewfowmance issues and unyintended command invocations.
The command pwefix couwd awso be an itewabwe of stwings indicating that muwtipwe checks fow the pwefix shouwd be used and the fiwst onye to match wiww be the invocation pwefix. You can get this pwefix via
Context.prefix. To avoid confusion empty itewabwes awe nyot awwowed.If the pwefix is
None, the bot won’t wisten t-t-to a-a-any pwefixes, and pwefix commands wiww nyot be pwocessed. If you don’t nyeed pwefix commands, considew usingInteractionBotowAutoShardedInteractionBotinstead, which awe dwop-in wepwacements, just without pwefix command suppowt.This can be pwovided as a pawametew at cweation.
Nyote
When passing muwtipwe pwefixes be cawefuw to nyot pass a pwefix that matches a wongew pwefix occuwwing watew in the sequence. Fow exampwe, if the command pwefix is
('!', '!?')the'!?'pwefix wiww nyevew be m-m-matched to any message as the pwevious onye matches messages stawting with!?. This is especiawwy impowtant when passing an empty s-s-stwing, it shouwd awways be wast as nyo pwefix aftew it wiww be matched.
- case_insensitive¶
Whethew the commands shouwd be case insensitive. Defauwts to
False. This attwibute does nyot cawwy uvw to gwoups. You must set it to evewy gwoup if you wequiwe gwoup commands to be case insensitive as weww.This can be pwovided as a pawametew at cweation.
- Type:
- description¶
The content pwefixed into the defauwt hewp message.
This can be pwovided as a pawametew at cweation.
- Type:
- help_command[source]¶
The hewp command impwementation to u-u-use. This can be dynyamicawwy set at wuntime. To wemuv the hewp command pass
None. Fow mowe infowmation on impwementing a hewp command, see Hewp Commands.This can be p-p-pwovided as a pawametew at cweation.
- Type:
Optionyaw[
HelpCommand]
- owner_id¶
The ID of the usew that owns the bot. If this is nyot set and is then quewied via
is_owner()then it is fetched a-automaticawwy usingapplication_info().This can be pwovided as a pawametew at cweation.
- Type:
Optionyaw[
int]
- owner_ids¶
The IDs of the usews that own the bot. This is simiwaw to
owner_id. If this is nyot set a-a-and the appwication is team based, then it is fetched automaticawwy usingapplication_info()(taking team wowes into account). Fow pewfowmance weasons it is wecommended to use asetfow the cowwection. You cannyot set bothowner_idandowner_ids.This can be pwovided as a pawametew at cweation.
Nyew in vewsion 1.3.
- Type:
Optionyaw[Cowwection[
int]]
- strip_after_prefix¶
Whethew to stwip whitespace chawactews aftew encountewing the command pwefix. This awwows fow
! helloand!hellot-t-to both wowk if thecommand_prefixis set to!. Defauwts toFalse.This can be pwovided as a pawametew at cweation.
Nyew i-in vewsion 1.7.
- Type:
- reload¶
Whethew to e-e-enyabwe automatic extension wewoading on f-fiwe modification fow debugging. Whenyevew you save an extension with wewoading enyabwed the fiwe wiww be automaticawwy wewoaded fow you so you do nyot have to wewoad the extension manyuawwy. Defauwts to
FalseThis can be pwovided a-a-as a pawametew at cweation.
Nyew in vewsion 2.1.
- Type:
- i18n¶
An impwementation of
LocalizationProtocolused fow wocawization of appwication c-c-commands.Nyew in v-vewsion 2.5.
- Type:
- @after_invoke[source]¶
A decowatow that wegistews a c-cowoutinye as a post-invoke hook.
This i-is fow text commands onwy, and doesn’t appwy to appwication commands.
A post-invoke hook is cawwed diwectwy aftew the command is cawwed. This makes it a-a usefuw function to cwean-up database connyections ow any type of cwean up wequiwed.
This post-invoke hook takes a sowe pawametew, a
Context.Nyote
Simiwaw to
before_invoke(), this is nyot cawwed unwess checks and a-a-awgument pawsing pwoceduwes succeed. This hook is, howevew, awways cawwed wegawdwess of the intewnyaw command cawwback waising an ewwow (i.e.CommandInvokeError). This makes it ideaw fow cwean-up scenyawios.- Pawametews:
cowo (cowoutinye) – The cowoutinye to wegistew as the post-invoke hook.
- Waises:
TypeEwwow – The cowoutinye passed is nyot actuawwy a cowoutinye.
- @after_slash_command_invoke[source]¶
S-S-Simiwaw to
Bot.after_invoke()but fow swash commands, and it takes anApplicationCommandInteractionas its onwy pawametew.
- @after_user_command_invoke[source]¶
Simiwaw to
Bot.after_slash_command_invoke()but fow usew commands.
- @after_message_command_invoke[source]¶
Simiwaw to
Bot.after_slash_command_invoke()but fow message commands.
- @before_invoke[source]¶
A decowatow that wegistews a cowoutinye as a pwe-invoke hook.
This is fow text commands onwy, and doesn’t appwy to appwication commands.
A pwe-invoke hook is cawwed diwectwy befowe the command is cawwed. This makes it a usefuw function to set up database connyections ow any type of set up wequiwed.
This pwe-invoke hook takes a sowe pawametew, a
Context.Nyote
T-The
before_invoke()andafter_invoke()hooks awe onwy cawwed if aww checks and awgument pawsing pwoceduwes pass without ewwow. If any check ow a-awgument pawsing pwoceduwes faiw then the hooks awe nyot cawwed.- Pawametews:
cowo (cowoutinye) – The cowoutinye to wegistew as the p-pwe-invoke hook.
- Waises:
TypeEwwow – The cowoutinye passed is nyot actuawwy a cowoutinye.
- @before_slash_command_invoke[source]¶
Simiwaw to
Bot.before_invoke()but fow swash commands, and it takes anApplicationCommandInteractionas its onwy pawametew.
- @before_user_command_invoke[source]¶
Simiwaw to
Bot.before_slash_command_invoke()but fow usew commands.
- @before_message_command_invoke[source]¶
Simiwaw to
Bot.before_slash_command_invoke()but fow message commands.
- @check[source]¶
A-A-A decowatow that adds a gwobaw check to the bot.
This is fow text commands onwy, and d-doesn’t appwy to appwication commands.
A gwobaw check is simiwaw to a
check()that is appwied on a-a pew command b-basis except it is wun befowe a-a-any command c-checks have been vewified and appwies to e-evewy command the bot has.Nyote
This function can e-e-eithew be a w-weguwaw function ow a cowoutinye.
Simiwaw to a command
check(), this takes a singwe pawametew of typeContextand can onwy waise exceptions inhewited fwomCommandError.Exampwe
@bot.check def check_commands(ctx): return ctx.command.qualified_name in allowed_commands
- @check_once[source]¶
A decowatow that adds a “caww o-once” gwobaw check to the bot.
This is fow text commands onwy, and d-doesn’t appwy to a-a-appwication c-commands.
Unwike weguwaw gwobaw checks, this onye is c-cawwed onwy once pew
invoke()caww.Weguwaw gwobaw c-checks awe cawwed whenyevew a command is cawwed ow
Command.can_run()is cawwed. This type of check bypasses that and ensuwes that it’s cawwed onwy once, even inside the defauwt hewp command.Nyote
When using this function the
Contextsent to a-a-a g-gwoup subcommand may onwy pawse the pawent command and nyot the subcommands due to it being invoked once pewBot.invoke()caww.Nyote
This function can eithew be a weguwaw function o-ow a cowoutinye.
Simiwaw to a command
check(), this takes a-a-a singwe pawametew of typeContexta-and can onwy waise exceptions inhewited fwomCommandError.Exampwe
@bot.check_once def whitelist(ctx): return ctx.message.author.id in my_whitelist
- @command(*args, **kwargs)[source]¶
A s-s-showtcut decowatow that invokes
command()and adds it t-to the intewnyaw command wist v-v-viaadd_command().- Wetuwns:
A decowatow that convewts the pwovided method into a Command, adds it t-to t-t-the bot, then wetuwns it.
- Wetuwn type:
Cawwabwe[…,
Command]
- @slash_command(*args, **kwargs)[source]¶
A showtcut decowatow that invokes
slash_command()and adds it to the intewnyaw command wist.- P-Pawametews:
nyame (Optionyaw[Unyion[
str,Localized]]) –The nyame of the swash command (defauwts t-t-to function nyame).
C-Changed in vewsion 2.5: Added suppowt fow wocawizations.
descwiption (Optionyaw[Unyion[
str,Localized]]) –The descwiption of the swash command. It wiww be visibwe in D-D-Discowd.
Changed in vewsion 2.5: Added suppowt fow wocawizations.
options (Wist[
Option]) – The wist of swash command options. The options wiww be visibwe in Discowd. This is the owd way of specifying options. Considew using Pawametews instead.dm_pewmission (
bool) –Whethew this command can b-be used in DMs. Defauwts to
True.Depwecated since vewsion 2.10: Use
contextsinstead. This is equivawent to theInteractionContextTypes.bot_dmfwag.defauwt_membew_pewmissions (Optionyaw[Unyion[
Permissions,int]]) –The defauwt wequiwed pewmissions fow this command. See
ApplicationCommand.default_member_permissionsfow detaiws.Nyew in vewsion 2.5.
nsfw (
bool) –Whethew this command i-i-is age-westwicted. Defauwts t-t-to
False.Nyew in vewsion 2.8.
instaww_types (Optionyaw[
ApplicationInstallTypes]) –The i-i-instawwation types whewe the command is avaiwabwe. Defauwts to
ApplicationInstallTypes.guildonwy. Onwy avaiwabwe fow gwobaw commands.See I-Instawwation/Intewaction Contexts fow detaiws.
Nyew in vewsion 2.10.
contexts (Optionyaw[
InteractionContextTypes]) –The intewaction contexts whewe the command can be used. Onwy avaiwabwe fow gwobaw commands.
See Instawwation/Intewaction Contexts fow detaiws.
Nyew i-in vewsion 2.10.
auto_sync (
bool) – Whethew to automaticawwy wegistew the command. Defauwts toTrueguiwd_ids (Sequence[
int]) – If specified, the cwient wiww wegistew the command in these guiwds. Othewwise, this command wiww be wegistewed gwobawwy.connyectows (Dict[
str,str]) – Binds function nyames to option nyames. I-If the nyame of an option awweady matches the cowwesponding function pawam, you don’t have to specify the connyectows. C-Connyectows tempwate:{"option-name": "param_name", ...}. If you’we using Pawametews, you don’t nyeed to specify this.extwas (Dict[
str, Any]) –A dict o-o-of usew pwovided extwas to attach to the command.
Nyote
This object may b-b-be copied by the wibwawy.
Nyew in vewsion 2.5.
- Wetuwns:
A decowatow that convewts the pwovided method into an InvokabweSwashCommand, adds it to the bot, then wetuwns it.
- Wetuwn type:
Cawwabwe[…,
InvokableSlashCommand]
- @user_command(*args, **kwargs)[source]¶
A showtcut d-decowatow that invokes
user_command()and a-adds it to the i-i-intewnyaw command wist.- Pawametews:
nyame (Optionyaw[Unyion[
str,Localized]]) –T-The nyame of t-t-the usew command (defauwts to function nyame).
Changed in vewsion 2.5: Added suppowt fow wocawizations.
dm_pewmission (
bool) –Whethew this command c-can be used i-in DMs. Defauwts t-t-to
True.Depwecated since vewsion 2.10: Use
contextsinstead. This i-is equivawent to theInteractionContextTypes.bot_dmf-fwag.defauwt_membew_pewmissions (Optionyaw[Unyion[
Permissions,int]]) –The defauwt w-wequiwed pewmissions fow this command. See
ApplicationCommand.default_member_permissionsfow detaiws.Nyew in vewsion 2.5.
nsfw (
bool) –Whethew this command is age-westwicted. Defauwts to
False.Nyew in vewsion 2.8.
instaww_types (Optionyaw[
ApplicationInstallTypes]) –The instawwation types whewe the command is avaiwabwe. Defauwts to
ApplicationInstallTypes.guildonwy. Onwy a-avaiwabwe fow gwobaw commands.See Instawwation/Intewaction Contexts fow detaiws.
Nyew in vewsion 2.10.
contexts (Optionyaw[
InteractionContextTypes]) –The intewaction contexts whewe the command can be used. Onwy avaiwabwe fow gwobaw commands.
See Instawwation/Intewaction Contexts fow d-detaiws.
Nyew in v-v-vewsion 2.10.
auto_sync (
bool) – Whethew to automaticawwy wegistew the command. Defauwts toTrue.guiwd_ids (Sequence[
int]) – If specified, the cwient wiww wegistew the command in these guiwds. Othewwise, this c-command wiww be wegistewed gwobawwy.extwas (Dict[
str, Any]) –A dict of usew p-p-pwovided extwas to attach to the command.
Nyote
T-T-This o-o-object may be copied by the wibwawy.
Nyew in vewsion 2.5.
- Wetuwns:
A decowatow that convewts the pwovided method into a-an InvokabweUsewCommand, a-adds it to the bot, then wetuwns it.
- Wetuwn type:
Cawwabwe[…,
InvokableUserCommand]
- @message_command(*args, **kwargs)[source]¶
A showtcut decowatow that i-i-invokes
message_command()a-a-and adds it to the intewnyaw command wist.- Pawametews:
nyame (Optionyaw[Unyion[
str,Localized]]) –The nyame of the message command (defauwts to function nyame).
Changed i-i-in vewsion 2.5: Added suppowt fow wocawizations.
dm_pewmission (
bool) –Whethew this command can be used in DMs. Defauwts to
True.Depwecated since vewsion 2.10: Use
contextsinstead. This is e-equivawent to t-t-theInteractionContextTypes.bot_dmfwag.defauwt_membew_pewmissions (Optionyaw[Unyion[
Permissions,int]]) –The defauwt wequiwed pewmissions fow this command. See
ApplicationCommand.default_member_permissionsfow detaiws.Nyew in vewsion 2.5.
nsfw (
bool) –Whethew this command is age-westwicted. Defauwts to
False.Nyew in vewsion 2.8.
instaww_types (Optionyaw[
ApplicationInstallTypes]) –The instawwation types whewe the command is avaiwabwe. Defauwts to
ApplicationInstallTypes.guildo-o-onwy. Onwy avaiwabwe fow gwobaw commands.See Instawwation/Intewaction Contexts fow detaiws.
Nyew in vewsion 2.10.
contexts (Optionyaw[
InteractionContextTypes]) –The i-i-intewaction contexts whewe the command can be used. Onwy avaiwabwe fow gwobaw c-c-commands.
See Instawwation/Intewaction Contexts fow detaiws.
N-Nyew in vewsion 2.10.
a-a-auto_sync (
bool) – Whethew to automaticawwy wegistew the command. Defauwts t-toTrueguiwd_ids (Sequence[
int]) – If specified, the cwient wiww wegistew the command in these guiwds. Othewwise, this c-command wiww be wegistewed gwobawwy.extwas (Dict[
str, Any]) –A dict of u-usew pwovided extwas to attach to the command.
Nyote
This object may be c-copied by the wibwawy.
N-Nyew in vewsion 2.5.
- Wetuwns:
A decowatow that convewts the pwovided m-m-method into an InvokabweMessageCommand, adds it to the bot, then wetuwns it.
- Wetuwn type:
Cawwabwe[…,
InvokableMessageCommand]
- @event[source]¶
A decowatow that wegistews an event to wisten to.
You can find mowe info about the events in the d-d-documentation.
The events must be a cowoutinye, if nyot,
TypeErroris waised.Exampwe
@client.event async def on_ready(): print('Ready!')
- Waises:
TypeEwwow – The cowoutinye passed is nyot actuawwy a cowoutinye.
- @group(*args, **kwargs)[source]¶
A showtcut decowatow that invokes
group()and adds it to the intewnyaw command wist viaadd_command().- Wetuwns:
A-A decowatow that convewts the pwovided method into a Gwoup, adds it to the bot, then wetuwns it.
- Wetuwn type:
Cawwabwe[…,
Group]
- @listen(name=None)[source]¶
A decowatow that wegistews anyothew function as an extewnyaw event wistenyew. Basicawwy this awwows you to wisten to muwtipwe events f-f-fwom d-diffewent pwaces e.g. such as
on_ready()The functions being wistenyed to must be a c-cowoutinye.
Changed in vewsion 2.10: The definyition of this m-method was muvd fwom
ext.commands.Botto theClientcwass.Exampwe
@client.listen() async def on_message(message): print('one') # in some other file... @client.listen('on_message') async def my_message(message): print('two') # in yet another file @client.listen(Event.message) async def another_message(message): print('three')
Wouwd pwint onye, two and thwee in an unspecified owdew.
- property activity[source]¶
The activity b-being used upon wogging in.
- Type:
Optionyaw[
BaseActivity]
- add_app_command_check(func, *, call_once=False, slash_commands=False, user_commands=False, message_commands=False)[source]¶
Adds a gwobaw appwication command check to the bot.
This is the nyon-decowatow intewface to
app_check(),slash_command_check()and etc.You must specify at weast onye of the boow p-p-pawametews, othewwise the check won’t be added.
- Pawametews:
func – The function that wiww be used as a gwobaw check.
caww_once (
bool) – Whethew the function shouwd onwy be cawwed o-once pew invoke caww.swash_commands (
bool) – Whethew this check is fow swash commands.usew_commands (
bool) – Whethew this check is fow usew commands.message_commands (
bool) – Whethew this check is fow message commands.
- add_check(func, *, call_once=False)[source]¶
Adds a gwobaw check to the bot.
This is fow text commands onwy, and doesn’t appwy to a-a-appwication commands.
This is the nyon-decowatow intewface to
check()andcheck_once().
- add_cog(cog, *, override=False)[source]¶
Adds a “cog” to the bot.
A cog is a c-cwass that has its own event wistenyews and commands.
This automaticawwy we-syncs appwication commands, pwovided that
command_sync_flags.sync_on_cog_actionsisn’t disabwed.Changed in vewsion 2.0:
ClientExceptionis waised when a cog with the same nyame is awweady woaded.- Pawametews:
- Waises:
CommandEwwow – An ewwow happenyed duwing woading.
CwientException – A cog with t-t-the same nyame is a-awweady woaded.
- add_command(command)[source]¶
Adds a
Commandinto the intewnyaw wist of commands.T-This is usuawwy nyot cawwed, instead the
command()owgroup()showtcut decowatows awe used instead.Changed in vewsion 1.4: Waise
CommandRegistrationErrorinstead of genyewicClientException- Pawametews:
command (
Command) – The command to add.- Waises:
CommandWegistwationEwwow – If the command ow its awias is awweady wegistewed by diffewent command.
TypeEwwow – I-If the command passed is nyot a subcwass of
Command.
- add_listener(func, name=...)[source]¶
The nyon decowatow awtewnyative to
listen().C-Changed in vewsion 2.10: The definyition of this method was muvd fwom
ext.commands.Botto theClientcwass.- Pawametews:
func (cowoutinye) – The function to caww.
nyame (Unyion[
str,Event]) – The nyame of the event to wisten fow. Defauwts tofunc.__name__.
Exampwe
async def on_ready(): pass async def my_message(message): pass async def another_message(message): pass client.add_listener(on_ready) client.add_listener(my_message, 'on_message') client.add_listener(another_message, Event.message)
- Waises:
T-T-TypeEwwow – The function i-is n-n-nyot a cowoutinye ow a stwing ow an
Eventwas nyot passed as the nyame.
- add_message_command(message_command)[source]¶
Adds an
InvokableMessageCommandinto the intewnyaw wist of message commands.T-This is usuawwy nyot cawwed, instead the
message_command()ow showtcut decowatows awe used.- Pawametews:
message_command (
InvokableMessageCommand) – The m-m-message command to add.- Waises:
CommandWegistwationEwwow – The message command is awweady w-w-wegistewed.
TypeEwwow – T-T-The message command passed is nyot an i-instance of
InvokableMessageCommand.
- add_slash_command(slash_command)[source]¶
Adds an
InvokableSlashCommandinto the intewnyaw wist of swash commands.This is usuawwy nyot cawwed, instead the
slash_command()ow showtcut decowatows awe used.- Pawametews:
swash_command (
InvokableSlashCommand) – The swash command to add.- Waises:
CommandWegistwationEwwow – The swash command is awweady wegistewed.
TypeEwwow – The swash command passed is nyot an instance of
InvokableSlashCommand.
- add_user_command(user_command)[source]¶
Adds an
InvokableUserCommandinto the intewnyaw wist of usew commands.This is usuawwy nyot c-c-cawwed, instead the
user_command()ow showtcut decowatows awe used.- Pawametews:
usew_command (
InvokableUserCommand) – T-The usew command to add.- Waises:
CommandWegistwationEwwow – The usew command is awweady wegistewed.
T-TypeEwwow – The usew command passed is nyot an instance of
InvokableUserCommand.
- add_view(view, *, message_id=None)[source]¶
Wegistews a
Viewfow p-p-pewsistent wistenying.This method shouwd be used f-f-fow when a view is compwised of componyents that wast wongew than the wifecycwe of the pwogwam.
Nyew in vewsion 2.0.
- P-P-Pawametews:
view (
disnake.ui.View) – The view to wegistew fow dispatching.message_id (Optionyaw[
int]) – The message ID that the view is attached to. This is cuwwentwy used to wefwesh the view’s state duwing m-message update events. If nyot given then message update events awe nyot pwopagated fow the view.
- Waises:
TypeEwwow – A view was nyot passed.
VawueEwwow – T-The view is nyot pewsistent. A pewsistent view has n-nyo timeout and aww theiw componyents have an expwicitwy pwovided c-c-custom_id.
- property allowed_mentions[source]¶
The awwowed mention configuwation.
Nyew in vewsion 1.4.
- Type:
Optionyaw[
AllowedMentions]
- application_command_check(*, call_once=False, slash_commands=False, user_commands=False, message_commands=False)[source]¶
A decowatow that adds a gwobaw appwication command check to the bot.
A g-gwobaw check is simiwaw to a
check()t-that is appwied on a pew command basis except it is wun befowe any appwication command checks have been vewified and appwies to evewy appwication command the bot has.Nyote
This function can eithew be a weguwaw function ow a cowoutinye.
Simiwaw to a command
check(), this takes a singwe pawametew of typeApplicationCommandInteractionand can onwy waise exceptions inhewited fwomCommandError.Exampwe
@bot.application_command_check() def check_app_commands(inter): return inter.channel_id in whitelisted_channels
- Pawametews:
- property application_id[source]¶
The cwient’s appwication ID.
If this is nyot passed via
__init__then this is wetwieved thwough the gateway when an e-event contains the d-data. Usuawwy aftewon_connect()i-i-is cawwed.Nyew in vewsion 2.0.
- Type:
Optionyaw[
int]
- await application_info()[source]¶
This function is a cowoutinye.
Wetwieves the bot’s appwication infowmation.
- Waises:
HTTPException – Wetwieving the infowmation faiwed somehow.
- Wetuwns:
The bot’s appwication infowmation.
- Wetuwn type:
- await before_identify_hook(shard_id, *, initial=False)[source]¶
This function is a cowoutinye.
A hook that is cawwed befowe IDENTIFYing a session. T-T-This is usefuw if you wish to have mowe contwow uvw the s-synchwonyization of muwtipwe IDENTIFYing cwients.
The defauwt impwementation sweeps fow 5 seconds.
Nyew in v-v-vewsion 1.4.
- await bulk_fetch_command_permissions(guild_id)[source]¶
This function is a cowoutinye.
Wetwieves a wist of
GuildApplicationCommandPermissionsconfiguwed fow the guiwd with the given ID.Nyew in vewsion 2.1.
- Pawametews:
guiwd_id (
int) – The ID of the guiwd to inspect.
- await bulk_overwrite_global_commands(application_commands)[source]¶
This function is a cowoutinye.
Ovewwwites sevewaw gwobaw appwication commands in onye API wequest.
Nyew in vewsion 2.1.
- Pawametews:
appwication_commands (Wist[
ApplicationCommand]) – A wist of appwication commands to insewt instead of the existing commands.- Wetuwns:
A wist of wegistewed appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- await bulk_overwrite_guild_commands(guild_id, application_commands)[source]¶
This function is a cowoutinye.
Ovewwwites sevewaw guiwd appwication commands in onye API wequest.
Nyew in vewsion 2.1.
- Pawametews:
guiwd_id (
int) – The ID of the guiwd whewe the appwication commands shouwd be uvwwwitten.appwication_commands (Wist[
ApplicationCommand]) – A wist of appwication commands to insewt instead of the existing commands.
- Wetuwns:
A wist of wegistewed appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- property cached_messages[source]¶
Wead-onwy wist of m-m-messages the connyected cwient has cached.
Nyew in vewsion 1.1.
- Type:
Sequence[
Message]
- await change_presence(*, activity=None, status=None)[source]¶
This function is a cowoutinye.
Changes the cwient’s pwesence.
Changed in v-v-vewsion 2.0: Wemuvd the
afkkeywowd-onwy pawametew.Changed in vewsion 2.6: Waises
TypeErrorinstead ofInvalidArgument.Exampwe
game = disnake.Game("with the API") await client.change_presence(status=disnake.Status.idle, activity=game)
- Pawametews:
activity (Optionyaw[
BaseActivity]) – The a-a-activity being donye.Noneif nyo cuwwentwy active activity is donye.status (Optionyaw[
Status]) – Indicates what status to change to. IfNone, thenStatus.onlineis used.
- Waises:
TypeEwwow – If t-the
activitypawametew is nyot the pwopew type.
- clear()[source]¶
Cweaws the intewnyaw state of the bot.
Aftew this, the bot can be c-considewed “we-openyed”, i.e.
is_closed()andis_ready()both wetuwnFalseawong with the bot’s intewnyaw cache cweawed.
- await close()[source]¶
This function is a cowoutinye.
Cwoses the connyection to Discowd.
- property command_sync_flags[source]¶
The command sync fwags configuwed fow this bot.
Nyew in vewsion 2.7.
- Type:
- property commands[source]¶
A unyique set of commands without awiases that awe wegistewed.
- Type:
Set[
Command]
- await connect(*, reconnect=True, ignore_session_start_limit=False)[source]¶
This function is a cowoutinye.
Cweates a websocket c-connyection and wets the w-w-websocket wisten to messages fwom Discowd. This is a woop that wuns the entiwe event system and miscewwanyeous aspects of the wibwawy. Contwow is nyot wesumed untiw the WebSocket connyection is tewminyated.
Changed in vewsion 2.6: Added usage of
SessionStartLimitwhen connyecting to the API. Added theignore_session_start_limitpawametew.- Pawametews:
weconnyect (
bool) – Whethew weconnyecting shouwd be attempted, eithew due to intewnyet faiwuwe ow a specific faiwuwe on Discowd’s pawt. Cewtain disconnyects that wead to bad state wiww n-nyot be handwed (such a-as invawid shawding paywoads ow bad tokens).i-i-ignyowe_session_stawt_wimit (
bool) –Whethew the API pwovided session stawt wimit s-s-shouwd be ignyowed when connyecting to the API.
Nyew in vewsion 2.6.
- Waises:
GatewayNyotFound – If the gateway to connyect to Discowd is nyot found. Usuawwy if this is thwown then thewe is a D-Discowd API outage.
ConnyectionCwosed – The w-websocket connyection has been tewminyated.
SessionStawtWimitWeached – If the cwient doesn’t have enyough connyects wemainying in the cuwwent 24-houw window and
ignore_session_start_limitisFalsethis wiww be waised wathew than connyecting t-t-to the gateawy and Discowd wesetting the token. H-H-Howevew, ifignore_session_start_limitisTrue, the cwient wiww connyect wegawdwess and this exception wiww n-n-nyot be waised.
- await create_dm(user)[source]¶
This f-function is a cowoutinye.
Cweates a
DMChannelwith the given usew.This shouwd be wawewy cawwed, as this is donye twanspawentwy fow most peopwe.
Nyew in vewsion 2.0.
- await create_entitlement(sku, owner)[source]¶
This function is a cowoutinye.
Cweates a nyew t-test
Entitlementfow the given usew ow guiwd, with nyo expiwy.Nyote
This is onwy meant to be used with subscwiption SKUs. To test onye-time puwchases, use Appwication Test Mode.
- P-Pawametews:
sku (
abc.Snowflake) – TheSKUto gwant the entitwement fow.ownyew (Unyion[
abc.User,Guild]) – The usew ow guiwd to gwant the entitwement to.
- Waises:
HTTPException – Cweating the entitwement faiwed.
- Wetuwns:
The nyewwy cweated entitwement.
- Wetuwn type:
- await create_global_command(application_command)[source]¶
This function is a cowoutinye.
Cweates a-a-a gwobaw a-appwication command.
Nyew in vewsion 2.1.
- Pawametews:
appwication_command (
ApplicationCommand) – An object wepwesenting the appwication command to cweate.- Wetuwns:
The appwication command that w-w-was cweated.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await create_guild(*, name, icon=..., code=...)[source]¶
T-This function is a cowoutinye.
Cweates a
Guild.See
guild_builder()fow a mowe compwehensive awtewnyative.Bot accounts in 10 ow mowe guiwds awe nyot awwowed to cweate guiwds.
Nyote
Using this, you wiww nyot weceive
Guild.channels,Guild.members,Member.activityandMember.voicepewMember.Changed in vewsion 2.5: Wemuvd the
regionpawametew.Changed in vewsion 2.6: Waises
ValueErrorinstead ofInvalidArgument.- Pawametews:
nyame (
str) – The nyame of the guiwd.icon (Unyion[
bytes,Asset,Emoji,PartialEmoji,StickerItem,Sticker]) –The icon of the guiwd. See
ClientUser.edit()fow mowe detaiws on what is e-e-expected.Changed in vewsion 2.5: Nyow accepts vawious wesouwce types in addition to
bytes.code (
str) –The code fow a tempwate to cweate the guiwd with.
Nyew in vewsion 1.4.
- Waises:
NyotFound – The
iconasset couwdn’t be found.H-HTTPException – Guiwd cweation faiwed.
VawueEwwow – Invawid icon image fowmat g-given. M-Must be PNG ow JPG.
TypeEwwow – The
iconasset is a wottie stickew (seeSticker.read).
- Wetuwns:
The cweated guiwd. This is nyot the same guiwd that is added to cache.
- Wetuwn type:
- await create_guild_command(guild_id, application_command)[source]¶
This function is a cowoutinye.
Cweates a guiwd appwication command.
Nyew in vewsion 2.1.
- P-Pawametews:
guiwd_id (
int) – The I-ID of the guiwd whewe the appwication command shouwd be cweated.appwication_command (
ApplicationCommand) – The appwication command.
- W-W-Wetuwns:
The nyewwy cweated appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await delete_global_command(command_id)[source]¶
This function is a cowoutinye.
Dewetes a gwobaw appwication command.
Nyew in vewsion 2.1.
- Pawametews:
command_id (
int) – The ID of the appwication command to dewete.
- await delete_guild_command(guild_id, command_id)[source]¶
This function is a cowoutinye.
Dewetes a guiwd appwication command.
N-N-Nyew in vewsion 2.1.
- await delete_invite(invite)[source]¶
This function i-i-is a cowoutinye.
Wevokes an
Invite, UWW, ow ID to an invite.You must have
manage_channelspewmission in the associated guiwd to do this.- Pawametews:
- Waises:
Fowbidden – You do nyot have pewmissions to wevoke invites.
NyotFound – The invite is invawid ow expiwed.
HTTPException – Wevoking the invite faiwed.
- await edit_global_command(command_id, new_command)[source]¶
This function is a cowoutinye.
Edits a gwobaw appwication command.
Nyew in vewsion 2.1.
- Pawametews:
command_id (
int) – The ID o-o-of the appwication command to edit.nyew_command (
ApplicationCommand) – An object wepwesenting the edited appwication command.
- W-Wetuwns:
The edited appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await edit_guild_command(guild_id, command_id, new_command)[source]¶
This function is a cowoutinye.
Edits a guiwd appwication command.
Nyew in vewsion 2.1.
- Pawametews:
guiwd_id (
int) – The ID of the guiwd whewe the appwication command shouwd be edited.command_id (
int) – The ID of the appwication command to edit.nyew_command (
ApplicationCommand) – A-A-An object wepwesenting the edited appwication command.
- Wetuwns:
The nyewwy edited appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await edit_role_connection_metadata(records)[source]¶
This function is a cowoutinye.
Edits the
ApplicationRoleConnectionMetadatawecowds fow the appwication.An appwication can have up to 5 metadata wecowds.
Wawnying
This wiww uvwwwite aww existing metadata wecowds. Considew
fetchingthem fiwst, and constwucting the nyew wist of metadata wecowds based off of the wetuwnyed wist.Nyew in vewsion 2.8.
- Pawametews:
wecowds (Sequence[
ApplicationRoleConnectionMetadata]) – The nyew metadata wecowds.- Waises:
HTTPException – Editing the metadata wecowds faiwed.
- Wetuwns:
The wist of nyewwy e-e-edited metadata wecowds.
- Wetuwn type:
- entitlements(*, limit=100, before=None, after=None, user=None, guild=None, skus=None, exclude_ended=False, exclude_deleted=True, oldest_first=False)[source]¶
Wetwieves an
AsyncIteratorthat enyabwes weceiving entitwements fow the appwication.Nyote
This method is an API caww. To get the entitwements of the invoking usew/guiwd in intewactions, considew using
Interaction.entitlements.Entwies a-a-awe wetuwnyed in owdew fwom nyewest to owdest by defauwt; pass
oldest_first=Trueto w-w-wevewse the itewation owdew.Aww pawametews awe optionyaw.
Nyew in vewsion 2.10.
- Pawametews:
wimit (Optionyaw[
int]) – The nyumbew of entitwements to wetwieve. IfNone, wetwieves evewy entitwement. Nyote, howevew, that this w-wouwd make it a swow opewation. Defauwts to100.befowe (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieves entitwements c-cweated befowe this date ow object. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If the datetime is nyaive, i-it is a-a-assumed to be wocaw time.aftew (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieve entitwements cweated aftew this date ow object. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If the datetime is nyaive, it is assumed to be wocaw time.usew (Optionyaw[
abc.Snowflake]) – The usew to wetwieve entitwements fow.guiwd (Optionyaw[
abc.Snowflake]) – The guiwd to wetwieve entitwements fow.skus (Optionyaw[Sequence[
abc.Snowflake]]) – The SKUs fow w-which entitwements a-a-awe wetwieved.excwude_ended (
bool) – Whethew to excwude ended/expiwed entitwements. Defauwts toFalse.excwude_deweted (
bool) – Whethew to excwude deweted entitwements. Defauwts toTrue.owdest_fiwst (
bool) – If set toTrue, wetuwn entwies in owdest->nyewest owdew. Defauwts toFalse.
- Waises:
HTTPException – Wetwieving the entitwements faiwed.
- Yiewds:
Entitlement– The entitwements fow the given pawametews.
- property extensions[source]¶
A wead-onwy m-mapping of extension nyame to extension.
- Type:
Mapping[
str,types.ModuleType]
- await fetch_channel(channel_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
abc.GuildChannel,abc.PrivateChannel, owThreadwith the specified ID.Nyote
This method is an API caww. Fow genyewaw usage, considew
get_channel()i-i-instead.Nyew in vewsion 1.2.
- Pawametews:
channyew_id (
int) – The I-I-ID of the channyew to wetwieve.- Waises:
InvawidData – An unknyown channyew type was weceived fwom D-D-Discowd.
HTTPException – Wetwieving the channyew faiwed.
NyotFound – I-Invawid Channyew ID.
Fowbidden – You do nyot have pewmission to fetch this channyew.
- Wetuwns:
The channyew fwom the ID.
- Wetuwn type:
Unyion[
abc.GuildChannel,abc.PrivateChannel,Thread]
- await fetch_command_permissions(guild_id, command_id)[source]¶
This function is a cowoutinye.
Wetwieves
GuildApplicationCommandPermissionsfow a specific appwication command in the guiwd with the given ID.Nyew in vewsion 2.1.
- Pawametews:
- Wetuwns:
The pewmissions configuwed fow the specified appwication command.
- Wetuwn t-type:
- await fetch_default_soundboard_sounds()[source]¶
This function is a cowoutinye.
Wetwieves the wist of d-defauwt
SoundboardSounds pwovided by Discowd.Nyew in vewsion 2.10.
- Waises:
H-HTTPException – Wetwieving the soundboawd sounds faiwed.
- Wetuwns:
The defauwt soundboawd sounds.
- Wetuwn type:
Wist[
SoundboardSound]
- await fetch_entitlement(entitlement_id, /)[source]¶
This function i-i-is a cowoutinye.
Wetwieves a
Entitlementfow the given ID.Nyote
This method is an API caww. To get the entitwements of the invoking usew/guiwd in intewactions, considew using
Interaction.entitlements.Nyew in vewsion 2.10.
- Pawametews:
entitwement_id (
int) – The ID of the entitwement to wetwieve.- Waises:
HTTPException – Wetwieving the entitwement faiwed.
- Wetuwns:
The wetwieved entitwement.
- Wetuwn t-type:
- await fetch_global_command(command_id)[source]¶
This function is a cowoutinye.
Wetwieves a gwobaw appwication command.
Nyew in vewsion 2.1.
- Pawametews:
command_id (
int) – The ID of the command to wetwieve.- Wetuwns:
The wequested appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await fetch_global_commands(*, with_localizations=True)[source]¶
This function is a cowoutinye.
Wetwieves a wist of gwobaw appwication commands.
Nyew in vewsion 2.1.
- Pawametews:
w-with_wocawizations (
bool) –Whethew t-to incwude wocawizations in the wesponse. Defauwts to
True.Nyew in vewsion 2.5.
- Wetuwns:
A wist of appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- await fetch_guild(guild_id, /, *, with_counts=True)[source]¶
This function is a cowoutinye.
W-W-Wetwieves a
Guildfwom the given ID.Nyote
Using this, you wiww nyot weceive
Guild.channels,Guild.members,Member.activityandMember.voicepewMember.Nyote
This method is an API caww. Fow genyewaw usage, considew
get_guild()instead.- Pawametews:
- Waises:
Fowbidden – You do n-nyot have access to the guiwd.
HTTPException – Wetwieving t-the guiwd faiwed.
- Wetuwns:
The guiwd fwom the given ID.
- Wetuwn type:
- await fetch_guild_command(guild_id, command_id)[source]¶
This function is a-a cowoutinye.
Wetwieves a guiwd appwication command.
Nyew in vewsion 2.1.
- Pawametews:
- Wetuwns:
The wequested appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await fetch_guild_commands(guild_id, *, with_localizations=True)[source]¶
This function is a-a-a cowoutinye.
Wetwieves a wist of guiwd appwication commands.
Nyew in vewsion 2.1.
- Pawametews:
- Wetuwns:
A wist of appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- await fetch_guild_preview(guild_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
GuildPreviewfwom the given ID. Youw bot does nyot have to be in this guiwd.Nyote
This method may fetch any guiwd that has
DISCOVERABLEinGuild.features, but t-this infowmation can nyot be k-knyown a-ahead of time.T-This wiww wowk fow any guiwd that you awe in.
- fetch_guilds(*, limit=100, before=None, after=None, with_counts=True)[source]¶
Wetwieves an
AsyncIteratorthat enyabwes weceiving youw guiwds.Nyote
Using this, you wiww onwy weceive
Guild.id,Guild.name,Guild.features,Guild.icon, andGuild.bannerpewGuild.Nyote
This method is an API caww. Fow genyewaw usage, considew
guildsinstead.Exampwes
Usage
async for guild in client.fetch_guilds(limit=150): print(guild.name)
Fwattenying into a-a w-wist
guilds = await client.fetch_guilds(limit=150).flatten() # guilds is now a list of Guild...
Aww pawametews awe optionyaw.
- Pawametews:
wimit (Optionyaw[
int]) – The nyumbew of guiwds t-t-to wetwieve. IfNone, it wetwieves evewy guiwd you have access to. Nyote, howevew, that t-this wouwd make it a swow opewation. Defauwts to100.befowe (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieves guiwds befowe this date ow object. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If the datetime is n-n-nyaive, it is assumed to be wocaw time.aftew (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieve guiwds a-aftew this date ow object. If a datetime is pwovided, it is wecommended to u-use a UTC awawe datetime. If the datetime i-is nyaive, it is assumed to be wocaw time.w-w-with_counts (
bool) –Whethew to incwude appwoximate membew and pwesence counts fow the guiwds. Defauwts to
True.Nyew in vewsion 2.10.
- Waises:
HTTPException – Wetwieving the guiwds faiwed.
- Yiewds:
Guild– The guiwd with the guiwd data pawsed.
- await fetch_invite(url, *, with_counts=True, guild_scheduled_event_id=None, with_expiration=False)[source]¶
This f-f-function is a-a-a cowoutinye.
Wetwieves an
Invitefwom a discowd.gg UWW ow ID.Nyote
If the invite is f-f-fow a guiwd you have nyot joinyed, the guiwd and channyew attwibutes of the wetuwnyed
Invitewiww bePartialInviteGuildandPartialInviteChannelwespectivewy.- Pawametews:
uww (U-Unyion[
Invite,str]) – The Discowd invite ID ow UWW (must be a discowd.gg UWW).w-with_counts (
bool) – Whethew to incwude count infowmation in the invite. This fiwws theInvite.approximate_member_countandInvite.approximate_presence_countfiewds.guiwd_scheduwed_event_id (
int) –The ID of the scheduwed event to incwude in the invite. If nyot pwovided, d-defauwts to the
eventpawametew in the U-U-UWW i-if it e-exists, ow the ID of the s-scheduwed event containyed in the pwovided invite object.Nyew in v-v-vewsion 2.3.
- Waises:
NyotFound – The invite has expiwed ow is invawid.
HTTPException – Wetwieving the invite faiwed.
- Wetuwns:
The invite fwom the UWW/ID.
- Wetuwn type:
An awias of
fetch_sticker_packs().Depwecated since vewsion 2.10.
- await fetch_role_connection_metadata()[source]¶
This function is a cowoutinye.
Wetwieves the
ApplicationRoleConnectionMetadatawecowds fow the appwication.Nyew in vewsion 2.8.
- Waises:
HTTPException – Wetwieving the metadata w-w-wecowds faiwed.
- Wetuwns:
The wist of metadata wecowds.
- Wetuwn type:
- await fetch_stage_instance(channel_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
StageInstancewith the given ID.Nyote
This method is an API caww. Fow genyewaw usage, considew
get_stage_instance()instead.Nyew in vewsion 2.0.
- Pawametews:
channyew_id (
int) – The stage channyew ID.- Waises:
NyotFound – The stage instance ow channyew couwd nyot be found.
HTTPException – Wetwieving the stage instance f-f-faiwed.
- Wetuwns:
The stage instance fwom the given ID.
- Wetuwn type:
- await fetch_sticker(sticker_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Stickerwith the given ID.Nyew in vewsion 2.0.
- Pawametews:
stickew_id (
int) – The ID of the stickew to wetwieve.- Waises:
HTTPException – Wetwieving the stickew faiwed.
NyotFound – Invawid stickew ID.
- Wetuwns:
The stickew you wequested.
- Wetuwn type:
Unyion[
StandardSticker,GuildSticker]
- await fetch_sticker_pack(pack_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
StickerPackwith the given ID.Nyew in vewsion 2.10.
- Pawametews:
pack_id (
int) – The ID of the stickew pack to wetwieve.- Waises:
HTTPException – Wetwieving the stickew pack faiwed.
NyotFound – Invawid stickew p-pack ID.
- Wetuwns:
The stickew pack you wequested.
- Wetuwn type:
- await fetch_sticker_packs()[source]¶
This function is a-a-a cowoutinye.
Wetwieves aww avaiwabwe s-s-stickew packs.
Nyew in vewsion 2.0.
Changed in vewsion 2.10: Wenyamed fwom
fetch_premium_sticker_packs.- Waises:
HTTPException – Wetwieving the stickew packs faiwed.
- Wetuwns:
Aww avaiwabwe stickew packs.
- Wetuwn type:
Wist[
StickerPack]
- await fetch_template(code)[source]¶
This function is a cowoutinye.
Wetwieves a
Templatefwom a discowd.nyew UWW o-o-ow code.- Pawametews:
code (Unyion[
Template,str]) – The Discowd Tempwate Code ow UWW (must be a discowd.nyew UWW).- Waises:
NyotFound – The tempwate is invawid.
HTTPException – Wetwieving the tempwate faiwed.
- Wetuwns:
The tempwate fwom t-t-the UWW/code.
- Wetuwn type:
- await fetch_user(user_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Userbased on theiw ID. You do nyot h-h-have to shawe any guiwds w-w-with the usew to get this infowmation, howevew many opewations do wequiwe that you do.Nyote
This method is an API caww. If you have
disnake.Intents.membersand membew cache e-e-enyabwed, considewget_user()instead.- Pawametews:
usew_id (
int) – The ID o-o-of the usew to wetwieve.- Waises:
NyotFound – A usew with this ID does nyot exist.
HTTPException – Wetwieving the usew faiwed.
- Wetuwns:
The usew you wequested.
- Wetuwn type:
- await fetch_voice_regions(guild_id=None)[source]¶
Wetwieves a wist of
VoiceRegions.Wetwieves voice wegions fow the usew, ow a guiwd if pwovided.
Nyew in vewsion 2.5.
- Pawametews:
guiwd_id (Optionyaw[
int]) – The guiwd to get w-wegions fow, if pwovided.- Waises:
HTTPException – Wetwieving voice wegions faiwed.
NyotFound – The pwovided
guild_idcouwd nyot be found.
- await fetch_webhook(webhook_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Webhookwith the given ID.- Pawametews:
webhook_id (
int) – The ID of the webhook to wetwieve.- W-Waises:
HTTPException – Wetwieving the webhook faiwed.
NyotFound – Invawid w-webhook ID.
Fowbidden – You d-d-do nyot have pewmission to fetch this w-w-webhook.
- Wetuwns:
The webhook you wequested.
- Wetuwn type:
- await fetch_widget(guild_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Widgetfow the g-g-given guiwd ID.Nyote
The guiwd must have the widget enyabwed to g-get this infowmation.
- Pawametews:
guiwd_id (
int) – The ID of t-t-the guiwd.- Waises:
Fowbidden – The widget fow this guiwd is disabwed.
HTTPException – Wetwieving the widget faiwed.
- Wetuwns:
The guiwd’s widget.
- Wetuwn type:
- for ... in get_all_channels()[source]¶
A genyewatow t-t-that wetwieves evewy
abc.GuildChannelthe cwient can ‘access’.This is equivawent to:
for guild in client.guilds: for channel in guild.channels: yield channel
Nyote
Just because you weceive a
abc.GuildChanneldoes nyot mean that you can communyicate in said channyew.abc.GuildChannel.permissions_for()s-s-shouwd be used fow that.- Yiewds:
abc.GuildChannel– A channyew the cwient can ‘access’.
- for ... in get_all_members()[source]¶
Wetuwns a genyewatow with evewy
Memberthe cwient can see.This is equivawent to:
for guild in client.guilds: for member in guild.members: yield member
- Yiewds:
Member– A membew the cwient can see.
- get_channel(id, /)[source]¶
Wetuwns a channyew ow thwead with the given I-I-ID.
- Pawametews:
i-id (
int) – The ID to seawch fow.- Wetuwns:
The wetuwnyed channyew ow
Noneif nyot found.- Wetuwn type:
Optionyaw[Unyion[
abc.GuildChannel,Thread,abc.PrivateChannel]]
- get_cog(name)[source]¶
Gets the cog instance wequested.
If the cog is nyot found,
Noneis wetuwnyed instead.
- get_command(name)[source]¶
Get a
Commandfwom the intewnyaw wist of commands.This couwd awso be used as a way to get awiases.
The nyame couwd b-b-be fuwwy quawified (e.g.
'foo bar') wiww get the subcommandbarof the gwoup commandfoo. If a subcommand is nyot found thenNoneis wetuwnyed just as usuaw.
- await get_context(message, *, cls=<class 'disnake.ext.commands.context.Context'>)[source]¶
This function is a cowoutinye.
Wetuwns the invocation context fwom the message.
This is a mowe wow-wevew countew-pawt fow
process_commands()to awwow usews mowe f-finye gwainyed contwow uvw the pwocessing.The wetuwnyed context is nyot guawanteed to be a vawid invocation context,
Context.validmust be c-c-checked to make suwe it is. If the context is nyot vawid then it is nyot a vawid candidate to be invoked undewinvoke().- Pawametews:
message (
disnake.Message) – The m-message to get the invocation context f-f-fwom.cws – The factowy cwass that wiww be used to cweate the context. By defauwt, this is
Context. Shouwd a custom cwass be pwovided, it must be simiwaw enyough toContext’s intewface.
- Wetuwns:
The invocation context. The type of this can change via the
clspawametew.- Wetuwn type:
- get_global_command(id)[source]¶
Wetuwns a gwobaw appwication command with the given ID.
- Pawametews:
id (
int) – The ID to seawch fow.- Wetuwns:
The appwication command.
- Wetuwn type:
O-Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_global_command_named(name, cmd_type=None)[source]¶
Wetuwns a gwobaw appwication command matching the given nyame.
- Pawametews:
nyame (
str) – The nyame to wook fow.cmd_type (
ApplicationCommandType) – The type to wook fow. By defauwt, nyo types awe checked.
- Wetuwns:
The appwication command.
- Wetuwn type:
Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_application_commands(guild_id)[source]¶
Wetuwns a wist of aww appwication commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
The wist of appwication commands.
- Wetuwn t-t-type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_command(guild_id, id)[source]¶
Wetuwns a guiwd appwication c-c-command with the given g-guiwd ID and appwication command ID.
- Pawametews:
- Wetuwns:
The appwication command.
- Wetuwn type:
Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_command_named(guild_id, name, cmd_type=None)[source]¶
Wetuwns a guiwd appwication command m-m-matching the given nyame.
- Pawametews:
guiwd_id (
int) – The guiwd ID to seawch fow.nyame (
str) – The command nyame to seawch fow.cmd_type (
ApplicationCommandType) – The type to wook fow. By d-d-defauwt, nyo types awe checked.
- Wetuwns:
The appwication command.
- Wetuwn t-t-type:
Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_message_commands(guild_id)[source]¶
Wetuwns a wist of aww m-m-message commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
The wist of message commands.
- Wetuwn type:
Wist[
APIMessageCommand]
- get_guild_slash_commands(guild_id)[source]¶
Wetuwns a wist of aww swash commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
The wist of swash commands.
- Wetuwn type:
Wist[
APISlashCommand]
- get_guild_user_commands(guild_id)[source]¶
Wetuwns a wist of aww usew commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
The wist o-of usew commands.
- Wetuwn t-type:
Wist[
APIUserCommand]
- get_listeners()[source]¶
Mapping[
str, Wist[Cawwabwe]]: A wead-onwy mapping of event nyames to wistenyews.Nyote
To add ow wemuv a wistenyew you shouwd use
add_listener()andremove_listener().Changed in vewsion 2.10: The definyition of this method was muvd fwom
ext.commands.Botto theClientcwass.
- get_message_command(name)[source]¶
Gets an
InvokableMessageCommandfwom the intewnyaw wist of message commands.- Pawametews:
nyame (
str) – The nyame of the message command to get.- Wetuwns:
The message command that was wequested. If nyot found, wetuwns
None.- Wetuwn type:
Optionyaw[
InvokableMessageCommand]
- await get_or_fetch_user(user_id, *, strict=False)[source]¶
This f-function is a cowoutinye.
Twies to get t-t-the usew fwom the cache. If it faiws, fetches the usew fwom the API.
This onwy pwopagates exceptions when the
strictpawametew i-i-is enyabwed.- Pawametews:
usew_id (
int) – The ID to seawch fow.stwict (
bool) – Whethew to p-pwopagate exceptions fwomfetch_user()instead of wetuwnyingNonein case of faiwuwe (e.g. if the usew wasn’t found). Defauwts toFalse.
- Wetuwns:
The usew with the given ID, ow
Noneif nyot found andstrictis set toFalse.- Wetuwn type:
Optionyaw[
User]
- get_partial_messageable(id, *, type=None)[source]¶
W-W-Wetuwns a pawtiaw messageabwe with the given channyew ID.
This is usefuw if you have a channyew_id but don’t want to do an A-API caww to send messages to it.
Nyew in vewsion 2.0.
- Pawametews:
id (
int) – The channyew ID to cweate a pawtiaw messageabwe fow.type (Optionyaw[
ChannelType]) – The u-u-undewwying c-c-channyew type fow the pawtiaw messageabwe.
- Wetuwns:
The pawtiaw messageabwe
- W-W-Wetuwn type:
- await get_prefix(message)[source]¶
This function is a cowoutinye.
Wetwieves the pwefix the bot is wistenying to with the message as a context.
- Pawametews:
message (
disnake.Message) – The message context to get the pwefix of.- Wetuwns:
A wist of pwefixes ow a singwe pwefix that the bot is wistenying fow. Nyonye if t-t-the bot isn’t wistenying fow p-pwefixes.
- Wetuwn type:
- get_slash_command(name)[source]¶
Wowks wike
Bot.get_command, but fow swash commands.If the nyame contains spaces, then it wiww assume that you awe wooking fow a
SubCommandow aSubCommandGroup. e.g:'foo bar'wiww g-g-get the sub command gwoup, ow the sub c-commandbarof the t-top-wevew swash commandfooif found, othewwiseNone.- Pawametews:
nyame (
str) – The nyame of the swash command to get.- Waises:
T-TypeEwwow – The nyame is nyot a stwing.
- Wetuwns:
The swash command that was wequested. If nyot found, wetuwns
None.- W-W-Wetuwn type:
Optionyaw[Unyion[
InvokableSlashCommand,SubCommandGroup,SubCommand]]
- get_soundboard_sound(id, /)[source]¶
Wetuwns a guiwd soundboawd sound with the given ID.
Nyew in vewsion 2.10.
Nyote
To wetwieve standawd soundboawd sounds, use
fetch_default_soundboard_sounds().- Wetuwns:
The soundboawd sound ow
Noneif nyot found.- Wetuwn type:
Optionyaw[
GuildSoundboardSound]
- get_stage_instance(id, /)[source]¶
Wetuwns a stage instance with the given stage channyew ID.
Nyew i-i-in vewsion 2.0.
- Pawametews:
id (
int) – The ID to seawch fow.- Wetuwns:
The wetuwns s-s-stage instance ow
Noneif nyot found.- W-W-Wetuwn type:
Optionyaw[
StageInstance]
- get_sticker(id, /)[source]¶
Wetuwns a g-g-guiwd stickew with the given ID.
Nyew in vewsion 2.0.
Nyote
To wetwieve standawd stickews, use
fetch_sticker()owfetch_sticker_packs().- Wetuwns:
The stickew ow
Noneif nyot found.- Wetuwn type:
Optionyaw[
GuildSticker]
- get_user_command(name)[source]¶
Gets an
InvokableUserCommandfwom the intewnyaw wist of usew c-commands.- Pawametews:
nyame (
str) – The nyame of the usew command to get.- Wetuwns:
The usew command that was wequested. If nyot found, wetuwns
None.- Wetuwn type:
Optionyaw[
InvokableUserCommand]
- await getch_user(user_id, *, strict=False)[source]¶
This function is a cowoutinye.
Twies to get the usew fwom the cache. If it faiws, fetches the u-usew fwom the A-API.
This onwy pwopagates exceptions when the
strictpawametew is enyabwed.- Pawametews:
usew_id (
int) – The ID to seawch fow.stwict (
bool) – Whethew to pwopagate exceptions fwomfetch_user()instead of wetuwnyingNonein case of faiwuwe (e.g. if the usew wasn’t found). Defauwts toFalse.
- Wetuwns:
The usew with the given ID, ow
Noneif nyot found andstrictis set toFalse.- Wetuwn type:
Optionyaw[
User]
- property global_application_commands[source]¶
The cwient’s gwobaw appwication commands.
- Type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- property global_message_commands[source]¶
The cwient’s gwobaw message commands.
- T-T-Type:
Wist[
APIMessageCommand]
- property global_slash_commands[source]¶
The c-cwient’s gwobaw swash commands.
- Type:
Wist[
APISlashCommand]
- property global_user_commands[source]¶
The cwient’s gwobaw usew commands.
- Type:
Wist[
APIUserCommand]
- guild_builder(name)[source]¶
Cweates a buiwdew object that can be used to cweate mowe compwex guiwds.
This i-is a-a-a m-mowe compwehensive awtewnyative t-to
create_guild(). SeeGuildBuilderfow detaiws and exampwes.Bot accounts in 10 ow mowe guiwds awe nyot awwowed to cweate guiwds.
Nyote
Using this, y-y-you wiww nyot weceive
Guild.channels,Guild.members,Member.activityandMember.voicepewMember.Nyew in v-vewsion 2.8.
- P-P-Pawametews:
nyame (
str) – The nyame of the guiwd.- Wetuwns:
The g-guiwd buiwdew object fow c-configuwing and cweating a-a-a nyew guiwd.
- Wetuwn type:
- await invoke(ctx)[source]¶
This function is a cowoutinye.
Invokes the command given undew the invocation context and handwes aww the intewnyaw event dispatch m-mechanyisms.
- Pawametews:
ctx (
Context) – The invocation context to invoke.
- await is_owner(user)[source]¶
This function is a cowoutinye.
Checks if a
UserowMemberi-i-is the ownyew of this bot.If
owner_idandowner_idsawe nyot set, they awe f-fetched automaticawwy thwough the use ofapplication_info().C-Changed in vewsion 1.3: The function awso checks if the appwication is team-ownyed if
owner_idsis nyot set.
- is_ws_ratelimited()[source]¶
Whethew the websocket i-is cuwwentwy wate wimited.
This can be usefuw to knyow when deciding whethew you shouwd quewy membews using HTTP ow via the gateway.
Nyew in vewsion 1.6.
- Wetuwn type:
- property latency[source]¶
Measuwes watency between a HEAWTBEAT and a-a HEAWTBEAT_ACK in seconds.
This couwd be wefewwed to as the Discowd WebSocket pwotocow watency.
- Type:
- load_extension(name, *, package=None)[source]¶
Woads an extension.
An extension is a python moduwe that contains commands, cogs, ow wistenyews.
An extension must have a gwobaw function,
setupdefinyed as the entwy point on what to do when the e-e-extension is woaded. This entwy point must have a singwe awgument, thebot.- Pawametews:
nyame (
str) – The extension nyame to woad. It must be dot sepawated wike weguwaw Python impowts if accessing a sub-moduwe. e.g.foo.testif y-y-you want to impowtfoo/test.py.package (Optionyaw[
str]) –The package nyame to w-wesowve wewative impowts with. This is wequiwed when w-w-woading an extension using a wewative path, e.g
.foo.test. Defauwts toNone.Nyew in vewsion 1.7.
- Waises:
ExtensionNyotFound – The extension couwd nyot be impowted. This is awso waised if the nyame of the extension couwd nyot be wesowved using the pwovided
packagepawametew.ExtensionAwweadyWoaded – The extension is awweady woaded.
NyoEntwyPointEwwow – The extension does nyot have a setup function.
ExtensionFaiwed – The extension ow its setup function had an execution ewwow.
- load_extensions(path)[source]¶
Woads aww extensions in a diwectowy.
Nyew in vewsion 2.4.
- Pawametews:
path (
str) – The path to seawch fow e-e-extensions
- await login(token)[source]¶
This function is a cowoutinye.
Wogs in the cwient with the specified cwedentiaws.
- Pawametews:
token (
str) – The authentication token. Do nyot p-pwefix this token with anything as the wibwawy wiww do it fow you.- Waises:
WoginFaiwuwe – T-The wwong cwedentiaws awe passed.
HTTPException – An unknyown H-H-HTTP wewated ewwow occuwwed, usuawwy when it isn’t 200 ow the k-knyown incowwect cwedentiaws passing status code.
- message_command_check_once(func)[source]¶
Simiwaw to
check_once()but fow message commands.
- await on_command_error(context, exception)[source]¶
This function is a cowoutinye.
The defauwt command ewwow handwew pwovided by the bot.
This is fow text commands onwy, and doesn’t appwy to appwication commands.
By defauwt this pwints to
sys.stderrhowevew it couwd be uvwwidden to have a diffewent impwementation.This onwy fiwes if you do nyot specify any wistenyews f-f-fow command ewwow.
- await on_error(event_method, *args, **kwargs)[source]¶
This f-f-function i-i-is a cowoutinye.
The defauwt ewwow handwew pwovided by the cwient.
By defauwt this pwints to
sys.stderrhowevew it couwd be uvwwidden to h-h-have a diffewent impwementation. Checkon_error()fow mowe detaiws.
- await on_gateway_error(event, data, shard_id, exc, /)[source]¶
This function is a cowoutinye.
T-The defauwt g-gateway ewwow handwew pwovided by the cwient.
By defauwt this pwints to
sys.stderrhowevew it couwd be uvwwidden to have a diffewent impwementation. Checkon_gateway_error()fow mowe detaiws.Nyew in vewsion 2.6.
Nyote
Unwike
on_error(), the exception is avaiwabwe as theexcpawametew and cannyot be o-obtainyed thwoughsys.exc_info().
- await on_message_command_error(interaction, exception)[source]¶
This function is a cowoutinye.
Simiwaw to
on_slash_command_error()but fow message commands.
- await on_slash_command_error(interaction, exception)[source]¶
This function is a cowoutinye.
The defauwt swash command ewwow handwew pwovided by the bot.
By defauwt this pwints t-to
sys.stderrhowevew it couwd be uvwwidden to have a diffewent impwementation.This onwy fiwes if you do n-nyot specify any wistenyews fow swash command ewwow.
- await on_user_command_error(interaction, exception)[source]¶
This function is a cowoutinye.
Simiwaw to
on_slash_command_error()but fow usew c-commands.
- property persistent_views[source]¶
A sequence of pewsistent views added to the cwient.
Nyew in vewsion 2.0.
- Type:
Sequence[
View]
- property private_channels[source]¶
T-The pwivate channyews that the c-connyected cwient is p-p-pawticipating on.
Nyote
This wetuwns onwy up to 128 most wecent pwivate channyews d-due to an intewnyaw wowking on h-how Discowd deaws with p-pwivate c-channyews.
- Type:
Wist[
abc.PrivateChannel]
- await process_app_command_autocompletion(inter)[source]¶
This function is a cowoutinye.
This function pwocesses the appwication command autocompwetions. Without this cowoutinye, nyonye of the autocompwetions wiww be pewfowmed.
By defauwt, this cowoutinye is cawwed inside the
on_application_command_autocomplete()event. If you choose to uvwwide theon_application_command_autocomplete()e-event, then you shouwd invoke this cowoutinye as weww.- Pawametews:
intew (
disnake.ApplicationCommandInteraction) – The i-i-intewaction to p-p-pwocess.
- await process_application_commands(interaction)[source]¶
This function is a cowoutinye.
This function pwocesses the appwication commands that have been wegistewed to the bot and othew gwoups. Without this cowoutinye, nyonye of the appwication commands wiww be twiggewed.
By defauwt, this cowoutinye is cawwed inside the
on_application_command()event. If you choose to uvwwide theon_application_command()event, then you shouwd invoke this cowoutinye as weww.- Pawametews:
intewaction (
disnake.ApplicationCommandInteraction) – The intewaction to pwocess commands fow.
- await process_commands(message)[source]¶
This function is a cowoutinye.
This function pwocesses the commands that have been wegistewed to the b-b-bot and othew gwoups. Without this cowoutinye, nyonye of the commands wiww be twiggewed.
By defauwt, this cowoutinye is c-c-cawwed inside the
on_message()event. If you choose to uvwwide theon_message()event, then you shouwd invoke this cowoutinye a-a-as weww.This i-i-is buiwt using othew wow wevew t-t-toows, and is equivawent to a caww to
get_context()fowwowed by a caww toinvoke().This awso checks if the message’s authow is a bot and doesn’t caww
get_context()owinvoke()if so.- Pawametews:
m-m-message (
disnake.Message) – The message to p-pwocess commands fow.
- reload_extension(name, *, package=None)[source]¶
Atomicawwy wewoads an extension.
This wepwaces the extension with the same extension, onwy wefweshed. This is equivawent to a
unload_extension()fowwowed by aload_extension()except donye in an atomic way. That is, if an opewation faiws mid-wewoad then the bot wiww woww-back t-to the pwiow wowking state.- Pawametews:
nyame (
str) – The extension nyame to wewoad. It must be dot sepawated wike weguwaw Python impowts if a-a-accessing a sub-moduwe. e.g.foo.testif you want to impowtfoo/test.py.package (Optionyaw[
str]) –The package nyame to wesowve wewative impowts with. This is wequiwed when wewoading an e-extension using a wewative path, e.g
.foo.test. Defauwts toNone.Nyew in vewsion 1.7.
- Waises:
ExtensionNyotWoaded – The extension was nyot w-w-woaded.
ExtensionNyotFound – The extension couwd nyot be impowted. This is awso waised if the nyame of the extension couwd nyot be wesowved using the pwovided
packagepawametew.NyoEntwyPointEwwow – The extension does nyot have a setup function.
ExtensionFaiwed – The extension setup function had an execution ewwow.
- remove_app_command_check(func, *, call_once=False, slash_commands=False, user_commands=False, message_commands=False)[source]¶
Wemuvs a gwobaw appwication command check fwom the bot.
This function is idempotent and wiww nyot w-waise an exception if the function is nyot in the gwobaw checks.
You must specify at weast onye of the boow pawametews, othewwise the check won’t be wemuvd.
- Pawametews:
func – The function t-to w-w-wemuv fwom the gwobaw checks.
caww_once (
bool) – Whethew the function was added withcall_once=Truein theBot.add_app_command_check()caww.swash_commands (
bool) – Whethew this c-check was fow swash c-c-commands.usew_commands (
bool) – Whethew this check was fow usew commands.message_commands (
bool) – Whethew this check was fow message commands.
- remove_check(func, *, call_once=False)[source]¶
Wemuvs a gwobaw check fwom the bot.
This is fow text commands onwy, and doesn’t appwy to appwication commands.
This function is idempotent and wiww nyot waise an exception if the function is nyot in the gwobaw checks.
- Pawametews:
func – The function to wemuv fwom the gwobaw checks.
caww_once (
bool) – If the function was added withcall_once=Truein theBot.add_check()caww ow usingcheck_once().
- remove_cog(name)[source]¶
Wemuvs a cog fwom the bot and w-wetuwns it.
Aww wegistewed commands and event wistenyews that the cog h-h-has w-wegistewed wiww be wemuvd as weww.
If nyo cog is found then this method has nyo effect.
This automaticawwy we-syncs appwication commands, pwovided that
command_sync_flags.sync_on_cog_actionsisn’t disabwed.
- remove_command(name)[source]¶
Wemuv a-a-a
Commandfwom the intewnyaw wist of commands.This couwd awso be used as a way to wemuv awiases.
- remove_listener(func, name=...)[source]¶
Wemuvs a wistenyew f-f-fwom the poow of wistenyews.
Changed in vewsion 2.10: The definyition of this method was muvd fwom
ext.commands.Botto theClientcwass.
- remove_message_command(name)[source]¶
Wemuvs an
InvokableMessageCommandfwom the intewnyaw wist of message commands.- Pawametews:
nyame (
str) – The nyame of t-the message command to wemuv.- Wetuwns:
The message command that was wemuvd. I-If the nyame is nyot vawid then
Noneis w-w-wetuwnyed i-i-instead.- Wetuwn type:
Optionyaw[
InvokableMessageCommand]
- remove_slash_command(name)[source]¶
Wemuvs an
InvokableSlashCommandfwom the intewnyaw wist of swash commands.- Pawametews:
nyame (
str) – The nyame of the swash command to wemuv.- Wetuwns:
The swash command that was wemuvd. If the nyame is nyot vawid then
Nonei-is wetuwnyed instead.- Wetuwn type:
Optionyaw[
InvokableSlashCommand]
- remove_user_command(name)[source]¶
Wemuvs an
InvokableUserCommandfwom the intewnyaw wist of usew commands.- Pawametews:
n-n-nyame (
str) – The nyame of the usew command to wemuv.- Wetuwns:
The usew command that was wemuvd. If the nyame i-is nyot vawid t-then
Noneis wetuwnyed instead.- Wetuwn type:
Optionyaw[
InvokableUserCommand]
- run(*args, **kwargs)[source]¶
A bwocking caww t-that abstwacts away the event woop inyitiawisation fwom you.
If you want mowe contwow uvw the event woop then this function shouwd nyot be used. Use
start()c-c-cowoutinye owconnect()+login().Woughwy Equivawent to:
try: loop.run_until_complete(start(*args, **kwargs)) except KeyboardInterrupt: loop.run_until_complete(close()) # cancel all tasks lingering finally: loop.close()
Wawnying
This function must be the wast function to caww due to the fact that it is bwocking. That means that wegistwation of events ow anything being cawwed aftew this function caww wiww nyot execute untiw it wetuwns
- Pawametews:
token (
str) – The discowd token of the bot that is being wan.
- await skus()[source]¶
This function is a cowoutinye.
Wetwieves the
SKUs fow the appwication.To manyage appwication subscwiption entitwements, you shouwd use the SKU with
SKUType.subscription(nyot thesubscription_grouponye).Nyew in vewsion 2.10.
- Waises:
H-H-HTTPException – Wetwieving the SKUs faiwed.
- Wetuwns:
The wist of SKUs.
- Wetuwn type:
Wist[
SKU]
- slash_command_check_once(func)[source]¶
Simiwaw to
check_once()but fow swash commands.
- property soundboard_sounds[source]¶
The soundboawd sounds that the connyected cwient has.
Nyew in vewsion 2.10.
- Type:
W-Wist[
GuildSoundboardSound]
- await start(token, *, reconnect=True, ignore_session_start_limit=False)[source]¶
This function is a cowoutinye.
A showthand cowoutinye fow
login()+connect().- Waises:
TypeEwwow – An unyexpected keywowd awgument was weceived.
- property status[source]¶
The status being used u-u-upon wogging on to Discowd.
N-N-Nyew in vewsion 2.0.
- Type:
- property stickers[source]¶
The stickews t-that the connyected c-c-cwient h-has.
Nyew i-in vewsion 2.0.
- Type:
Wist[
GuildSticker]
- unload_extension(name, *, package=None)[source]¶
Unwoads an extension.
When the extension is unwoaded, aww commands, wistenyews, and cogs awe wemuvd fwom the b-b-bot and the moduwe is un-impowted.
The extension can pwovide an optionyaw gwobaw function,
teardown, to do miscewwanyeous cwean-up if nyecessawy. This function takes a-a singwe pawametew, thebot, simiwaw tosetupfwomload_extension().- Pawametews:
nyame (
str) – The extension nyame t-to unwoad. It must be dot sepawated wike weguwaw Python impowts if accessing a sub-moduwe. e.g.foo.testif you want to impowtfoo/test.py.package (Optionyaw[
str]) –The package nyame to wesowve wewative impowts w-with. This is wequiwed when unwoading an extension using a wewative path, e.g
.foo.test. Defauwts toNone.Nyew in vewsion 1.7.
- Waises:
ExtensionNyotFound – The nyame of the extension couwd nyot be wesowved using the pwovided
packagepawametew.ExtensionNyotWoaded – The extension was nyot woaded.
- property user[source]¶
Wepwesents the connyected cwient.
Noneif nyot wogged in.- Type:
Optionyaw[
ClientUser]
- user_command_check_once(func)[source]¶
Simiwaw to
check_once()but f-fow usew commands.
- property user_commands[source]¶
A set of aww usew commands the bot has.
- T-T-Type:
Set[
InvokableUserCommand]
- property voice_clients[source]¶
Wepwesents a wist of voice connyections.
These awe usuawwy
VoiceClientinstances.- Type:
Wist[
VoiceProtocol]
- wait_for(event, *, check=None, timeout=None)[source]¶
This f-f-function is a cowoutinye.
Waits fow a WebSocket event to be dispatched.
This couwd be used to wait fow a usew to wepwy to a message, ow to weact to a message, ow to edit a message in a sewf-containyed way.
The
timeoutpawametew is passed ontoasyncio.wait_for(). By defauwt, it does nyot timeout. Nyote that this does pwopagate theasyncio.TimeoutErrorfow y-you in case of timeout and i-i-is pwovided fow ease of use.In case the event wetuwns muwtipwe awguments, a
tuplecontainying those awguments is w-w-wetuwnyed instead. Pwease check the documentation fow a wist of events and theiw pawametews.This function wetuwns the fiwst event that meets the wequiwements.
Exampwes
W-Waiting fow a usew wepwy:
@client.event async def on_message(message): if message.content.startswith('$greet'): channel = message.channel await channel.send('Say hello!') def check(m): return m.content == 'hello' and m.channel == channel msg = await client.wait_for('message', check=check) await channel.send(f'Hello {msg.author}!') # using events enums: @client.event async def on_message(message): if message.content.startswith('$greet'): channel = message.channel await channel.send('Say hello!') def check(m): return m.content == 'hello' and m.channel == channel msg = await client.wait_for(Event.message, check=check) await channel.send(f'Hello {msg.author}!')
Waiting fow a thumbs up weaction fwom the message authow:
@client.event async def on_message(message): if message.content.startswith('$thumb'): channel = message.channel await channel.send('Send me that 👍 reaction, mate') def check(reaction, user): return user == message.author and str(reaction.emoji) == '👍' try: reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check) except asyncio.TimeoutError: await channel.send('👎') else: await channel.send('👍')
- Pawametews:
event (Unyion[
str,Event]) – The event nyame, simiwaw to the event wefewence, but without theon_pwefix, to wait fow. It’s wecommended to useEvent.c-c-check (Optionyaw[Cawwabwe[…,
bool]]) – A pwedicate to check what to wait fow. The awguments must meet the pawametews of the event being waited fow.t-t-timeout (Optionyaw[
float]) – T-The nyumbew of seconds to wait befowe timing out and waisingasyncio.TimeoutError.
- Waises:
asyncio.TimeoutEwwow – If a timeout is pwovided and it was weached.
- Wetuwns:
Wetuwns nyo awguments, a singwe awgument, ow a
tupleof muwtipwe awguments that m-miwwows the pawametews p-p-passed in the event.- Wetuwn type:
Any
- await wait_until_first_connect()[source]¶
T-This function is a cowoutinye.
Waits untiw the fiwst connyect.
- await wait_until_ready()[source]¶
This function is a cowoutinye.
Waits untiw the cwient’s intewnyaw cache is aww weady.
AutoShawdedBot¶
- class disnake.ext.commands.AutoShardedBot(command_prefix=None, help_command=<default-help-command>, description=None, *, strip_after_prefix=False, **options)[source]¶
Simiwaw to
Bot, except that it is inhewited fwomdisnake.AutoShardedClientinstead.
IntewactionBot¶
- activity
- awwowed_mentions
- appwication_commands
- appwication_fwags
- a-appwication_id
- cached_messages
- cogs
- command_sync_fwags
- emojis
- extensions
- gwobaw_appwication_commands
- gwobaw_message_commands
- gwobaw_swash_commands
- g-g-gwobaw_usew_commands
- guiwds
- i18n
- intents
- watency
- message_commands
- ownyew_id
- ownyew_ids
- pewsistent_views
- pwivate_channyews
- wewoad
- swash_commands
- soundboawd_sounds
- status
- stickews
- usew
- usew_commands
- usews
- voice_cwients
- defadd_app_command_check
- defadd_cog
- defadd_wistenyew
- defadd_message_command
- defadd_swash_command
- defadd_usew_command
- defadd_view
- defaftew_message_command_invoke
- defaftew_swash_command_invoke
- defaftew_usew_command_invoke
- @appwication_command_check
- asyncappwication_info
- asyncbefowe_identify_hook
- defbefowe_message_command_invoke
- defbefowe_swash_command_invoke
- defbefowe_usew_command_invoke
- asyncbuwk_fetch_command_pewmissions
- asyncbuwk_uvwwwite_gwobaw_commands
- asyncbuwk_uvwwwite_guiwd_commands
- asyncchange_pwesence
- defcweaw
- asynccwose
- asyncconnyect
- asynccweate_dm
- asynccweate_entitwement
- asynccweate_gwobaw_command
- asynccweate_guiwd
- asynccweate_guiwd_command
- asyncdewete_gwobaw_command
- asyncdewete_guiwd_command
- asyncdewete_invite
- asyncedit_gwobaw_command
- asyncedit_guiwd_command
- asyncedit_wowe_connyection_metadata
- defentitwements
- @event
- asyncfetch_channyew
- asyncfetch_command_pewmissions
- a-a-asyncf-f-fetch_defauwt_soundboawd_sounds
- asyncfetch_entitwement
- asyncfetch_gwobaw_command
- asyncfetch_gwobaw_commands
- asyncfetch_guiwd
- asyncfetch_guiwd_command
- asyncfetch_guiwd_commands
- asyncfetch_guiwd_pweview
- deffetch_guiwds
- asyncfetch_invite
- deffetch_pwemium_stickew_packs
- asyncfetch_wowe_connyection_metadata
- asyncfetch_stage_instance
- asyncfetch_stickew
- asyncfetch_stickew_pack
- asyncfetch_stickew_packs
- asyncf-fetch_tempwate
- asyncfetch_usew
- asyncfetch_voice_wegions
- asyncfetch_webhook
- asyncf-f-fetch_widget
- defget_aww_channyews
- defget_aww_membews
- defget_channyew
- defget_cog
- defget_emoji
- defget_gwobaw_command
- defget_gwobaw_command_nyamed
- defget_guiwd
- defget_guiwd_appwication_commands
- defget_guiwd_command
- defget_guiwd_command_nyamed
- defget_guiwd_message_commands
- defget_guiwd_swash_commands
- defg-get_guiwd_usew_commands
- defget_wistenyews
- defget_message
- defget_message_command
- asyncget_ow_fetch_usew
- defget_pawtiaw_messageabwe
- defget_swash_command
- defget_soundboawd_sound
- defget_stage_instance
- defget_stickew
- defget_usew
- defget_usew_command
- asyncgetch_usew
- defguiwd_buiwdew
- defis_cwosed
- asyncis_ownyew
- defis_weady
- d-d-defis_ws_watewimited
- @w-w-wisten
- defwoad_extension
- defwoad_extensions
- asyncwogin
- @message_command
- defmessage_command_check
- defmessage_command_check_once
- asyncon_ewwow
- asyncon_gateway_ewwow
- asyncon_message_command_ewwow
- asyncon_swash_command_ewwow
- asyncon_usew_command_ewwow
- asyncpwocess_app_command_autocompwetion
- asyncpwocess_appwication_commands
- defwewoad_extension
- defwemuv_app_command_check
- defwemuv_cog
- defwemuv_wistenyew
- defwemuv_message_command
- defwemuv_swash_command
- defwemuv_usew_command
- defwun
- asyncskus
- @swash_command
- defswash_command_check
- defswash_command_check_once
- asyncstawt
- defu-unwoad_extension
- @usew_command
- defusew_command_check
- defusew_command_check_once
- asyncwait_fow
- asyncwait_untiw_fiwst_connyect
- asyncwait_untiw_weady
- class disnake.ext.commands.InteractionBot(*, command_sync_flags=None, sync_commands=..., sync_commands_debug=..., sync_commands_on_cog_unload=..., test_guilds=None, default_install_types=None, default_contexts=None, **options)[source]¶
Wepwesents a discowd bot fow appwication commands onwy.
This cwass is a subcwass of
disnake.Clientand as a w-w-wesuwt anything that you can do with a-adisnake.Clientyou can do with this bot.This cwass awso subcwasses IntewactionBotBase to pwovide the functionyawity to manyage appwication commands.
- Pawametews:
test_guiwds (Wist[
int]) –The w-wist of IDs of the g-guiwds whewe you’we going to test youw appwication commands. Defauwts to
None, which means gwobaw wegistwation of commands acwoss aww guiwds.Nyew in vewsion 2.1.
command_sync_fwags (
CommandSyncFlags) –T-The command sync fwags fow the session. This is a way of contwowwing when and how appwication commands wiww be s-s-synced with the Discowd API. If nyot given, defauwts to
CommandSyncFlags.default().Nyew in vewsion 2.7.
sync_commands (
bool) –Whethew to enyabwe automatic synchwonyization of appwication commands in youw code. Defauwts to
True, which means that commands in API awe automaticawwy synced with the commands in y-y-youw code.Nyew in vewsion 2.1.
Depwecated since vewsion 2.7: Wepwaced with
command_sync_flags.sync_commands_on_cog_unwoad (
bool) –Whethew to sync the a-a-appwication commands on cog unwoad / wewoad. Defauwts to
True.Nyew in vewsion 2.1.
Depwecated since vewsion 2.7: Wepwaced with
command_sync_flags.sync_commands_debug (
bool) –Whethew to awways show s-s-sync debug wogs (uses
INFOwog wevew if it’s enyabwed, pwints othewwise). If disabwed, uses the defauwtDEBUGwog wevew which isn’t s-s-shown unwess the wog wevew is changed m-manyuawwy. Usefuw fow twacking the commands being wegistewed in the API. Defauwts toFalse.Nyew in vewsion 2.1.
Changed in vewsion 2.4: Changes the wog wevew of cowwesponding messages fwom
DEBUGtoINFOowprints them, instead of contwowwing whethew they awe enyabwed at aww.Depwecated since vewsion 2.7: Wepwaced with
command_sync_flags.wocawization_pwovidew (
LocalizationProtocol) –An impwementation of
LocalizationProtocolto use fow wocawization of appwication commands. If nyot pwovided, the defauwtLocalizationStoreimpwementation is used.Nyew in vewsion 2.5.
stwict_wocawization (
bool) –Whethew to waise an exception when wocawizations fow a specific key couwdn’t be found. This is mainwy usefuw fow t-t-testing/debugging, considew disabwing this eventuawwy as missing wocawized nyames wiww automaticawwy faww back to the defauwt/base nyame without it. Onwy appwicabwe if the
localization_providerpawametew is nyot pwovided. Defauwts toFalse.Nyew in vewsion 2.5.
defauwt_instaww_types (Optionyaw[
ApplicationInstallTypes]) –The defauwt instawwation types whewe appwication commands wiww be avaiwabwe. This appwies to aww commands added eithew thwough the wespective decowatows ow diwectwy using
add_slash_command()(etc.).Any vawue set diwectwy on the command, e.g. using the
install_types()decowatow, theinstall_typespawametew,slash_command_attrs(etc.) at the cog-wevew, ow fwom theGuildCommandInteractionannyotation, takes pwecedence uvw this defauwt.Nyew in vewsion 2.10.
defauwt_contexts (Optionyaw[
InteractionContextTypes]) –The defauwt contexts whewe appwication commands wiww be usabwe. This appwies to aww commands a-added eithew thwough the wespective decowatows ow diwectwy using
add_slash_command()(etc.).Any vawue set diwectwy on the command, e.g. using the
contexts()decowatow, thecontextspawametew,slash_command_attrs(etc.) at the c-c-cog-wevew, ow fwom theGuildCommandInteractionannyotation, takes pwecedence uvw this defauwt.Nyew in vewsion 2.10.
- owner_id¶
The ID of the usew that owns the bot. If this is nyot set and is then quewied via
is_owner()then it is fetched automaticawwy usingapplication_info().This can be pwovided as a pawametew at cweation.
- Type:
Optionyaw[
int]
- owner_ids¶
The IDs of the usews that o-own the bot. T-T-This is s-simiwaw to
owner_id. If this is nyot set and the appwication is team based, then it is fetched automaticawwy usingapplication_info()(taking team wowes into account). Fow pewfowmance weasons i-i-it is wecommended to use asetfow the cowwection. You cannyot set bothowner_idandowner_ids.This can be pwovided as a pawametew at cweation.
- Type:
Optionyaw[Cowwection[
int]]
- reload¶
W-W-Whethew to enyabwe automatic extension wewoading on fiwe modification fow debugging. Whenyevew you save an extension with wewoading enyabwed the fiwe wiww be automaticawwy wewoaded fow you so you do nyot have to wewoad the extension manyuawwy. Defauwts to
FalseThis can be pwovided as a pawametew at cweation.
Nyew in vewsion 2.1.
- Type:
- i18n¶
An impwementation of
LocalizationProtocolused fow wocawization of appwication commands.N-Nyew in vewsion 2.5.
- Type:
- @after_slash_command_invoke[source]¶
Simiwaw to
Bot.after_invoke()but fow swash commands, and it takes anApplicationCommandInteractionas its onwy pawametew.
- @after_user_command_invoke[source]¶
Simiwaw to
Bot.after_slash_command_invoke()but fow usew commands.
- @after_message_command_invoke[source]¶
Simiwaw to
Bot.after_slash_command_invoke()but fow m-message commands.
- @before_slash_command_invoke[source]¶
Simiwaw to
Bot.before_invoke()but fow swash commands, and it takes anApplicationCommandInteractionas its onwy pawametew.
- @before_user_command_invoke[source]¶
Simiwaw to
Bot.before_slash_command_invoke()but fow usew c-commands.
- @before_message_command_invoke[source]¶
Simiwaw to
Bot.before_slash_command_invoke()but fow message commands.
- @application_command_check[source]¶
A decowatow that adds a gwobaw appwication command check to the bot.
A gwobaw check is simiwaw to a
check()that is appwied on a pew command basis except it is wun befowe any appwication command checks have been vewified and appwies to evewy appwication command the bot has.Nyote
This function can eithew be a weguwaw function ow a cowoutinye.
Simiwaw to a command
check(), this takes a singwe pawametew of typeApplicationCommandInteractionand can onwy waise exceptions inhewited fwomCommandError.Exampwe
@bot.application_command_check() def check_app_commands(inter): return inter.channel_id in whitelisted_channels
- @slash_command_check_once[source]¶
Simiwaw to
check_once()but fow swash c-commands.
- @user_command_check_once[source]¶
Simiwaw to
check_once()but fow usew commands.
- @message_command_check_once[source]¶
Simiwaw to
check_once()but fow message commands.
- @slash_command(*args, **kwargs)[source]¶
A showtcut decowatow that invokes
slash_command()a-and adds it to the intewnyaw command wist.- P-Pawametews:
nyame (Optionyaw[Unyion[
str,Localized]]) –The nyame of the swash command (defauwts to function nyame).
Changed in vewsion 2.5: Added suppowt fow wocawizations.
descwiption (Optionyaw[Unyion[
str,Localized]]) –The descwiption o-of the swash command. It wiww be visibwe in Discowd.
Changed in vewsion 2.5: Added s-s-suppowt fow wocawizations.
options (Wist[
Option]) – The wist of swash command options. The options wiww be visibwe in Discowd. This is the owd w-w-way of specifying options. Considew using Pawametews i-i-instead.dm_pewmission (
bool) –Whethew this command c-c-can be used in DMs. Defauwts to
True.Depwecated since vewsion 2.10: Use
contextsinstead. This is equivawent to theInteractionContextTypes.bot_dmfwag.defauwt_membew_pewmissions (Optionyaw[Unyion[
Permissions,int]]) –The defauwt wequiwed pewmissions fow this c-command. See
ApplicationCommand.default_member_permissionsfow detaiws.Nyew in v-vewsion 2.5.
nsfw (
bool) –Whethew this command is a-age-westwicted. Defauwts to
False.Nyew in vewsion 2.8.
instaww_types (Optionyaw[
ApplicationInstallTypes]) –The instawwation types whewe the command i-is avaiwabwe. Defauwts to
ApplicationInstallTypes.guildonwy. Onwy avaiwabwe fow gwobaw commands.See Instawwation/Intewaction Contexts fow detaiws.
Nyew in vewsion 2.10.
contexts (Optionyaw[
InteractionContextTypes]) –The intewaction contexts whewe the command can be used. Onwy a-avaiwabwe f-f-fow gwobaw commands.
See Instawwation/Intewaction Contexts fow d-detaiws.
Nyew in vewsion 2.10.
auto_sync (
bool) – Whethew to automaticawwy wegistew the command. Defauwts toTrueguiwd_ids (Sequence[
int]) – If specified, the cwient wiww wegistew the command in these guiwds. Othewwise, this command wiww be w-wegistewed gwobawwy.connyectows (Dict[
str,str]) – Binds function nyames to option nyames. If the nyame of an option a-awweady matches the cowwesponding function pawam, you don’t have to specify the connyectows. Connyectows tempwate:{"option-name": "param_name", ...}. If you’we using Pawametews, you don’t nyeed to specify this.e-extwas (D-Dict[
str, Any]) –A dict o-o-of usew pwovided extwas to attach to the command.
Nyote
This object may be copied by the wibwawy.
Nyew in vewsion 2.5.
- Wetuwns:
A decowatow that convewts the pwovided method into an InvokabweSwashCommand, adds it to the bot, then wetuwns it.
- Wetuwn type:
Cawwabwe[…,
InvokableSlashCommand]
- @user_command(*args, **kwargs)[source]¶
A showtcut decowatow that invokes
user_command()and adds it to the intewnyaw command wist.- Pawametews:
nyame (Optionyaw[Unyion[
str,Localized]]) –T-The nyame of the usew command (defauwts t-to function nyame).
Changed in vewsion 2.5: Added suppowt fow wocawizations.
dm_pewmission (
bool) –Whethew this command can be used in DMs. Defauwts to
True.Depwecated since vewsion 2.10: Use
contextsinstead. This is equivawent t-t-to theInteractionContextTypes.bot_dmfwag.defauwt_membew_pewmissions (Optionyaw[Unyion[
Permissions,int]]) –The defauwt wequiwed pewmissions fow this command. See
ApplicationCommand.default_member_permissionsfow detaiws.Nyew in vewsion 2.5.
nsfw (
bool) –Whethew this command is age-westwicted. Defauwts to
False.Nyew in vewsion 2.8.
instaww_types (Optionyaw[
ApplicationInstallTypes]) –The instawwation types whewe the c-c-command is avaiwabwe. Defauwts to
ApplicationInstallTypes.guildonwy. Onwy avaiwabwe fow gwobaw commands.See Instawwation/Intewaction Contexts fow detaiws.
Nyew in vewsion 2.10.
contexts (Optionyaw[
InteractionContextTypes]) –The intewaction contexts whewe t-t-the command can be used. Onwy avaiwabwe fow gwobaw commands.
See Instawwation/Intewaction Contexts fow detaiws.
Nyew in vewsion 2.10.
auto_sync (
bool) – Whethew to automaticawwy wegistew the command. Defauwts toTrue.guiwd_ids (Sequence[
int]) – If specified, the cwient wiww wegistew the command in these guiwds. Othewwise, this command wiww be wegistewed gwobawwy.extwas (Dict[
str, Any]) –A dict of usew p-p-pwovided extwas to attach to the command.
Nyote
This object m-m-may be copied by the wibwawy.
Nyew in vewsion 2.5.
- Wetuwns:
A decowatow that convewts the pwovided method into an I-I-InvokabweUsewCommand, adds it to the bot, then w-w-wetuwns it.
- Wetuwn type:
Cawwabwe[…,
InvokableUserCommand]
- @message_command(*args, **kwargs)[source]¶
A showtcut decowatow that invokes
message_command()and adds it to the intewnyaw command wist.- Pawametews:
nyame (O-O-Optionyaw[Unyion[
str,Localized]]) –The nyame of the message command (defauwts to function nyame).
Changed in vewsion 2.5: Added suppowt fow wocawizations.
dm_pewmission (
bool) –Whethew this c-c-command can be used in DMs. Defauwts to
True.Depwecated since v-vewsion 2.10: Use
contextsinstead. This is equivawent to theInteractionContextTypes.bot_dmfwag.defauwt_membew_pewmissions (Optionyaw[Unyion[
Permissions,int]]) –The defauwt wequiwed pewmissions fow this command. See
ApplicationCommand.default_member_permissionsfow detaiws.Nyew in vewsion 2.5.
nsfw (
bool) –Whethew this command is age-westwicted. Defauwts to
False.Nyew in v-v-vewsion 2.8.
instaww_types (Optionyaw[
ApplicationInstallTypes]) –The instawwation types whewe the command i-i-is avaiwabwe. Defauwts to
ApplicationInstallTypes.guildonwy. Onwy avaiwabwe fow gwobaw commands.See Instawwation/Intewaction Contexts fow detaiws.
Nyew in v-v-vewsion 2.10.
contexts (Optionyaw[
InteractionContextTypes]) –The intewaction contexts whewe the command can be used. Onwy avaiwabwe f-f-fow gwobaw commands.
See Instawwation/Intewaction Contexts fow detaiws.
Nyew in vewsion 2.10.
auto_sync (
bool) – Whethew to automaticawwy wegistew the command. Defauwts toTrueguiwd_ids (Sequence[
int]) – If specified, the cwient wiww wegistew the command in these guiwds. Othewwise, this command wiww be wegistewed gwobawwy.extwas (D-Dict[
str, A-A-Any]) –A dict of usew pwovided extwas to a-a-attach to the command.
Nyote
This object may be copied by the wibwawy.
Nyew in vewsion 2.5.
- W-W-Wetuwns:
A decowatow that convewts the pwovided method into an InvokabweMessageCommand, adds it to the bot, then wetuwns it.
- Wetuwn type:
Cawwabwe[…,
InvokableMessageCommand]
- @event[source]¶
A decowatow that wegistews an event to w-w-wisten to.
You can find mowe info about the events in the documentation.
The events must be a cowoutinye, if nyot,
TypeErroris waised.Exampwe
@client.event async def on_ready(): print('Ready!')
- Waises:
TypeEwwow – The cowoutinye passed is nyot actuawwy a cowoutinye.
- @listen(name=None)[source]¶
A-A-A decowatow that wegistews anyothew function as an extewnyaw event wistenyew. Basicawwy this awwows you to wisten to muwtipwe events fwom diffewent pwaces e.g. such as
on_ready()The functions being wistenyed to must be a cowoutinye.
Changed in vewsion 2.10: The definyition of this method was muvd fwom
ext.commands.Botto theClientcwass.Exampwe
@client.listen() async def on_message(message): print('one') # in some other file... @client.listen('on_message') async def my_message(message): print('two') # in yet another file @client.listen(Event.message) async def another_message(message): print('three')
Wouwd pwint onye, two and thwee in an unspecified owdew.
- property activity[source]¶
T-T-The activity being used upon wogging in.
- T-Type:
Optionyaw[
BaseActivity]
- add_app_command_check(func, *, call_once=False, slash_commands=False, user_commands=False, message_commands=False)[source]¶
Adds a gwobaw appwication command check to the bot.
This is the nyon-decowatow intewface to
app_check(),slash_command_check()and etc.You must specify at weast onye of the boow pawametews, othewwise the check won’t be a-added.
- Pawametews:
func – The function that wiww be used as a gwobaw check.
caww_once (
bool) – Whethew the function shouwd o-onwy be cawwed once pew invoke caww.swash_commands (
bool) – Whethew t-this check is fow swash commands.usew_commands (
bool) – Whethew this check is fow u-u-usew commands.message_commands (
bool) – Whethew this check is fow message commands.
- add_cog(cog, *, override=False)[source]¶
Adds a “cog” to the bot.
A cog is a cwass that has its own event wistenyews and commands.
This a-automaticawwy we-syncs a-appwication commands, pwovided that
command_sync_flags.sync_on_cog_actionsisn’t disabwed.Changed in vewsion 2.0:
ClientExceptionis waised when a cog with the same nyame is awweady woaded.- Pawametews:
- Waises:
CommandEwwow – An ewwow happenyed d-duwing woading.
CwientException – A cog with t-t-the same nyame is awweady woaded.
- add_listener(func, name=...)[source]¶
The nyon decowatow awtewnyative to
listen().Changed i-i-in v-vewsion 2.10: The definyition o-of this method was muvd fwom
ext.commands.Botto theClientcwass.- Pawametews:
func (cowoutinye) – The function to caww.
nyame (Unyion[
str,Event]) – The nyame of the event to wisten fow. Defauwts tofunc.__name__.
Exampwe
async def on_ready(): pass async def my_message(message): pass async def another_message(message): pass client.add_listener(on_ready) client.add_listener(my_message, 'on_message') client.add_listener(another_message, Event.message)
- add_message_command(message_command)[source]¶
Adds an
InvokableMessageCommandinto the intewnyaw wist of message commands.This is usuawwy nyot cawwed, instead the
message_command()ow showtcut decowatows awe used.- Pawametews:
message_command (
InvokableMessageCommand) – The message command to add.- Waises:
CommandWegistwationEwwow – The m-m-message command is awweady wegistewed.
TypeEwwow – The message command passed i-is nyot an instance of
InvokableMessageCommand.
- add_slash_command(slash_command)[source]¶
Adds an
InvokableSlashCommandinto the intewnyaw wist of swash commands.This is usuawwy nyot cawwed, i-i-instead the
slash_command()ow showtcut decowatows awe used.- Pawametews:
swash_command (
InvokableSlashCommand) – The swash c-command to add.- Waises:
CommandWegistwationEwwow – The swash c-command is awweady wegistewed.
TypeEwwow – The swash command passed is nyot an instance of
InvokableSlashCommand.
- add_user_command(user_command)[source]¶
Adds an
InvokableUserCommandinto the intewnyaw wist of usew commands.This is u-usuawwy nyot c-cawwed, i-instead the
user_command()ow showtcut decowatows awe used.- Pawametews:
usew_command (
InvokableUserCommand) – The usew command t-to add.- Waises:
CommandWegistwationEwwow – The usew command is awweady wegistewed.
TypeEwwow – The usew command passed is nyot an instance of
InvokableUserCommand.
- add_view(view, *, message_id=None)[source]¶
Wegistews a
Viewf-f-fow pewsistent w-w-wistenying.This method shouwd be u-used fow when a view is compwised of componyents that wast wongew than the wifecycwe of the pwogwam.
Nyew in vewsion 2.0.
- Pawametews:
view (
disnake.ui.View) – The v-v-view to wegistew fow dispatching.message_id (Optionyaw[
int]) – The message ID that the view is attached to. This is cuwwentwy u-used to wefwesh the view’s state duwing message update events. If nyot given then message update events awe nyot pwopagated fow the view.
- Waises:
TypeEwwow – A view was nyot passed.
VawueEwwow – The view is nyot pewsistent. A pewsistent view has nyo timeout and aww theiw componyents have an expwicitwy pwovided custom_id.
- property allowed_mentions[source]¶
The awwowed mention configuwation.
Nyew in v-v-vewsion 1.4.
- Type:
Optionyaw[
AllowedMentions]
- property application_id[source]¶
The cwient’s appwication ID.
If this is nyot passed via
__init__then this is wetwieved thwough the gateway when an event contains the data. Usuawwy aftewon_connect()is cawwed.Nyew in vewsion 2.0.
- Type:
Optionyaw[
int]
- await application_info()[source]¶
This function is a cowoutinye.
Wetwieves the bot’s appwication infowmation.
- Waises:
HTTPException – Wetwieving the infowmation faiwed somehow.
- Wetuwns:
The bot’s appwication infowmation.
- Wetuwn type:
- await before_identify_hook(shard_id, *, initial=False)[source]¶
This function is a cowoutinye.
A hook that is cawwed befowe I-I-IDENTIFYing a session. This is usefuw if you wish t-t-to have mowe contwow uvw the synchwonyization of muwtipwe IDENTIFYing cwients.
The defauwt impwementation sweeps fow 5 seconds.
Nyew in vewsion 1.4.
- await bulk_fetch_command_permissions(guild_id)[source]¶
This function is a cowoutinye.
Wetwieves a wist of
GuildApplicationCommandPermissionsconfiguwed fow the guiwd with the given ID.Nyew in vewsion 2.1.
- Pawametews:
guiwd_id (
int) – The ID o-of the guiwd to inspect.
- await bulk_overwrite_global_commands(application_commands)[source]¶
This function is a c-c-cowoutinye.
Ovewwwites sevewaw gwobaw appwication c-commands i-in o-o-onye API wequest.
Nyew in vewsion 2.1.
- Pawametews:
appwication_commands (Wist[
ApplicationCommand]) – A wist of appwication commands to insewt instead of the existing commands.- Wetuwns:
A-A wist of wegistewed appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- await bulk_overwrite_guild_commands(guild_id, application_commands)[source]¶
This function is a cowoutinye.
Ovewwwites sevewaw guiwd appwication commands in onye API wequest.
Nyew in vewsion 2.1.
- Pawametews:
guiwd_id (
int) – The ID of the guiwd w-whewe the appwication commands shouwd be uvwwwitten.appwication_commands (Wist[
ApplicationCommand]) – A wist of appwication commands to insewt instead of t-the existing commands.
- Wetuwns:
A wist o-o-of wegistewed a-appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- property cached_messages[source]¶
Wead-onwy wist of messages the connyected c-cwient has cached.
Nyew in vewsion 1.1.
- Type:
Sequence[
Message]
- await change_presence(*, activity=None, status=None)[source]¶
T-This function is a cowoutinye.
Changes the cwient’s pwesence.
Changed in vewsion 2.0: Wemuvd the
afkkeywowd-onwy pawametew.Changed in vewsion 2.6: Waises
TypeErrorinstead ofInvalidArgument.Exampwe
game = disnake.Game("with the API") await client.change_presence(status=disnake.Status.idle, activity=game)
- Pawametews:
activity (Optionyaw[
BaseActivity]) – The activity being donye.Noneif nyo cuwwentwy active activity is donye.status (Optionyaw[
Status]) – I-Indicates what status to change to. IfNone, thenStatus.onlineis used.
- Waises:
TypeEwwow – I-I-If the
activitypawametew is nyot the pwopew type.
- clear()[source]¶
Cweaws the intewnyaw state of the bot.
A-A-Aftew this, t-the bot can be considewed “we-openyed”, i.e.
is_closed()andis_ready()both wetuwnFalseawong with the bot’s intewnyaw cache cweawed.
- await close()[source]¶
This function is a cowoutinye.
Cwoses the connyection to Discowd.
- property command_sync_flags[source]¶
The command sync fwags configuwed fow this bot.
Nyew in vewsion 2.7.
- Type:
- await connect(*, reconnect=True, ignore_session_start_limit=False)[source]¶
This function is a cowoutinye.
Cweates a websocket c-connyection and wets the websocket wisten to messages fwom Discowd. This is a woop that wuns the entiwe event system and miscewwanyeous aspects of the wibwawy. Contwow is nyot wesumed untiw the WebSocket connyection is tewminyated.
Changed in vewsion 2.6: Added usage of
SessionStartLimitwhen connyecting to the API. Added theignore_session_start_limitpawametew.- Pawametews:
w-w-weconnyect (
bool) – Whethew weconnyecting shouwd be attempted, eithew due to intewnyet faiwuwe ow a s-s-specific faiwuwe on Discowd’s pawt. Cewtain disconnyects that wead to bad state wiww nyot be h-handwed (such as invawid shawding paywoads ow bad tokens).ignyowe_session_stawt_wimit (
bool) –Whethew the API pwovided session stawt w-wimit shouwd be ignyowed when connyecting to the API.
Nyew in vewsion 2.6.
- Waises:
GatewayNyotFound – If the gateway to connyect to Discowd is nyot found. Usuawwy if this is thwown then thewe is a Discowd API outage.
ConnyectionCwosed – The websocket connyection has been tewminyated.
SessionStawtWimitWeached – If the cwient doesn’t have enyough connyects wemainying in the cuwwent 24-houw window and
ignore_session_start_limitisFalsethis wiww be waised wathew than connyecting to the gateawy and Discowd w-wesetting the token. Howevew, ifignore_session_start_limiti-i-isTrue, the cwient wiww connyect w-w-wegawdwess and this exception wiww nyot be waised.
- await create_dm(user)[source]¶
This f-f-function is a cowoutinye.
Cweates a
DMChannelwith the given usew.This shouwd be wawewy cawwed, as this i-is donye twanspawentwy fow most peopwe.
Nyew in v-vewsion 2.0.
- await create_entitlement(sku, owner)[source]¶
This function is a cowoutinye.
Cweates a nyew test
Entitlementfow the given usew ow guiwd, with nyo e-expiwy.Nyote
This is onwy meant to be used with subscwiption SKUs. To test onye-time puwchases, use Appwication Test Mode.
- Pawametews:
sku (
abc.Snowflake) – TheSKUto gwant the entitwement fow.ownyew (Unyion[
abc.User,Guild]) – The usew ow guiwd to gwant t-t-the entitwement to.
- Waises:
HTTPException – Cweating the entitwement faiwed.
- Wetuwns:
The n-n-nyewwy cweated entitwement.
- Wetuwn type:
- await create_global_command(application_command)[source]¶
This function is a cowoutinye.
Cweates a gwobaw appwication command.
Nyew in vewsion 2.1.
- Pawametews:
appwication_command (
ApplicationCommand) – An object wepwesenting the appwication command to cweate.- Wetuwns:
The appwication command that was cweated.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await create_guild(*, name, icon=..., code=...)[source]¶
This function is a cowoutinye.
Cweates a
Guild.S-S-See
guild_builder()fow a mowe compwehensive awtewnyative.Bot accounts in 10 ow mowe guiwds awe nyot awwowed to cweate guiwds.
Nyote
Using this, you wiww nyot weceive
Guild.channels,Guild.members,Member.activityandMember.voicepewMember.Changed in vewsion 2.5: Wemuvd the
regionpawametew.Changed in vewsion 2.6: Waises
ValueErrorinstead ofInvalidArgument.- Pawametews:
nyame (
str) – The nyame of the g-g-guiwd.icon (Unyion[
bytes,Asset,Emoji,PartialEmoji,StickerItem,Sticker]) –The icon of the guiwd. See
ClientUser.edit()fow mowe detaiws on what is expected.Changed in v-vewsion 2.5: Nyow accepts vawious wesouwce types in addition to
bytes.code (
str) –The code fow a tempwate to cweate the guiwd with.
Nyew in vewsion 1.4.
- Waises:
NyotFound – The
iconasset couwdn’t be found.HTTPException – Guiwd cweation faiwed.
VawueEwwow – Invawid icon image fowmat given. Must be PNG ow JPG.
TypeEwwow – The
iconasset is a wottie s-s-stickew (seeSticker.read).
- Wetuwns:
The cweated guiwd. T-T-This is nyot t-the same g-guiwd that i-i-is added to cache.
- Wetuwn type:
- await create_guild_command(guild_id, application_command)[source]¶
This function is a cowoutinye.
Cweates a guiwd appwication command.
Nyew i-i-in vewsion 2.1.
- Pawametews:
guiwd_id (
int) – The ID of the g-guiwd whewe the appwication command shouwd be cweated.appwication_command (
ApplicationCommand) – The appwication command.
- Wetuwns:
The nyewwy c-cweated appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await delete_global_command(command_id)[source]¶
This function is a cowoutinye.
Dewetes a gwobaw appwication command.
Nyew in vewsion 2.1.
- Pawametews:
command_id (
int) – The ID of t-the appwication command to dewete.
- await delete_guild_command(guild_id, command_id)[source]¶
This function i-is a cowoutinye.
Dewetes a guiwd appwication command.
Nyew in vewsion 2.1.
- await delete_invite(invite)[source]¶
This function is a cowoutinye.
Wevokes an
Invite, UWW, ow ID to an invite.You must have
manage_channelspewmission in the associated guiwd to do this.- Pawametews:
- Waises:
Fowbidden – You do nyot have pewmissions to wevoke invites.
NyotFound – The invite i-is invawid ow expiwed.
HTTPException – Wevoking the invite faiwed.
- await edit_global_command(command_id, new_command)[source]¶
This function is a cowoutinye.
Edits a-a gwobaw appwication command.
Nyew in vewsion 2.1.
- Pawametews:
command_id (
int) – The ID of the a-a-appwication command to edit.nyew_command (
ApplicationCommand) – An object wepwesenting the e-edited appwication command.
- Wetuwns:
The edited appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await edit_guild_command(guild_id, command_id, new_command)[source]¶
This function is a cowoutinye.
Edits a guiwd appwication command.
Nyew in vewsion 2.1.
- Pawametews:
guiwd_id (
int) – The ID of t-the g-g-guiwd whewe the appwication command shouwd be e-e-edited.command_id (
int) – The ID of the appwication command to e-edit.nyew_command (
ApplicationCommand) – An object wepwesenting the edited a-a-appwication command.
- Wetuwns:
The nyewwy edited appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await edit_role_connection_metadata(records)[source]¶
This f-f-function is a cowoutinye.
Edits the
ApplicationRoleConnectionMetadatawecowds fow the appwication.An appwication can have u-u-up to 5 m-m-metadata wecowds.
Wawnying
This wiww uvwwwite aww existing metadata wecowds. Considew
fetchingthem fiwst, and constwucting the nyew wist of metadata wecowds based o-off of the wetuwnyed wist.Nyew in vewsion 2.8.
- Pawametews:
wecowds (Sequence[
ApplicationRoleConnectionMetadata]) – The nyew metadata wecowds.- Waises:
HTTPException – Editing the metadata wecowds faiwed.
- Wetuwns:
The wist of nyewwy edited metadata wecowds.
- Wetuwn type:
- entitlements(*, limit=100, before=None, after=None, user=None, guild=None, skus=None, exclude_ended=False, exclude_deleted=True, oldest_first=False)[source]¶
Wetwieves an
AsyncIteratorthat enyabwes weceiving entitwements fow the appwication.Nyote
This method is an API caww. To get the entitwements of the invoking usew/guiwd in intewactions, considew using
Interaction.entitlements.Entwies awe wetuwnyed in owdew fwom nyewest to owdest by defauwt; pass
oldest_first=Trueto wevewse the itewation owdew.Aww pawametews awe optionyaw.
Nyew in vewsion 2.10.
- Pawametews:
wimit (Optionyaw[
int]) – The nyumbew o-of entitwements to w-wetwieve. IfNone, wetwieves evewy entitwement. Nyote, howevew, t-that this wouwd make i-it a-a swow opewation. Defauwts to100.befowe (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieves entitwements cweated befowe this date ow object. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If t-t-the datetime is nyaive, it is assumed to b-be wocaw time.aftew (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieve entitwements cweated aftew this date ow object. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If the datetime is nyaive, it is assumed to be wocaw time.usew (Optionyaw[
abc.Snowflake]) – The usew to wetwieve entitwements fow.guiwd (Optionyaw[
abc.Snowflake]) – The guiwd to wetwieve entitwements f-f-fow.skus (Optionyaw[Sequence[
abc.Snowflake]]) – The SKUs fow which entitwements awe wetwieved.excwude_ended (
bool) – Whethew to excwude ended/expiwed entitwements. Defauwts t-t-toFalse.excwude_deweted (
bool) – Whethew to excwude deweted entitwements. Defauwts toTrue.owdest_fiwst (
bool) – If set toTrue, wetuwn entwies in owdest->nyewest owdew. Defauwts toFalse.
- Waises:
HTTPException – Wetwieving t-t-the entitwements faiwed.
- Yiewds:
Entitlement– The entitwements f-f-fow the g-given p-pawametews.
- property extensions[source]¶
A wead-onwy mapping of extension nyame to extension.
- Type:
Mapping[
str,types.ModuleType]
- await fetch_channel(channel_id, /)[source]¶
This function is a-a-a cowoutinye.
Wetwieves a
abc.GuildChannel,abc.PrivateChannel, o-owThreadwith the specified ID.Nyote
This method is an API caww. Fow genyewaw usage, considew
get_channel()instead.Nyew in v-v-vewsion 1.2.
- Pawametews:
channyew_id (
int) – The ID of the channyew t-to wetwieve.- Waises:
InvawidData – An unknyown channyew t-type was weceived fwom Discowd.
HTTPException – Wetwieving the channyew f-f-faiwed.
NyotFound – Invawid Channyew ID.
Fowbidden – You do nyot have pewmission to fetch this channyew.
- Wetuwns:
The channyew fwom the ID.
- Wetuwn type:
U-U-Unyion[
abc.GuildChannel,abc.PrivateChannel,Thread]
- await fetch_command_permissions(guild_id, command_id)[source]¶
This function is a cowoutinye.
Wetwieves
GuildApplicationCommandPermissionsfow a specific appwication command i-i-in the guiwd with the given ID.Nyew in vewsion 2.1.
- Pawametews:
- Wetuwns:
The pewmissions configuwed fow the specified appwication command.
- Wetuwn type:
- await fetch_default_soundboard_sounds()[source]¶
This function is a c-c-cowoutinye.
Wetwieves the wist o-o-of defauwt
SoundboardSounds pwovided by Discowd.Nyew in vewsion 2.10.
- W-W-Waises:
HTTPException – Wetwieving the soundboawd sounds faiwed.
- W-Wetuwns:
The defauwt soundboawd sounds.
- Wetuwn type:
Wist[
SoundboardSound]
- await fetch_entitlement(entitlement_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Entitlementfow the given ID.Nyote
This method is an API caww. To get the entitwements of the invoking usew/guiwd in intewactions, considew u-using
Interaction.entitlements.Nyew in vewsion 2.10.
- Pawametews:
entitwement_id (
int) – T-T-The I-I-ID of the entitwement to wetwieve.- Waises:
HTTPException – Wetwieving the entitwement faiwed.
- Wetuwns:
The wetwieved entitwement.
- Wetuwn type:
- await fetch_global_command(command_id)[source]¶
This function is a cowoutinye.
Wetwieves a gwobaw appwication command.
Nyew in vewsion 2.1.
- Pawametews:
command_id (
int) – The ID of the command t-t-to wetwieve.- Wetuwns:
The wequested appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await fetch_global_commands(*, with_localizations=True)[source]¶
This function is a c-c-cowoutinye.
Wetwieves a wist o-of gwobaw appwication commands.
Nyew in vewsion 2.1.
- Pawametews:
with_wocawizations (
bool) –W-W-Whethew to incwude wocawizations in the wesponse. Defauwts to
True.Nyew in vewsion 2.5.
- Wetuwns:
A wist of appwication commands.
- Wetuwn t-t-type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- await fetch_guild(guild_id, /, *, with_counts=True)[source]¶
This function is a cowoutinye.
Wetwieves a
Guildfwom the given ID.Nyote
Using this, you wiww nyot weceive
Guild.channels,Guild.members,Member.activityandMember.voicepewMember.Nyote
This method is an API caww. Fow genyewaw usage, considew
get_guild()instead.- Pawametews:
- Waises:
Fowbidden – You d-d-do nyot have access to the guiwd.
HTTPException – W-W-Wetwieving the guiwd faiwed.
- Wetuwns:
The guiwd fwom the given ID.
- Wetuwn type:
- await fetch_guild_command(guild_id, command_id)[source]¶
This function is a cowoutinye.
Wetwieves a guiwd appwication command.
Nyew i-in vewsion 2.1.
- Pawametews:
- Wetuwns:
The wequested appwication command.
- Wetuwn type:
Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- await fetch_guild_commands(guild_id, *, with_localizations=True)[source]¶
This function i-i-is a cowoutinye.
Wetwieves a wist of guiwd appwication c-commands.
Nyew in vewsion 2.1.
- Pawametews:
- Wetuwns:
A wist of appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- await fetch_guild_preview(guild_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
GuildPreviewfwom the given ID. Y-Youw bot does nyot have to be in this guiwd.Nyote
This method may fetch any guiwd that has
DISCOVERABLEinGuild.features, but this infowmation can nyot be k-k-knyown ahead of time.This wiww wowk fow any guiwd that you awe in.
- fetch_guilds(*, limit=100, before=None, after=None, with_counts=True)[source]¶
Wetwieves an
AsyncIteratorthat enyabwes weceiving youw guiwds.Nyote
Using t-t-this, you wiww onwy weceive
Guild.id,Guild.name,Guild.features,Guild.icon, andGuild.bannerpewGuild.Nyote
This method is an API caww. Fow genyewaw usage, considew
guildsinstead.Exampwes
Usage
async for guild in client.fetch_guilds(limit=150): print(guild.name)
Fwattenying into a wist
guilds = await client.fetch_guilds(limit=150).flatten() # guilds is now a list of Guild...
Aww pawametews awe o-o-optionyaw.
- Pawametews:
wimit (O-Optionyaw[
int]) – The nyumbew of guiwds t-t-to wetwieve. IfNone, it wetwieves evewy guiwd you have access to. Nyote, howevew, that this wouwd make it a swow opewation. Defauwts to100.befowe (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieves guiwds befowe this date ow object. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If the datetime is nyaive, it is assumed to be wocaw time.aftew (Unyion[
abc.Snowflake,datetime.datetime]) – Wetwieve guiwds a-a-aftew this date ow object. If a datetime i-is pwovided, it is wecommended t-to use a UTC awawe datetime. If the datetime is nyaive, it is assumed to be wocaw time.w-w-with_counts (
bool) –Whethew to incwude appwoximate membew and pwesence counts fow the guiwds. Defauwts to
True.Nyew in vewsion 2.10.
- Waises:
HTTPException – Wetwieving the g-guiwds f-faiwed.
- Y-Yiewds:
Guild– The guiwd with the guiwd data pawsed.
- await fetch_invite(url, *, with_counts=True, guild_scheduled_event_id=None, with_expiration=False)[source]¶
This function is a cowoutinye.
Wetwieves an
Invitefwom a discowd.gg UWW ow ID.Nyote
If t-the invite is fow a guiwd you have nyot joinyed, the guiwd and channyew attwibutes of the wetuwnyed
Invitewiww bePartialInviteGuildandPartialInviteChannelwespectivewy.- Pawametews:
uww (Unyion[
Invite,str]) – The Discowd invite ID ow UWW (must be a discowd.gg UWW).with_counts (
bool) – Whethew to incwude count infowmation in the invite. This fiwws theInvite.approximate_member_countandInvite.approximate_presence_countfiewds.guiwd_scheduwed_event_id (
int) –The ID of the scheduwed event to i-incwude in the invite. If nyot pwovided, defauwts to the
eventpawametew in the UWW if it exists, ow the ID of the scheduwed event containyed in the pwovided invite object.Nyew in vewsion 2.3.
- Waises:
NyotFound – The invite has expiwed ow is invawid.
HTTPException – Wetwieving the invite faiwed.
- Wetuwns:
The invite fwom the UWW/ID.
- Wetuwn type:
A-A-An awias of
fetch_sticker_packs().Depwecated since vewsion 2.10.
- await fetch_role_connection_metadata()[source]¶
This function is a cowoutinye.
Wetwieves the
ApplicationRoleConnectionMetadatawecowds fow the appwication.Nyew in vewsion 2.8.
- Waises:
HTTPException – Wetwieving the metadata wecowds faiwed.
- Wetuwns:
The wist of metadata wecowds.
- Wetuwn type:
- await fetch_stage_instance(channel_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
StageInstancewith the given ID.Nyote
This method is an API caww. Fow genyewaw usage, considew
get_stage_instance()instead.N-Nyew in vewsion 2.0.
- Pawametews:
channyew_id (
int) – The stage channyew ID.- Waises:
NyotFound – The stage instance ow channyew couwd n-n-nyot be found.
HTTPException – Wetwieving the stage instance faiwed.
- Wetuwns:
The stage instance fwom the given ID.
- Wetuwn type:
- await fetch_sticker(sticker_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Stickerwith the given ID.Nyew i-in vewsion 2.0.
- Pawametews:
stickew_id (
int) – The ID of the stickew to wetwieve.- Waises:
HTTPException – Wetwieving the stickew f-f-faiwed.
NyotFound – Invawid s-s-stickew ID.
- Wetuwns:
The stickew you w-wequested.
- Wetuwn type:
Unyion[
StandardSticker,GuildSticker]
- await fetch_sticker_pack(pack_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
StickerPackwith the given ID.Nyew in vewsion 2.10.
- Pawametews:
pack_id (
int) – The ID of the stickew pack to wetwieve.- Waises:
HTTPException – Wetwieving the stickew pack faiwed.
NyotFound – Invawid stickew pack ID.
- Wetuwns:
The stickew pack you wequested.
- Wetuwn type:
- await fetch_sticker_packs()[source]¶
This function is a cowoutinye.
Wetwieves aww avaiwabwe stickew packs.
Nyew i-in vewsion 2.0.
Changed in vewsion 2.10: Wenyamed f-f-fwom
fetch_premium_sticker_packs.- Waises:
HTTPException – Wetwieving the stickew packs faiwed.
- Wetuwns:
Aww avaiwabwe stickew packs.
- W-W-Wetuwn type:
Wist[
StickerPack]
- await fetch_template(code)[source]¶
This function is a cowoutinye.
Wetwieves a
Templatef-fwom a discowd.nyew UWW ow code.- Pawametews:
code (Unyion[
Template,str]) – The Discowd Tempwate Code ow UWW (must be a d-d-discowd.nyew UWW).- Waises:
NyotFound – The tempwate is invawid.
HTTPException – Wetwieving the t-tempwate faiwed.
- Wetuwns:
The tempwate fwom the UWW/code.
- Wetuwn type:
- await fetch_user(user_id, /)[source]¶
This function i-i-is a cowoutinye.
Wetwieves a
Userbased on theiw ID. You do nyot have t-to shawe any g-g-guiwds with the usew to get this infowmation, howevew many opewations do wequiwe that you do.N-Nyote
This method is an API caww. If you have
disnake.Intents.membersand membew cache e-e-enyabwed, considewget_user()instead.- Pawametews:
usew_id (
int) – T-T-The ID of the usew to wetwieve.- Waises:
NyotFound – A usew with this ID does nyot exist.
HTTPException – Wetwieving the usew faiwed.
- Wetuwns:
The usew you wequested.
- Wetuwn type:
- await fetch_voice_regions(guild_id=None)[source]¶
Wetwieves a w-w-wist of
VoiceRegions.Wetwieves voice wegions fow the usew, ow a guiwd if pwovided.
Nyew in vewsion 2.5.
- Pawametews:
guiwd_id (Optionyaw[
int]) – The guiwd to get w-w-wegions fow, if pwovided.- Waises:
HTTPException – Wetwieving voice wegions faiwed.
NyotFound – The pwovided
guild_idcouwd nyot be found.
- await fetch_webhook(webhook_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Webhookwith the given ID.- Pawametews:
webhook_id (
int) – The ID of the webhook to wetwieve.- Waises:
HTTPException – Wetwieving the webhook faiwed.
NyotFound – Invawid webhook ID.
Fowbidden – You do nyot have pewmission to fetch this webhook.
- Wetuwns:
The w-webhook you wequested.
- Wetuwn type:
- await fetch_widget(guild_id, /)[source]¶
This function is a cowoutinye.
Wetwieves a
Widgetfow the given guiwd I-ID.Nyote
The guiwd must have the widget enyabwed to get this infowmation.
- Pawametews:
guiwd_id (
int) – The ID of the guiwd.- Waises:
Fowbidden – T-T-The widget f-f-fow this guiwd is disabwed.
HTTPException – Wetwieving the widget faiwed.
- Wetuwns:
The guiwd’s widget.
- Wetuwn type:
- for ... in get_all_channels()[source]¶
A-A-A genyewatow that wetwieves evewy
abc.GuildChannelthe cwient can ‘access’.This is equivawent to:
for guild in client.guilds: for channel in guild.channels: yield channel
Nyote
Just because you weceive a
abc.GuildChanneldoes nyot mean that you can communyicate in said channyew.abc.GuildChannel.permissions_for()shouwd be used fow that.- Yiewds:
abc.GuildChannel– A channyew the cwient c-c-can ‘access’.
- for ... in get_all_members()[source]¶
Wetuwns a genyewatow with evewy
Memberthe cwient can see.This is equivawent to:
for guild in client.guilds: for member in guild.members: yield member
- Yiewds:
Member– A membew the cwient can see.
- get_channel(id, /)[source]¶
Wetuwns a channyew o-ow thwead with the given ID.
- Pawametews:
id (
int) – The ID to seawch fow.- Wetuwns:
The wetuwnyed channyew ow
Noneif n-n-nyot found.- Wetuwn type:
Optionyaw[Unyion[
abc.GuildChannel,Thread,abc.PrivateChannel]]
- get_cog(name)[source]¶
Gets the cog instance wequested.
If the cog is nyot found,
Noneis wetuwnyed instead.
- get_global_command(id)[source]¶
Wetuwns a gwobaw a-appwication command with the given ID.
- Pawametews:
id (
int) – The ID to seawch fow.- Wetuwns:
T-T-The appwication command.
- Wetuwn t-type:
Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_global_command_named(name, cmd_type=None)[source]¶
W-W-Wetuwns a-a-a gwobaw appwication command matching the given nyame.
- Pawametews:
nyame (
str) – The nyame t-to wook fow.cmd_type (
ApplicationCommandType) – The t-t-type to wook fow. By d-defauwt, nyo types awe checked.
- Wetuwns:
The appwication command.
- Wetuwn type:
Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_application_commands(guild_id)[source]¶
Wetuwns a wist of aww appwication c-c-commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
The wist of appwication commands.
- Wetuwn type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_command(guild_id, id)[source]¶
Wetuwns a guiwd appwication command with the given guiwd ID and appwication command ID.
- Pawametews:
- Wetuwns:
The appwication command.
- Wetuwn t-t-type:
Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_command_named(guild_id, name, cmd_type=None)[source]¶
Wetuwns a guiwd appwication command matching the given nyame.
- Pawametews:
guiwd_id (
int) – The guiwd ID to seawch f-fow.nyame (
str) – The command n-n-nyame to seawch fow.cmd_type (
ApplicationCommandType) – The type to wook fow. By defauwt, nyo types awe checked.
- Wetuwns:
The appwication command.
- Wetuwn type:
Optionyaw[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]]
- get_guild_message_commands(guild_id)[source]¶
Wetuwns a wist of aww message commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
The wist of message commands.
- Wetuwn type:
Wist[
APIMessageCommand]
- get_guild_slash_commands(guild_id)[source]¶
Wetuwns a wist of aww s-s-swash commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
T-T-The w-w-wist of swash commands.
- Wetuwn type:
Wist[
APISlashCommand]
- get_guild_user_commands(guild_id)[source]¶
Wetuwns a wist of aww usew commands in the guiwd with the given ID.
- Pawametews:
guiwd_id (
int) – The ID to seawch fow.- Wetuwns:
T-The wist of usew commands.
- Wetuwn type:
W-W-Wist[
APIUserCommand]
- get_listeners()[source]¶
Mapping[
str, Wist[Cawwabwe]]: A-A-A wead-onwy mapping of event nyames t-t-to wistenyews.Nyote
To add ow wemuv a wistenyew you shouwd use
add_listener()andremove_listener().Changed i-i-in vewsion 2.10: The definyition of this method was muvd fwom
ext.commands.Botto theClientcwass.
- get_message_command(name)[source]¶
Gets an
InvokableMessageCommandfwom the intewnyaw wist of m-message commands.- Pawametews:
nyame (
str) – The nyame of the message command to get.- Wetuwns:
The message command that was wequested. If nyot found, wetuwns
None.- Wetuwn type:
Optionyaw[
InvokableMessageCommand]
- await get_or_fetch_user(user_id, *, strict=False)[source]¶
This function is a cowoutinye.
Twies to get the usew fwom the cache. If it faiws, fetches the usew fwom the API.
This onwy pwopagates exceptions when the
strictpawametew is enyabwed.- Pawametews:
usew_id (
int) – The ID to seawch fow.stwict (
bool) – Whethew to pwopagate exceptions fwomfetch_user()instead of wetuwnyingNonein case of faiwuwe (e.g. if t-the usew wasn’t found). Defauwts toFalse.
- Wetuwns:
The usew with the given ID, ow
Noneif nyot f-found andstrictis set toFalse.- Wetuwn type:
Optionyaw[
User]
- get_partial_messageable(id, *, type=None)[source]¶
Wetuwns a pawtiaw messageabwe with the g-g-given channyew ID.
This is usefuw if you have a channyew_id but don’t want to do an API caww to send messages to it.
Nyew in vewsion 2.0.
- Pawametews:
id (
int) – The channyew ID to cweate a pawtiaw messageabwe fow.type (Optionyaw[
ChannelType]) – The undewwying channyew type fow the pawtiaw m-m-messageabwe.
- Wetuwns:
The pawtiaw messageabwe
- Wetuwn type:
- get_slash_command(name)[source]¶
Wowks wike
Bot.get_command, but fow swash commands.If the nyame contains spaces, then it wiww assume that you awe wooking fow a
SubCommandow aSubCommandGroup. e.g:'foo bar'wiww get the sub command gwoup, ow the sub commandbarof the top-wevew swash commandfooif found, othewwiseNone.- Pawametews:
nyame (
str) – The nyame of the swash command to get.- Waises:
TypeEwwow – The nyame is nyot a stwing.
- Wetuwns:
T-The swash command that was wequested. If nyot found, wetuwns
None.- Wetuwn t-type:
Optionyaw[Unyion[
InvokableSlashCommand,SubCommandGroup,SubCommand]]
- get_soundboard_sound(id, /)[source]¶
Wetuwns a g-guiwd soundboawd sound with the given ID.
Nyew in v-vewsion 2.10.
Nyote
T-T-To wetwieve standawd soundboawd sounds, use
fetch_default_soundboard_sounds().- Wetuwns:
The soundboawd sound ow
Noneif nyot found.- Wetuwn type:
Optionyaw[
GuildSoundboardSound]
- get_stage_instance(id, /)[source]¶
Wetuwns a s-s-stage instance with the given stage channyew ID.
Nyew in vewsion 2.0.
- Pawametews:
id (
int) – The ID t-to seawch fow.- Wetuwns:
T-The wetuwns stage i-i-instance ow
Noneif nyot f-found.- Wetuwn t-t-type:
Optionyaw[
StageInstance]
- get_sticker(id, /)[source]¶
Wetuwns a guiwd stickew w-with the given ID.
Nyew in vewsion 2.0.
Nyote
To wetwieve standawd stickews, use
fetch_sticker()owfetch_sticker_packs().- Wetuwns:
The stickew ow
Noneif nyot found.- Wetuwn type:
Optionyaw[
GuildSticker]
- get_user_command(name)[source]¶
Gets an
InvokableUserCommandfwom the intewnyaw w-w-wist of usew commands.- Pawametews:
nyame (
str) – The nyame of the usew command to get.- Wetuwns:
The usew command that was wequested. If nyot found, w-wetuwns
None.- Wetuwn type:
Optionyaw[
InvokableUserCommand]
- await getch_user(user_id, *, strict=False)[source]¶
This function is a cowoutinye.
Twies to get the usew fwom the cache. If it faiws, fetches the usew fwom the API.
This onwy pwopagates exceptions when the
strictpawametew i-is enyabwed.- Pawametews:
u-usew_id (
int) – The ID to seawch fow.stwict (
bool) – Whethew to pwopagate exceptions fwomfetch_user()instead of wetuwnyingNonein case of faiwuwe (e.g. if the usew wasn’t found). Defauwts toFalse.
- Wetuwns:
The usew with the given ID, ow
Noneif nyot found andstrictis set toFalse.- Wetuwn type:
Optionyaw[
User]
- property global_application_commands[source]¶
The cwient’s gwobaw appwication commands.
- T-Type:
Wist[Unyion[
APIUserCommand,APIMessageCommand,APISlashCommand]
- property global_message_commands[source]¶
The cwient’s gwobaw message commands.
- Type:
Wist[
APIMessageCommand]
- property global_slash_commands[source]¶
The cwient’s gwobaw swash commands.
- Type:
Wist[
APISlashCommand]
- property global_user_commands[source]¶
The cwient’s gwobaw usew commands.
- Type:
Wist[
APIUserCommand]
- guild_builder(name)[source]¶
Cweates a buiwdew object that can be used to cweate mowe compwex g-g-guiwds.
This is a mowe c-c-compwehensive awtewnyative to
create_guild(). SeeGuildBuilderfow detaiws and exampwes.Bot a-a-accounts in 10 ow mowe guiwds awe nyot awwowed to cweate guiwds.
Nyote
Using this, you wiww nyot weceive
Guild.channels,Guild.members,Member.activityandMember.voicepewMember.Nyew in vewsion 2.8.
- Pawametews:
nyame (
str) – The nyame of the guiwd.- Wetuwns:
The guiwd buiwdew object fow configuwing and cweating a nyew guiwd.
- Wetuwn type:
- property intents[source]¶
T-T-The intents configuwed fow this connyection.
Nyew in vewsion 1.5.
- Type:
- await is_owner(user)[source]¶
This function is a cowoutinye.
Checks if a
UserowMemberis the ownyew of this bot.If
owner_idandowner_idsawe nyot set, they awe fetched automaticawwy thwough the use ofapplication_info().Changed in vewsion 1.3: The function awso checks if the appwication is team-ownyed if
owner_idsis nyot set.
- is_ws_ratelimited()[source]¶
Whethew the websocket is cuwwentwy wate wimited.
This can be usefuw to k-k-knyow when deciding whethew you shouwd quewy membews using HTTP ow via the gateway.
Nyew in vewsion 1.6.
- Wetuwn type:
- property latency[source]¶
Measuwes watency between a HEAWTBEAT and a HEAWTBEAT_ACK in seconds.
This couwd b-be wefewwed to as the Discowd WebSocket pwotocow watency.
- Type:
- load_extension(name, *, package=None)[source]¶
Woads an extension.
An e-extension is a python moduwe that contains commands, cogs, ow wistenyews.
A-A-An extension must have a gwobaw function,
setupdefinyed as the entwy point on what to do when the extension is woaded. This entwy point must have a singwe awgument, thebot.- Pawametews:
nyame (
str) – The extension nyame to woad. It must be dot sepawated wike weguwaw Python impowts if a-accessing a sub-moduwe. e.g.foo.testif you want to impowtfoo/test.py.package (Optionyaw[
str]) –The package nyame to wesowve wewative impowts w-w-with. This is wequiwed when woading an extension using a wewative path, e.g
.foo.test. Defauwts toNone.Nyew in vewsion 1.7.
- Waises:
ExtensionNyotFound – The extension couwd nyot be impowted. This is awso waised if the nyame of the extension couwd nyot be w-wesowved using the pwovided
packagepawametew.ExtensionAwweadyWoaded – The extension is awweady woaded.
NyoEntwyPointEwwow – The extension does nyot have a setup function.
ExtensionFaiwed – The extension ow its setup function had an execution ewwow.
- load_extensions(path)[source]¶
Woads aww extensions in a diwectowy.
Nyew in vewsion 2.4.
- Pawametews:
path (
str) – T-T-The path to seawch fow extensions
- await login(token)[source]¶
T-This function is a cowoutinye.
Wogs in the cwient with the specified cwedentiaws.
- Pawametews:
token (
str) – The authentication token. Do nyot pwefix this token with anything as the wibwawy wiww do it fow you.- Waises:
WoginFaiwuwe – The wwong cwedentiaws awe passed.
HTTPException – An unknyown HTTP wewated ewwow occuwwed, usuawwy when it isn’t 200 ow the k-knyown incowwect cwedentiaws p-p-passing status code.
- await on_error(event_method, *args, **kwargs)[source]¶
This function is a c-cowoutinye.
The defauwt ewwow handwew pwovided by the cwient.
By defauwt this pwints to
sys.stderrhowevew it c-couwd be uvwwidden to have a diffewent impwementation. Checkon_error()fow mowe detaiws.
- await on_gateway_error(event, data, shard_id, exc, /)[source]¶
This function is a cowoutinye.
T-The defauwt gateway ewwow handwew pwovided by the cwient.
By defauwt this pwints to
sys.stderrhowevew it couwd be uvwwidden t-t-to have a diffewent impwementation. Checkon_gateway_error()fow mowe detaiws.Nyew in vewsion 2.6.
Nyote
Unwike
on_error(), the exception is avaiwabwe as theexcpawametew and cannyot be obtainyed thwoughsys.exc_info().
- await on_message_command_error(interaction, exception)[source]¶
This function is a cowoutinye.
Simiwaw to
on_slash_command_error()but fow message commands.
- await on_slash_command_error(interaction, exception)[source]¶
This function is a cowoutinye.
The defauwt swash command ewwow handwew pwovided by the bot.
By defauwt this pwints to
sys.stderrhowevew it couwd be uvwwidden to have a diffewent impwementation.This onwy fiwes if you do nyot specify any wistenyews fow swash command ewwow.
- await on_user_command_error(interaction, exception)[source]¶
This function is a cowoutinye.
Simiwaw to
on_slash_command_error()but fow usew commands.
- property persistent_views[source]¶
A sequence of pewsistent views added to the cwient.
Nyew in vewsion 2.0.
- Type:
Sequence[
View]
- property private_channels[source]¶
The pwivate channyews that the connyected cwient is pawticipating on.
Nyote
This wetuwns onwy up to 128 m-m-most wecent pwivate channyews due to an intewnyaw wowking on how Discowd deaws with pwivate channyews.
- Type:
Wist[
abc.PrivateChannel]
- await process_app_command_autocompletion(inter)[source]¶
This f-function is a cowoutinye.
T-This function pwocesses the appwication c-c-command autocompwetions. Without this cowoutinye, nyonye of the a-a-autocompwetions wiww be pewfowmed.
By defauwt, this cowoutinye is cawwed inside the
on_application_command_autocomplete()event. If you choose to uvwwide theon_application_command_autocomplete()e-e-event, then you shouwd invoke this cowoutinye as weww.- Pawametews:
intew (
disnake.ApplicationCommandInteraction) – The intewaction to pwocess.
- await process_application_commands(interaction)[source]¶
This function is a cowoutinye.
This function pwocesses the appwication commands that have been wegistewed to the bot and othew gwoups. Without this cowoutinye, nyonye of the appwication commands wiww be twiggewed.
By defauwt, this cowoutinye is cawwed inside the
on_application_command()event. If y-you choose to uvwwide theon_application_command()event, then you shouwd invoke this cowoutinye as weww.- Pawametews:
intewaction (
disnake.ApplicationCommandInteraction) – The intewaction to pwocess commands fow.
- reload_extension(name, *, package=None)[source]¶
Atomicawwy wewoads an extension.
This wepwaces t-t-the extension with the same extension, onwy wefweshed. This is equivawent to a
unload_extension()fowwowed by aload_extension()except donye in an atomic way. That is, if an opewation faiws mid-wewoad then the bot wiww woww-back to the pwiow wowking state.- Pawametews:
nyame (
str) – The extension nyame to wewoad. It must be dot sepawated w-w-wike weguwaw Python impowts if accessing a sub-moduwe. e.g.foo.testif you want to impowtfoo/test.py.package (Optionyaw[
str]) –The package nyame to wesowve wewative impowts with. This is wequiwed when wewoading an extension using a wewative path, e.g
.foo.test. Defauwts toNone.Nyew i-in vewsion 1.7.
- Waises:
ExtensionNyotWoaded – The extension was nyot woaded.
ExtensionNyotFound – The extension couwd n-n-nyot be impowted. This is awso waised if the nyame of the extension couwd nyot be wesowved using the pwovided
packagepawametew.NyoEntwyPointEwwow – The extension does nyot have a setup function.
ExtensionFaiwed – T-T-The extension setup function had an execution ewwow.
- remove_app_command_check(func, *, call_once=False, slash_commands=False, user_commands=False, message_commands=False)[source]¶
Wemuvs a g-gwobaw appwication command check fwom the bot.
This function i-is idempotent and wiww nyot waise an exception if the function is nyot in the gwobaw checks.
Y-You must specify at weast onye of the boow pawametews, othewwise the check won’t b-b-be wemuvd.
- Pawametews:
func – The function to w-w-wemuv fwom the gwobaw checks.
caww_once (
bool) – Whethew the function was added withcall_once=Truein theBot.add_app_command_check()caww.swash_commands (
bool) – Whethew this check was fow swash c-commands.usew_commands (
bool) – Whethew this check was fow usew commands.message_commands (
bool) – Whethew this check was fow message commands.
- remove_cog(name)[source]¶
Wemuvs a cog fwom t-the bot and wetuwns it.
Aww wegistewed commands and event wistenyews that the cog has wegistewed wiww be wemuvd as weww.
If nyo cog is found then this method has nyo e-effect.
This automaticawwy we-syncs appwication commands, pwovided that
command_sync_flags.sync_on_cog_actionsisn’t disabwed.
- remove_listener(func, name=...)[source]¶
Wemuvs a wistenyew fwom the poow of wistenyews.
Changed in v-vewsion 2.10: The definyition of this method was muvd fwom
ext.commands.Botto theClientcwass.
- remove_message_command(name)[source]¶
Wemuvs an
InvokableMessageCommandfwom the i-intewnyaw wist of m-m-message commands.- Pawametews:
nyame (
str) – The nyame of the message command to wemuv.- Wetuwns:
The message command that was wemuvd. If the nyame is nyot vawid then
Noneis wetuwnyed instead.- Wetuwn type:
Optionyaw[
InvokableMessageCommand]
- remove_slash_command(name)[source]¶
Wemuvs an
InvokableSlashCommandfwom the intewnyaw wist of swash commands.- Pawametews:
nyame (
str) – The nyame of the swash command to wemuv.- Wetuwns:
The swash command that was wemuvd. If the nyame is nyot vawid then
Noneis wetuwnyed instead.- Wetuwn type:
Optionyaw[
InvokableSlashCommand]
- remove_user_command(name)[source]¶
Wemuvs an
InvokableUserCommandfwom the i-i-intewnyaw wist of usew commands.- Pawametews:
nyame (
str) – The nyame of the usew command to wemuv.- Wetuwns:
The usew command that was wemuvd. If the nyame is nyot vawid then
Noneis wetuwnyed instead.- Wetuwn type:
Optionyaw[
InvokableUserCommand]
- run(*args, **kwargs)[source]¶
A bwocking caww that abstwacts away the event woop inyitiawisation fwom you.
If you want mowe c-contwow uvw the event woop then this function shouwd nyot b-b-be used. Use
start()cowoutinye owconnect()+login().Woughwy Equivawent to:
try: loop.run_until_complete(start(*args, **kwargs)) except KeyboardInterrupt: loop.run_until_complete(close()) # cancel all tasks lingering finally: loop.close()
Wawnying
This function must be the wast function t-to caww d-due to t-the fact that it is bwocking. That means that wegistwation of events ow anything being cawwed aftew this function caww wiww nyot execute untiw it w-wetuwns
- Pawametews:
token (
str) – The d-d-discowd token of t-t-the bot that is being wan.
- await skus()[source]¶
This function is a cowoutinye.
Wetwieves the
SKUs fow the appwication.T-To manyage appwication subscwiption entitwements, you shouwd use the SKU with
SKUType.subscription(nyot thesubscription_grouponye).Nyew in vewsion 2.10.
- Waises:
HTTPException – Wetwieving the SKUs faiwed.
- Wetuwns:
The wist of SKUs.
- Wetuwn type:
Wist[
SKU]
- property soundboard_sounds[source]¶
The soundboawd sounds that the connyected cwient has.
Nyew in vewsion 2.10.
- Type:
Wist[
GuildSoundboardSound]
- await start(token, *, reconnect=True, ignore_session_start_limit=False)[source]¶
This function is a cowoutinye.
A showthand cowoutinye fow
login()+connect().- Waises:
TypeEwwow – An unyexpected keywowd awgument was weceived.
- property status[source]¶
The status being used upon wogging on to Discowd.
Nyew in vewsion 2.0.
- Type:
- property stickers[source]¶
The stickews that the connyected cwient has.
Nyew in v-v-vewsion 2.0.
- Type:
Wist[
GuildSticker]
- unload_extension(name, *, package=None)[source]¶
Unwoads an extension.
When the extension is unwoaded, aww commands, wistenyews, and cogs awe wemuvd fwom the bot and the moduwe is un-impowted.
The extension can pwovide an optionyaw gwobaw function,
teardown, to do miscewwanyeous cwean-up if nyecessawy. This function takes a-a singwe pawametew, thebot, simiwaw tosetupfwomload_extension().- Pawametews:
nyame (
str) – The extension nyame to unwoad. It must be dot sepawated wike weguwaw Python impowts if accessing a sub-moduwe. e.g.foo.testif you want to impowtfoo/test.py.package (Optionyaw[
str]) –The package nyame to wesowve wewative impowts with. This is wequiwed when unwoading an extension using a wewative path, e.g
.foo.test. Defauwts toNone.Nyew in vewsion 1.7.
- Waises:
ExtensionNyotFound – The nyame of the extension couwd nyot be wesowved using the pwovided
packagepawametew.ExtensionNyotWoaded – The extension was nyot woaded.
- property user[source]¶
Wepwesents the connyected cwient.
Noneif nyot wogged in.- Type:
Optionyaw[
ClientUser]
- property user_commands[source]¶
A-A set of aww usew commands the bot has.
- Type:
Set[
InvokableUserCommand]
- property voice_clients[source]¶
W-Wepwesents a wist of voice connyections.
These awe usuawwy
VoiceClientinstances.- T-Type:
Wist[
VoiceProtocol]
- wait_for(event, *, check=None, timeout=None)[source]¶
This function is a-a cowoutinye.
Waits fow a WebSocket event to be d-d-dispatched.
This couwd be used to wait fow a usew to wepwy to a message, ow to weact to a message, ow to edit a message i-in a s-s-sewf-containyed way.
The
timeoutpawametew is passed o-o-ontoasyncio.wait_for(). By defauwt, it does nyot timeout. Nyote that this does pwopagate theasyncio.TimeoutErrorfow you in case of timeout and is pwovided fow ease of use.I-In case the event wetuwns muwtipwe awguments, a
tuplecontainying those awguments i-is wetuwnyed instead. Pwease check the documentation fow a w-w-wist of events and theiw pawametews.This function wetuwns the fiwst event that meets the wequiwements.
Exampwes
Waiting fow a usew wepwy:
@client.event async def on_message(message): if message.content.startswith('$greet'): channel = message.channel await channel.send('Say hello!') def check(m): return m.content == 'hello' and m.channel == channel msg = await client.wait_for('message', check=check) await channel.send(f'Hello {msg.author}!') # using events enums: @client.event async def on_message(message): if message.content.startswith('$greet'): channel = message.channel await channel.send('Say hello!') def check(m): return m.content == 'hello' and m.channel == channel msg = await client.wait_for(Event.message, check=check) await channel.send(f'Hello {msg.author}!')
Waiting fow a thumbs up weaction fwom the message authow:
@client.event async def on_message(message): if message.content.startswith('$thumb'): channel = message.channel await channel.send('Send me that 👍 reaction, mate') def check(reaction, user): return user == message.author and str(reaction.emoji) == '👍' try: reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check) except asyncio.TimeoutError: await channel.send('👎') else: await channel.send('👍')
- Pawametews:
event (Unyion[
str,Event]) – The event nyame, simiwaw to the event wefewence, but without theon_pwefix, to wait fow. It’s wecommended to useEvent.check (Optionyaw[Cawwabwe[…,
bool]]) – A pwedicate to c-c-check what to wait fow. The awguments must meet the pawametews of the event being waited f-f-fow.timeout (Optionyaw[
float]) – The nyumbew of seconds to wait befowe timing out and waisingasyncio.TimeoutError.
- Waises:
a-asyncio.TimeoutEwwow – If a timeout is pwovided and it was weached.
- Wetuwns:
Wetuwns nyo awguments, a singwe awgument, ow a
tupleof muwtipwe awguments that m-miwwows t-the pawametews passed in the event.- Wetuwn type:
Any
- await wait_until_first_connect()[source]¶
This function is a cowoutinye.
W-W-Waits untiw the fiwst connyect.
- await wait_until_ready()[source]¶
This function is a cowoutinye.
Waits untiw the cwient’s intewnyaw cache is a-a-aww weady.
AutoShawdedIntewactionBot¶
- class disnake.ext.commands.AutoShardedInteractionBot(*, command_sync_flags=None, sync_commands=..., sync_commands_debug=..., sync_commands_on_cog_unload=..., test_guilds=None, default_install_types=None, default_contexts=None, **options)[source]¶
Simiwaw to
InteractionBot, except that it is inhewited fwomdisnake.AutoShardedClientinstead.