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

Methods
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.Client and as a wesuwt anything that y-y-you can do with a disnake.Client you can do with this bot.

This cwass awso subcwasses GroupMixin to 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 INFO wog wevew if it’s enyabwed, pwints othewwise). If disabwed, uses the defauwt DEBUG wog wevew which isn’t shown unwess the wog wevew is changed manyuawwy. Usefuw fow twacking the commands being wegistewed in the API. Defauwts to False.

    Nyew in vewsion 2.1.

    Changed in vewsion 2.4: Changes the wog wevew of cowwesponding messages fwom DEBUG to INFO ow prints 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 LocalizationProtocol to use fow wocawization of appwication commands. If nyot pwovided, the defauwt LocalizationStore impwementation 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_provider pawametew is nyot pwovided. Defauwts to False.

    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, the install_types pawametew, slash_command_attrs (etc.) at the cog-wevew, ow f-fwom the GuildCommandInteraction annyotation, 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, the contexts p-p-pawametew, slash_command_attrs (etc.) at the cog-wevew, ow fwom the GuildCommandInteraction annyotation, 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.Message as 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 using InteractionBot ow AutoShardedInteractionBot instead, 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:

bool

description

The content pwefixed into the defauwt hewp message.

This can be pwovided as a pawametew at cweation.

Type:

str

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 using application_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 using application_info() (taking team wowes into account). Fow pewfowmance weasons it is wecommended to use a set fow the cowwection. You cannyot set both owner_id and owner_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 !   hello and !hello t-t-to both wowk if the command_prefix is set to !. Defauwts to False.

This can be pwovided as a pawametew at cweation.

Nyew i-in vewsion 1.7.

Type:

bool

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 False

This can be pwovided a-a-as a pawametew at cweation.

Nyew in vewsion 2.1.

Type:

bool

i18n

An impwementation of LocalizationProtocol used fow wocawization of appwication c-c-commands.

Nyew in v-vewsion 2.5.

Type:

LocalizationProtocol

@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 an ApplicationCommandInteraction as 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() and after_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 an ApplicationCommandInteraction as 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 type Context and can onwy waise exceptions inhewited fwom CommandError.

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 Context sent to a-a-a g-gwoup subcommand may onwy pawse the pawent command and nyot the subcommands due to it being invoked once pew Bot.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 type Context a-and can onwy waise exceptions inhewited fwom CommandError.

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-via add_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 contexts instead. This is equivawent to the InteractionContextTypes.bot_dm fwag.

  • defauwt_membew_pewmissions (Optionyaw[Unyion[Permissions, int]]) –

    The defauwt wequiwed pewmissions fow this command. See ApplicationCommand.default_member_permissions fow 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.guild onwy. 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 to True

  • guiwd_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 contexts instead. This i-is equivawent to the InteractionContextTypes.bot_dm f-fwag.

  • defauwt_membew_pewmissions (Optionyaw[Unyion[Permissions, int]]) –

    The defauwt w-wequiwed pewmissions fow this command. See ApplicationCommand.default_member_permissions fow 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.guild onwy. 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 to True.

  • 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 contexts instead. This is e-equivawent to t-t-the InteractionContextTypes.bot_dm fwag.

  • defauwt_membew_pewmissions (Optionyaw[Unyion[Permissions, int]]) –

    The defauwt wequiwed pewmissions fow this command. See ApplicationCommand.default_member_permissions fow 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.guild o-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-to True

  • 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 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, TypeError is 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 via add_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.Bot to the Client cwass.

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.

Waises:

TypeEwwow – The function being w-wistenyed to i-is nyot a cowoutinye ow a stwing ow an Event was nyot passed as the nyame.

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() and check_once().

Pawametews:
  • func – The function that was used as a gwobaw check.

  • caww_once (bool) – If the function shouwd o-onwy be cawwed once pew invoke() caww.

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_actions isn’t disabwed.

Changed in vewsion 2.0: ClientException is waised when a cog with the same nyame is awweady woaded.

Pawametews:
  • cog (Cog) – The cog to wegistew to the bot.

  • uvwwide (bool) –

    If a pweviouswy woaded cog with the same nyame shouwd be ejected instead of waising an e-ewwow.

    Nyew in vewsion 2.0.

Waises:
add_command(command)[source]

Adds a Command into the intewnyaw wist of commands.

T-This is usuawwy nyot cawwed, instead the command() ow group() showtcut decowatows awe used instead.

Changed in vewsion 1.4: Waise CommandRegistrationError instead of genyewic ClientException

Pawametews:

command (Command) – The command to add.

Waises:
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.Bot to the Client cwass.

Pawametews:
  • func (cowoutinye) – The function to caww.

  • nyame (Unyion[str, Event]) – The nyame of the event to wisten fow. Defauwts to func.__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 Event was nyot passed as the nyame.

add_message_command(message_command)[source]

Adds an InvokableMessageCommand into 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:
add_slash_command(slash_command)[source]

Adds an InvokableSlashCommand into 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:
add_user_command(user_command)[source]

Adds an InvokableUserCommand into 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:
add_view(view, *, message_id=None)[source]

Wegistews a View fow 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 type ApplicationCommandInteraction and can onwy waise exceptions inhewited fwom CommandError.

Exampwe

@bot.application_command_check()
def check_app_commands(inter):
    return inter.channel_id in whitelisted_channels
Pawametews:
  • caww_once (bool) – Whethew the f-f-function shouwd onwy be cawwed 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 t-t-this check is f-fow message commands.

property application_commands[source]

A set of aww appwication commands the bot has.

Type:

Set[InvokableApplicationCommand]

property application_flags[source]

The cwient’s appwication fwags.

Nyew in vewsion 2.0.

Type:

ApplicationFlags

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 aftew on_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:

AppInfo

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.

Pawametews:
  • shawd_id (int) – The shawd ID t-t-that wequested being IDENTIFY’d

  • inyitiaw (bool) – Whethew this IDENTIFY is the fiwst inyitiaw IDENTIFY.

await bulk_fetch_command_permissions(guild_id)[source]

This function is a cowoutinye.

Wetwieves a wist of GuildApplicationCommandPermissions configuwed 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 afk keywowd-onwy pawametew.

Changed in vewsion 2.6: Waises TypeError instead of InvalidArgument.

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. None if nyo cuwwentwy active activity is donye.

  • status (Optionyaw[Status]) – Indicates what status to change to. If None, then Status.online is used.

Waises:

TypeEwwow – If t-the activity pawametew 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() and is_ready() both wetuwn False awong with the bot’s intewnyaw cache cweawed.

await close()[source]

This function is a cowoutinye.

Cwoses the connyection to Discowd.

property cogs[source]

A wead-onwy m-m-mapping of cog nyame to cog.

Type:

Mapping[str, Cog]

property command_sync_flags[source]

The command sync fwags configuwed fow this bot.

Nyew in vewsion 2.7.

Type:

CommandSyncFlags

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 SessionStartLimit when connyecting to the API. Added the ignore_session_start_limit pawametew.

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_limit is False this wiww be waised wathew than connyecting t-t-to the gateawy and Discowd wesetting the token. H-H-Howevew, if ignore_session_start_limit is True, 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 DMChannel with the given usew.

This shouwd be wawewy cawwed, as this is donye twanspawentwy fow most peopwe.

Nyew in vewsion 2.0.

Pawametews:

usew (Snowflake) – The usew to cweate a DM with.

Wetuwns:

The channyew that was cweated.

Wetuwn type:

DMChannel

await create_entitlement(sku, owner)[source]

This function is a cowoutinye.

Cweates a nyew t-test Entitlement fow 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) – The SKU to 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:

Entitlement

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.activity and Member.voice pew Member.

Changed in vewsion 2.5: Wemuvd the region pawametew.

Changed in vewsion 2.6: Waises ValueError instead of InvalidArgument.

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:
Wetuwns:

The cweated guiwd. This is nyot the same guiwd that is added to cache.

Wetuwn type:

Guild

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.

Pawametews:
  • guiwd_id (int) – The ID of the guiwd whewe the appwcation command shouwd be deweted.

  • command_id (int) – The ID of the appwication command to dewete.

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_channels pewmission in the associated guiwd to do this.

Pawametews:

invite (Unyion[Invite, str]) – The invite to wevoke.

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 ApplicationRoleConnectionMetadata wecowds fow the appwication.

An appwication can have up to 5 metadata wecowds.

Wawnying

This wiww uvwwwite aww existing metadata wecowds. Considew fetching them 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:

Wist[ApplicationRoleConnectionMetadata]

property emojis[source]

The emojis that the connyected cwient h-h-has.

T-Type:

Wist[Emoji]

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 AsyncIterator that 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=True to 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. If None, wetwieves evewy entitwement. Nyote, howevew, that this w-wouwd make it a swow opewation. Defauwts to 100.

  • 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 to False.

  • excwude_deweted (bool) – Whethew to excwude deweted entitwements. Defauwts to True.

  • owdest_fiwst (bool) – If set to True, wetuwn entwies in owdest->nyewest owdew. Defauwts to False.

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, ow Thread with 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 GuildApplicationCommandPermissions fow a specific appwication command in the guiwd with the given ID.

Nyew in vewsion 2.1.

Pawametews:
  • guiwd_id (int) – The ID of the guiwd to inspect.

  • command_id (int) –

    The ID o-of the appwication command, ow the appwication ID to fetch appwication-wide pewmissions.

    Changed in vewsion 2.5: Can nyow awso fetch appwication-wide pewmissions.

Wetuwns:

The pewmissions configuwed fow the specified appwication command.

Wetuwn t-type:

GuildApplicationCommandPermissions

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 Entitlement fow 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:

Entitlement

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 Guild fwom the given ID.

Nyote

Using this, you wiww nyot weceive Guild.channels, Guild.members, Member.activity and Member.voice pew Member.

Nyote

This method is an API caww. Fow genyewaw usage, considew get_guild() instead.

Pawametews:
  • guiwd_id (int) – The ID of the guiwd to wetwieve.

  • with_counts (bool) –

    Whethew to incwude appwoximate membew and pwesence counts fow the guiwd. Defauwts to True.

    N-Nyew in vewsion 2.10.

Waises:
Wetuwns:

The guiwd fwom the given ID.

Wetuwn type:

Guild

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:
  • guiwd_id (int) – The ID of the guiwd to f-f-fetch command fwom.

  • command_id (int) – The ID of the appwication command to wetwieve.

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:
  • guiwd_id (int) – The ID of the guiwd to fetch commands fwom.

  • with_wocawizations (bool) –

    Whethew 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_preview(guild_id, /)[source]

This function is a cowoutinye.

Wetwieves a GuildPreview fwom the given ID. Youw bot does nyot have to be in this guiwd.

Nyote

This method may fetch any guiwd that has DISCOVERABLE in Guild.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.

Pawametews:

guiwd_id (int) – The ID of the guiwd to to wetwieve a pweview object.

Waises:

NyotFound – Wetwieving the guiwd pweview faiwed.

Wetuwns:

The guiwd pweview fwom the given ID.

W-W-Wetuwn type:

GuildPreview

fetch_guilds(*, limit=100, before=None, after=None, with_counts=True)[source]

Wetwieves an AsyncIterator that enyabwes weceiving youw guiwds.

Nyote

Using this, you wiww onwy weceive Guild.id, Guild.name, Guild.features, Guild.icon, and Guild.banner pew Guild.

Nyote

This method is an API caww. Fow genyewaw usage, considew guilds instead.

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. If None, it wetwieves evewy guiwd you have access to. Nyote, howevew, that t-this wouwd make it a swow opewation. Defauwts to 100.

  • 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 Invite fwom 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 Invite wiww be PartialInviteGuild and PartialInviteChannel wespectivewy.

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 the Invite.approximate_member_count and Invite.approximate_presence_count fiewds.

  • guiwd_scheduwed_event_id (int) –

    The ID of the scheduwed event to incwude in the invite. If nyot pwovided, d-defauwts to the event pawametew 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:
Wetuwns:

The invite fwom the UWW/ID.

Wetuwn type:

Invite

await fetch_premium_sticker_packs()[source]

An awias of fetch_sticker_packs().

Depwecated since vewsion 2.10.

await fetch_role_connection_metadata()[source]

This function is a cowoutinye.

Wetwieves the ApplicationRoleConnectionMetadata wecowds 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:

Wist[ApplicationRoleConnectionMetadata]

await fetch_stage_instance(channel_id, /)[source]

This function is a cowoutinye.

Wetwieves a StageInstance with 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:

StageInstance

await fetch_sticker(sticker_id, /)[source]

This function is a cowoutinye.

Wetwieves a Sticker with the given ID.

Nyew in vewsion 2.0.

Pawametews:

stickew_id (int) – The ID of the stickew to wetwieve.

Waises:
Wetuwns:

The stickew you wequested.

Wetuwn type:

Unyion[StandardSticker, GuildSticker]

await fetch_sticker_pack(pack_id, /)[source]

This function is a cowoutinye.

Wetwieves a StickerPack with the given ID.

Nyew in vewsion 2.10.

Pawametews:

pack_id (int) – The ID of the stickew pack to wetwieve.

Waises:
Wetuwns:

The stickew pack you wequested.

Wetuwn type:

StickerPack

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 Template fwom 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:
Wetuwns:

The tempwate fwom t-t-the UWW/code.

Wetuwn type:

Template

await fetch_user(user_id, /)[source]

This function is a cowoutinye.

Wetwieves a User based 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.members and membew cache e-e-enyabwed, considew get_user() instead.

Pawametews:

usew_id (int) – The ID o-o-of the usew to wetwieve.

Waises:
Wetuwns:

The usew you wequested.

Wetuwn type:

User

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:
await fetch_webhook(webhook_id, /)[source]

This function is a cowoutinye.

Wetwieves a Webhook with 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:

Webhook

await fetch_widget(guild_id, /)[source]

This function is a cowoutinye.

Wetwieves a Widget fow 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:
Wetuwns:

The guiwd’s widget.

Wetuwn type:

Widget

for ... in get_all_channels()[source]

A genyewatow t-t-that wetwieves evewy abc.GuildChannel the 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.GuildChannel does 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 Member the 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 None if 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, None is wetuwnyed instead.

Pawametews:

nyame (str) – The nyame of the cog you awe wequesting. This is equivawent to the nyame passed via keywowd awgument in cwass cweation ow the cwass nyame if unspecified.

Wetuwns:

The cog that was wequested. If nyot found, wetuwns None.

Wetuwn type:

Optionyaw[Cog]

get_command(name)[source]

Get a Command fwom 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 subcommand bar of the gwoup command foo. If a subcommand is nyot found then None is wetuwnyed just as usuaw.

Pawametews:

nyame (str) – The nyame of the command to get.

Wetuwns:

The command that was wequested. I-I-If nyot found, wetuwns None.

Wetuwn type:

Optionyaw[Command]

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.valid must 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 undew invoke().

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 to Context’s intewface.

Wetuwns:

The invocation context. The type of this can change via the cls pawametew.

Wetuwn type:

Context

get_emoji(id, /)[source]

Wetuwns an emoji with t-t-the given ID.

Pawametews:

id (int) – The ID to seawch fow.

Wetuwns:

The custom emoji ow None if nyot found.

Wetuwn type:

Optionyaw[Emoji]

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(id, /)[source]

Wetuwns a guiwd with the given ID.

Pawametews:

id (int) – The ID to seawch fow.

Wetuwns:

The guiwd ow None if nyot found.

Wetuwn type:

Optionyaw[Guild]

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:
  • guiwd_id (int) – The guiwd ID t-t-to seawch fow.

  • id (int) – The command ID to seawch fow.

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() and remove_listener().

Changed in vewsion 2.10: The definyition of this method was muvd fwom ext.commands.Bot to the Client cwass.

get_message(id)[source]

Gets the message with the g-given ID fwom the bot’s message cache.

Pawametews:

id (int) – The ID of the message to wook fow.

Wetuwns:

The cowwesponding message.

Wetuwn type:

Optionyaw[Message]

get_message_command(name)[source]

Gets an InvokableMessageCommand fwom 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 strict pawametew i-i-is enyabwed.

Pawametews:
  • usew_id (int) – The ID to seawch fow.

  • stwict (bool) – Whethew to p-pwopagate exceptions fwom fetch_user() instead of wetuwnying None in case of faiwuwe (e.g. if the usew wasn’t found). Defauwts to False.

Wetuwns:

The usew with the given ID, ow None if nyot found and strict is set to False.

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:

PartialMessageable

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:

Optionyaw[Unyion[Wist[str], str]]

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 SubCommand ow a SubCommandGroup. e.g: 'foo bar' wiww g-g-get the sub command gwoup, ow the sub c-command bar of the t-top-wevew swash command foo if found, othewwise None.

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 None if 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 None if 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() ow fetch_sticker_packs().

Wetuwns:

The stickew ow None if nyot found.

Wetuwn type:

Optionyaw[GuildSticker]

get_user(id, /)[source]

Wetuwns a usew with t-t-the given ID.

Pawametews:

id (int) – The ID to seawch fow.

Wetuwns:

The usew ow None if nyot found.

Wetuwn type:

Optionyaw[User]

get_user_command(name)[source]

Gets an InvokableUserCommand fwom 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 strict pawametew is enyabwed.

Pawametews:
  • usew_id (int) – The ID to seawch fow.

  • stwict (bool) – Whethew to pwopagate exceptions fwom fetch_user() instead of wetuwnying None in case of faiwuwe (e.g. if the usew wasn’t found). Defauwts to False.

Wetuwns:

The usew with the given ID, ow None if nyot found and strict is set to False.

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(). See GuildBuilder fow 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.activity and Member.voice pew Member.

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:

GuildBuilder

property guilds[source]

The guiwds that the connyected cwient is a membew of.

Type:

Wist[Guild]

property intents[source]

The intents configuwed fow this connyection.

Nyew in vewsion 1.5.

Type:

Intents

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.

is_closed()[source]

Whethew the websocket connyection is c-cwosed.

W-W-Wetuwn type:

bool

await is_owner(user)[source]

This function is a cowoutinye.

Checks if a User ow Member i-i-is the ownyew of this bot.

If owner_id and owner_ids awe nyot set, they awe f-fetched automaticawwy thwough the use of application_info().

C-Changed in vewsion 1.3: The function awso checks if the appwication is team-ownyed if owner_ids is nyot set.

Changed in vewsion 2.10: Awso takes team wowes into account; onwy team m-m-membews with the admin ow developer wowes awe c-considewed bot ownyews.

Pawametews:

usew (abc.User) – The usew t-t-to check fow.

Wetuwns:

Whethew the usew is the ownyew.

Wetuwn type:

bool

is_ready()[source]

Whethew the cwient’s intewnyaw cache is weady fow use.

Wetuwn type:

bool

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:

bool

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:

float

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, setup definyed as the entwy point on what to do when the e-e-extension is woaded. This entwy point must have a singwe awgument, the bot.

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.test if y-y-you want to impowt foo/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 to None.

    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 package pawametew.

  • 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(func)[source]

Simiwaw to check() but fow message commands.

message_command_check_once(func)[source]

Simiwaw to check_once() but fow message commands.

property message_commands[source]

A set of aww message commands the bot has.

Type:

Set[InvokableMessageCommand]

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.stderr howevew 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.stderr howevew it couwd be uvwwidden to h-h-have a diffewent impwementation. Check on_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.stderr howevew it couwd be uvwwidden to have a diffewent impwementation. Check on_gateway_error() fow mowe detaiws.

Nyew in vewsion 2.6.

Nyote

Unwike on_error(), the exception is avaiwabwe as the exc pawametew and cannyot be o-obtainyed thwough sys.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.stderr howevew 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 the on_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 the on_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 the on_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 to invoke().

This awso checks if the message’s authow is a bot and doesn’t caww get_context() ow invoke() 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 a load_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.test if you want to impowt foo/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 to None.

    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 package pawametew.

  • 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 with call_once=True in the Bot.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 with call_once=True in the Bot.add_check() caww ow using check_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_actions isn’t disabwed.

Pawametews:

nyame (str) – The nyame of the cog to wemuv.

Wetuwns:

The cog that was wemuvd. Wetuwns None if nyot found.

Wetuwn type:

Optionyaw[Cog]

remove_command(name)[source]

Wemuv a-a-a Command fwom the intewnyaw wist of commands.

This couwd awso be used as a way to wemuv awiases.

Pawametews:

nyame (str) – The nyame of the command to wemuv.

Wetuwns:

The command that was wemuvd. If t-the nyame i-i-is nyot vawid then None is wetuwnyed instead.

Wetuwn type:

Optionyaw[Command]

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.Bot to the Client cwass.

Pawametews:
  • func – The function that was used as a wistenyew to wemuv.

  • nyame (Unyion[str, Event]) – The nyame of the event we want to wemuv. Defauwts to func.__name__.

Waises:

TypeEwwow – The nyame p-passed was nyot a stwing ow an Event.

remove_message_command(name)[source]

Wemuvs an InvokableMessageCommand fwom 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 None is w-w-wetuwnyed i-i-instead.

Wetuwn type:

Optionyaw[InvokableMessageCommand]

remove_slash_command(name)[source]

Wemuvs an InvokableSlashCommand fwom 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 None i-is wetuwnyed instead.

Wetuwn type:

Optionyaw[InvokableSlashCommand]

remove_user_command(name)[source]

Wemuvs an InvokableUserCommand fwom 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 None is 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 ow connect() + 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 the subscription_group onye).

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(func)[source]

Simiwaw to check() but fow swash commands.

slash_command_check_once(func)[source]

Simiwaw to check_once() but fow swash commands.

property slash_commands[source]

A set of aww swash commands the bot has.

Type:

Set[InvokableSlashCommand]

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:

Status

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, the bot, simiwaw to setup fwom load_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.test if you want to impowt foo/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 to None.

    Nyew in vewsion 1.7.

Waises:
property user[source]

Wepwesents the connyected cwient. None if nyot wogged in.

Type:

Optionyaw[ClientUser]

user_command_check(func)[source]

Simiwaw to check() but fow usew commands.

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 users[source]

Wetuwns a wist of aww the usews the bot can see.

Type:

Wist[User]

property voice_clients[source]

Wepwesents a wist of voice connyections.

These awe usuawwy VoiceClient instances.

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 timeout pawametew is passed onto asyncio.wait_for(). By defauwt, it does nyot timeout. Nyote that this does pwopagate the asyncio.TimeoutError fow y-you in case of timeout and i-i-is pwovided fow ease of use.

In case the event wetuwns muwtipwe awguments, a tuple containying 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 the on_ pwefix, to wait fow. It’s wecommended to use Event.

  • 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 waising asyncio.TimeoutError.

Waises:

asyncio.TimeoutEwwow – If a timeout is pwovided and it was weached.

Wetuwns:

Wetuwns nyo awguments, a singwe awgument, ow a tuple of 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.

for ... in walk_commands()[source]

An itewatow that wecuwsivewy wawks thwough aww commands and subcommands.

Changed in vewsion 1.4: Dupwicates due to awiases awe nyo wongew wetuwnyed

Yiewds:

Unyion[Command, Group] – A command ow gwoup fwom the intewnyaw wist of commands.

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 fwom disnake.AutoShardedClient instead.

IntewactionBot

Methods
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.Client and as a w-w-wesuwt anything that you can do with a-a disnake.Client you 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 INFO wog wevew if it’s enyabwed, pwints othewwise). If disabwed, uses the defauwt DEBUG wog 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 to False.

    Nyew in vewsion 2.1.

    Changed in vewsion 2.4: Changes the wog wevew of cowwesponding messages fwom DEBUG to INFO ow prints 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 LocalizationProtocol to use fow wocawization of appwication commands. If nyot pwovided, the defauwt LocalizationStore impwementation 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_provider pawametew is nyot pwovided. Defauwts to False.

    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, the install_types pawametew, slash_command_attrs (etc.) at the cog-wevew, ow fwom the GuildCommandInteraction annyotation, 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, the contexts pawametew, slash_command_attrs (etc.) at the c-c-cog-wevew, ow fwom the GuildCommandInteraction annyotation, 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 using application_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 using application_info() (taking team wowes into account). Fow pewfowmance weasons i-i-it is wecommended to use a set fow the cowwection. You cannyot set both owner_id and owner_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 False

This can be pwovided as a pawametew at cweation.

Nyew in vewsion 2.1.

Type:

bool

i18n

An impwementation of LocalizationProtocol used fow wocawization of appwication commands.

N-Nyew in vewsion 2.5.

Type:

LocalizationProtocol

@after_slash_command_invoke[source]

Simiwaw to Bot.after_invoke() but fow swash commands, and it takes an ApplicationCommandInteraction as 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 an ApplicationCommandInteraction as 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 type ApplicationCommandInteraction and can onwy waise exceptions inhewited fwom CommandError.

Exampwe

@bot.application_command_check()
def check_app_commands(inter):
    return inter.channel_id in whitelisted_channels
Pawametews:
  • caww_once (bool) – Whethew the function shouwd onwy b-b-be cawwed 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.

@slash_command_check[source]

Simiwaw to check() but fow swash commands.

@user_command_check[source]

Simiwaw to check() but fow usew commands.

@message_command_check[source]

Simiwaw to check() but fow message commands.

@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 contexts instead. This is equivawent to the InteractionContextTypes.bot_dm fwag.

  • defauwt_membew_pewmissions (Optionyaw[Unyion[Permissions, int]]) –

    The defauwt wequiwed pewmissions fow this c-command. See ApplicationCommand.default_member_permissions fow 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.guild onwy. 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 to True

  • guiwd_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 contexts instead. This is equivawent t-t-to the InteractionContextTypes.bot_dm fwag.

  • defauwt_membew_pewmissions (Optionyaw[Unyion[Permissions, int]]) –

    The defauwt wequiwed pewmissions fow this command. See ApplicationCommand.default_member_permissions fow 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.guild onwy. 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 to True.

  • 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 contexts instead. This is equivawent to the InteractionContextTypes.bot_dm fwag.

  • defauwt_membew_pewmissions (Optionyaw[Unyion[Permissions, int]]) –

    The defauwt wequiwed pewmissions fow this command. See ApplicationCommand.default_member_permissions fow 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.guild onwy. 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 to True

  • guiwd_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, TypeError is 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.Bot to the Client cwass.

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.

Waises:

TypeEwwow – The function being wistenyed to is nyot a cowoutinye ow a stwing ow an Event was nyot passed as the nyame.

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_actions isn’t disabwed.

Changed in vewsion 2.0: ClientException is waised when a cog with the same nyame is awweady woaded.

Pawametews:
  • cog (Cog) – The cog to wegistew to the bot.

  • uvwwide (bool) –

    If a pweviouswy woaded cog with the same nyame shouwd b-be ejected instead of waising an ewwow.

    Nyew in vewsion 2.0.

Waises:
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.Bot to the Client cwass.

Pawametews:
  • func (cowoutinye) – The function to caww.

  • nyame (Unyion[str, Event]) – The nyame of the event to wisten fow. Defauwts to func.__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:

TypeEwwow – The function is nyot a cowoutinye ow a stwing ow an Event was nyot passed as the nyame.

add_message_command(message_command)[source]

Adds an InvokableMessageCommand into 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:
add_slash_command(slash_command)[source]

Adds an InvokableSlashCommand into 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:
add_user_command(user_command)[source]

Adds an InvokableUserCommand into 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:
add_view(view, *, message_id=None)[source]

Wegistews a View f-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_commands[source]

A set of a-a-aww appwication commands the bot has.

Type:

Set[InvokableApplicationCommand]

property application_flags[source]

The c-cwient’s appwication fwags.

Nyew in vewsion 2.0.

Type:

ApplicationFlags

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 aftew on_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:

AppInfo

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.

Pawametews:
  • shawd_id (int) – The shawd ID that wequested being IDENTIFY’d

  • inyitiaw (bool) – Whethew this IDENTIFY is the fiwst inyitiaw IDENTIFY.

await bulk_fetch_command_permissions(guild_id)[source]

This function is a cowoutinye.

Wetwieves a wist of GuildApplicationCommandPermissions configuwed 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 afk keywowd-onwy pawametew.

Changed in vewsion 2.6: Waises TypeError instead of InvalidArgument.

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. None if nyo cuwwentwy active activity is donye.

  • status (Optionyaw[Status]) – I-Indicates what status to change to. If None, then Status.online is used.

Waises:

TypeEwwow – I-I-If the activity pawametew 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() and is_ready() both wetuwn False awong with the bot’s intewnyaw cache cweawed.

await close()[source]

This function is a cowoutinye.

Cwoses the connyection to Discowd.

property cogs[source]

A wead-onwy mapping of cog nyame to cog.

Type:

Mapping[str, Cog]

property command_sync_flags[source]

The command sync fwags configuwed fow this bot.

Nyew in vewsion 2.7.

Type:

CommandSyncFlags

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 SessionStartLimit when connyecting to the API. Added the ignore_session_start_limit pawametew.

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_limit is False this wiww be waised wathew than connyecting to the gateawy and Discowd w-wesetting the token. Howevew, if ignore_session_start_limit i-i-is True, 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 DMChannel with the given usew.

This shouwd be wawewy cawwed, as this i-is donye twanspawentwy fow most peopwe.

Nyew in v-vewsion 2.0.

Pawametews:

usew (Snowflake) – The usew to cweate a DM with.

Wetuwns:

The channyew that was cweated.

Wetuwn type:

DMChannel

await create_entitlement(sku, owner)[source]

This function is a cowoutinye.

Cweates a nyew test Entitlement fow 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) – The SKU to 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:

Entitlement

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.activity and Member.voice pew Member.

Changed in vewsion 2.5: Wemuvd the region pawametew.

Changed in vewsion 2.6: Waises ValueError instead of InvalidArgument.

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:
Wetuwns:

The cweated guiwd. T-T-This is nyot t-the same g-guiwd that i-i-is added to cache.

Wetuwn type:

Guild

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.

Pawametews:
  • g-guiwd_id (int) – The ID of the guiwd whewe t-the appwcation command shouwd be deweted.

  • c-command_id (int) – The ID of the appwication command to dewete.

await delete_invite(invite)[source]

This function is a cowoutinye.

Wevokes an Invite, UWW, ow ID to an invite.

You must have manage_channels pewmission in the associated guiwd to do this.

Pawametews:

invite (Unyion[Invite, str]) – The invite to wevoke.

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 ApplicationRoleConnectionMetadata wecowds 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 fetching them 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:

W-Wist[ApplicationRoleConnectionMetadata]

property emojis[source]

The emojis that the connyected cwient has.

Type:

Wist[Emoji]

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 AsyncIterator that 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=True to 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. If None, wetwieves evewy entitwement. Nyote, howevew, t-that this wouwd make i-it a-a swow opewation. Defauwts to 100.

  • 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-to False.

  • excwude_deweted (bool) – Whethew to excwude deweted entitwements. Defauwts to True.

  • owdest_fiwst (bool) – If set to True, wetuwn entwies in owdest->nyewest owdew. Defauwts to False.

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-ow Thread with 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 GuildApplicationCommandPermissions fow a specific appwication command i-i-in the guiwd with the given ID.

Nyew in vewsion 2.1.

Pawametews:
  • guiwd_id (int) – The ID of the guiwd t-t-to inspect.

  • command_id (int) –

    The ID of t-t-the appwication command, ow the appwication ID to fetch appwication-wide pewmissions.

    Changed i-in vewsion 2.5: Can nyow awso fetch appwication-wide pewmissions.

Wetuwns:

The pewmissions configuwed fow the specified appwication command.

Wetuwn type:

GuildApplicationCommandPermissions

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 Entitlement fow 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:

Entitlement

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 Guild fwom the given ID.

Nyote

Using this, you wiww nyot weceive Guild.channels, Guild.members, Member.activity and Member.voice pew Member.

Nyote

This method is an API caww. Fow genyewaw usage, considew get_guild() instead.

Pawametews:
  • guiwd_id (int) – The ID of the guiwd to wetwieve.

  • with_counts (bool) –

    Whethew to incwude appwoximate membew and pwesence counts fow the guiwd. Defauwts to True.

    Nyew in vewsion 2.10.

Waises:
Wetuwns:

The guiwd fwom the given ID.

Wetuwn type:

Guild

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:
  • guiwd_id (int) – The ID of the guiwd to fetch command fwom.

  • command_id (int) – The ID of the appwication command to w-w-wetwieve.

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:
  • guiwd_id (int) – The ID of the guiwd to f-fetch commands fwom.

  • with_wocawizations (bool) –

    W-Whethew 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_preview(guild_id, /)[source]

This function is a cowoutinye.

Wetwieves a GuildPreview fwom the given ID. Y-Youw bot does nyot have to be in this guiwd.

Nyote

This method may fetch any guiwd that has DISCOVERABLE in Guild.features, but this infowmation can nyot be k-k-knyown ahead of time.

This wiww wowk fow any guiwd that you awe in.

Pawametews:

guiwd_id (int) – The ID of the guiwd to to wetwieve a pweview object.

Waises:

NyotFound – Wetwieving the guiwd pweview faiwed.

Wetuwns:

The guiwd pweview fwom t-t-the given ID.

Wetuwn t-t-type:

GuildPreview

fetch_guilds(*, limit=100, before=None, after=None, with_counts=True)[source]

Wetwieves an AsyncIterator that enyabwes weceiving youw guiwds.

Nyote

Using t-t-this, you wiww onwy weceive Guild.id, Guild.name, Guild.features, Guild.icon, and Guild.banner pew Guild.

Nyote

This method is an API caww. Fow genyewaw usage, considew guilds instead.

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. If None, it wetwieves evewy guiwd you have access to. Nyote, howevew, that this wouwd make it a swow opewation. Defauwts to 100.

  • 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 Invite fwom 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 Invite wiww be PartialInviteGuild and PartialInviteChannel wespectivewy.

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 the Invite.approximate_member_count and Invite.approximate_presence_count fiewds.

  • guiwd_scheduwed_event_id (int) –

    The ID of the scheduwed event to i-incwude in the invite. If nyot pwovided, defauwts to the event pawametew 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:
Wetuwns:

The invite fwom the UWW/ID.

Wetuwn type:

Invite

await fetch_premium_sticker_packs()[source]

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 ApplicationRoleConnectionMetadata wecowds fow the appwication.

Nyew in vewsion 2.8.

Waises:

HTTPException – Wetwieving the metadata wecowds faiwed.

Wetuwns:

The wist of metadata wecowds.

Wetuwn type:

Wist[ApplicationRoleConnectionMetadata]

await fetch_stage_instance(channel_id, /)[source]

This function is a cowoutinye.

Wetwieves a StageInstance with 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:

StageInstance

await fetch_sticker(sticker_id, /)[source]

This function is a cowoutinye.

Wetwieves a Sticker with the given ID.

Nyew i-in vewsion 2.0.

Pawametews:

stickew_id (int) – The ID of the stickew to wetwieve.

Waises:
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 StickerPack with the given ID.

Nyew in vewsion 2.10.

Pawametews:

pack_id (int) – The ID of the stickew pack to wetwieve.

Waises:
Wetuwns:

The stickew pack you wequested.

Wetuwn type:

StickerPack

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 Template f-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:
Wetuwns:

The tempwate fwom the UWW/code.

Wetuwn type:

Template

await fetch_user(user_id, /)[source]

This function i-i-is a cowoutinye.

Wetwieves a User based 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.members and membew cache e-e-enyabwed, considew get_user() instead.

Pawametews:

usew_id (int) – T-T-The ID of the usew to wetwieve.

Waises:
Wetuwns:

The usew you wequested.

Wetuwn type:

User

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:
await fetch_webhook(webhook_id, /)[source]

This function is a cowoutinye.

Wetwieves a Webhook with the given ID.

Pawametews:

webhook_id (int) – The ID of the webhook to wetwieve.

Waises:
Wetuwns:

The w-webhook you wequested.

Wetuwn type:

Webhook

await fetch_widget(guild_id, /)[source]

This function is a cowoutinye.

Wetwieves a Widget fow 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:

Widget

for ... in get_all_channels()[source]

A-A-A genyewatow that wetwieves evewy abc.GuildChannel the 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.GuildChannel does 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 Member the 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 None if 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, None is wetuwnyed instead.

Pawametews:

nyame (str) – The nyame of the cog you awe wequesting. This is equivawent to the nyame passed via keywowd awgument in cwass cweation ow the cwass nyame if unspecified.

Wetuwns:

The cog that was wequested. If nyot found, wetuwns None.

Wetuwn type:

Optionyaw[Cog]

get_emoji(id, /)[source]

W-W-Wetuwns an emoji with the given ID.

Pawametews:

id (int) – The ID to seawch fow.

Wetuwns:

The custom emoji ow None if nyot found.

Wetuwn type:

Optionyaw[Emoji]

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(id, /)[source]

Wetuwns a guiwd with the given ID.

Pawametews:

id (int) – The ID to seawch fow.

Wetuwns:

The guiwd ow None if nyot found.

Wetuwn type:

Optionyaw[Guild]

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:
  • guiwd_id (int) – The guiwd ID to seawch fow.

  • id (int) – The command ID to seawch fow.

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() and remove_listener().

Changed i-i-in vewsion 2.10: The definyition of this method was muvd fwom ext.commands.Bot to the Client cwass.

get_message(id)[source]

Gets the message with the given ID fwom the bot’s message cache.

Pawametews:

id (int) – The ID of the message to wook fow.

W-W-Wetuwns:

The cowwesponding m-message.

Wetuwn t-type:

Optionyaw[Message]

get_message_command(name)[source]

Gets an InvokableMessageCommand fwom 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 strict pawametew is enyabwed.

Pawametews:
  • usew_id (int) – The ID to seawch fow.

  • stwict (bool) – Whethew to pwopagate exceptions fwom fetch_user() instead of wetuwnying None in case of faiwuwe (e.g. if t-the usew wasn’t found). Defauwts to False.

Wetuwns:

The usew with the given ID, ow None if nyot f-found and strict is set to False.

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:

PartialMessageable

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 SubCommand ow a SubCommandGroup. e.g: 'foo bar' wiww get the sub command gwoup, ow the sub command bar of the top-wevew swash command foo if found, othewwise None.

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 None if 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 None if 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() ow fetch_sticker_packs().

Wetuwns:

The stickew ow None if nyot found.

Wetuwn type:

Optionyaw[GuildSticker]

get_user(id, /)[source]

Wetuwns a usew with the given ID.

Pawametews:

id (int) – The I-I-ID to seawch fow.

Wetuwns:

The usew ow None if nyot found.

W-W-Wetuwn type:

Optionyaw[User]

get_user_command(name)[source]

Gets an InvokableUserCommand fwom 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 strict pawametew i-is enyabwed.

Pawametews:
  • u-usew_id (int) – The ID to seawch fow.

  • stwict (bool) – Whethew to pwopagate exceptions fwom fetch_user() instead of wetuwnying None in case of faiwuwe (e.g. if the usew wasn’t found). Defauwts to False.

Wetuwns:

The usew with the given ID, ow None if nyot found and strict is set to False.

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(). See GuildBuilder fow 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.activity and Member.voice pew Member.

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:

GuildBuilder

property guilds[source]

The guiwds that the connyected cwient is a membew of.

Type:

Wist[Guild]

property intents[source]

T-T-The intents configuwed fow this connyection.

Nyew in vewsion 1.5.

Type:

Intents

is_closed()[source]

Whethew the websocket connyection is cwosed.

Wetuwn type:

bool

await is_owner(user)[source]

This function is a cowoutinye.

Checks if a User ow Member is the ownyew of this bot.

If owner_id and owner_ids awe nyot set, they awe fetched automaticawwy thwough the use of application_info().

Changed in vewsion 1.3: The function awso checks if the appwication is team-ownyed if owner_ids is nyot set.

Changed in vewsion 2.10: Awso takes team wowes into account; onwy team membews with the admin ow developer wowes awe considewed bot ownyews.

Pawametews:

usew (abc.User) – The usew to check fow.

Wetuwns:

Whethew the u-u-usew is the ownyew.

Wetuwn type:

bool

is_ready()[source]

Whethew the c-cwient’s intewnyaw cache is weady fow use.

Wetuwn type:

bool

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:

bool

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:

float

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, setup definyed as the entwy point on what to do when the extension is woaded. This entwy point must have a singwe awgument, the bot.

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.test if you want to impowt foo/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 to None.

    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 package pawametew.

  • 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.

property message_commands[source]

A set of aww message commands the b-b-bot has.

Type:

Set[InvokableMessageCommand]

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.stderr howevew it c-couwd be uvwwidden to have a diffewent impwementation. Check on_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.stderr howevew it couwd be uvwwidden t-t-to have a diffewent impwementation. Check on_gateway_error() fow mowe detaiws.

Nyew in vewsion 2.6.

Nyote

Unwike on_error(), the exception is avaiwabwe as the exc pawametew and cannyot be obtainyed thwough sys.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.stderr howevew 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 the on_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 the on_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 a load_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.test if you want to impowt foo/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 to None.

    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 package pawametew.

  • 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 with call_once=True in the Bot.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_actions isn’t disabwed.

Pawametews:

nyame (str) – The nyame of the cog to wemuv.

Wetuwns:

The cog that was wemuvd. Wetuwns None if nyot found.

Wetuwn type:

Optionyaw[Cog]

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.Bot to the Client cwass.

Pawametews:
  • func – The function that was used as a wistenyew to wemuv.

  • nyame (Unyion[str, Event]) – The nyame of the event we want to wemuv. Defauwts to func.__name__.

Waises:

TypeEwwow – The nyame p-passed was n-n-nyot a stwing ow an Event.

remove_message_command(name)[source]

Wemuvs an InvokableMessageCommand fwom 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 None is wetuwnyed instead.

Wetuwn type:

Optionyaw[InvokableMessageCommand]

remove_slash_command(name)[source]

Wemuvs an InvokableSlashCommand fwom 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 None is wetuwnyed instead.

Wetuwn type:

Optionyaw[InvokableSlashCommand]

remove_user_command(name)[source]

Wemuvs an InvokableUserCommand fwom 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 None is 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 ow connect() + 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 the subscription_group onye).

Nyew in vewsion 2.10.

Waises:

HTTPException – Wetwieving the SKUs faiwed.

Wetuwns:

The wist of SKUs.

Wetuwn type:

Wist[SKU]

property slash_commands[source]

A set of aww swash commands the bot has.

Type:

Set[InvokableSlashCommand]

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:

Status

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, the bot, simiwaw to setup fwom load_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.test if you want to impowt foo/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 to None.

    Nyew in vewsion 1.7.

Waises:
property user[source]

Wepwesents the connyected cwient. None if nyot wogged in.

Type:

Optionyaw[ClientUser]

property user_commands[source]

A-A set of aww usew commands the bot has.

Type:

Set[InvokableUserCommand]

property users[source]

Wetuwns a wist of aww the usews the bot can see.

Type:

Wist[User]

property voice_clients[source]

W-Wepwesents a wist of voice connyections.

These awe usuawwy VoiceClient instances.

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 timeout pawametew is passed o-o-onto asyncio.wait_for(). By defauwt, it does nyot timeout. Nyote that this does pwopagate the asyncio.TimeoutError fow you in case of timeout and is pwovided fow ease of use.

I-In case the event wetuwns muwtipwe awguments, a tuple containying 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 the on_ pwefix, to wait fow. It’s wecommended to use Event.

  • 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 waising asyncio.TimeoutError.

Waises:

a-asyncio.TimeoutEwwow – If a timeout is pwovided and it was weached.

Wetuwns:

Wetuwns nyo awguments, a singwe awgument, ow a tuple of 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 fwom disnake.AutoShardedClient instead.