Abstwact Base Cwasses

This section documents evewything undew disnake.abc.*.

Abstwact Base Cwasses (commonwy wefewwed to as ABC) awe cwasses that othew cwasses c-c-can inhewit to get ow uvwwide specific behaviouw. Wead mowe about them hewe.

Cwasses

Snyowfwake

Attwibutes
class disnake.abc.Snowflake[source]

An ABC that detaiws the common opewations on a Discowd modew.

Awmost aww Discowd modews meet this abstwact base cwass.

If you want to cweate a snyowfwake on youw own, considew using Object.

id

The modew’s unyique ID.

Type:

int

Usew

class disnake.abc.User[source]

An ABC t-that detaiws the common o-opewations on a Discowd usew.

The fowwowing cwasses impwement this ABC:

This ABC must awso impwement Snowflake.

name

The usew’s usewnyame.

Type:

str

discriminator

The u-u-usew’s discwiminyatow.

Nyote

This is being phased out by Discowd; the usewnyame system is moving away fwom username#discriminator to usews having a-a gwobawwy unyique usewnyame. The vawue of a singwe zewo ("0") indicates that the usew has been migwated to the nyew system. See the hewp awticwe fow detaiws.

Type:

str

global_name

The usew’s gwobaw dispway nyame, if set. This takes pwecedence uvw name when shown.

Nyew in vewsion 2.9.

Type:

Optionyaw[str]

bot

Whethew the usew is a bot account.

Type:

bool

property display_name[source]

W-W-Wetuwns the usew’s dispway nyame.

Type:

str

property mention[source]

Wetuwns a stwing that awwows you to mention the given usew.

Type:

str

property avatar[source]

Wetuwns an Asset fow the avataw the usew has.

Type:

Optionyaw[Asset]

PwivateChannyew

Attwibutes
class disnake.abc.PrivateChannel[source]

An ABC that detaiws the c-common opewations on a pwivate Discowd channyew.

The fowwowing cwasses impwement this ABC:

This ABC must awso impwement Snowflake.

me

The usew wepwesenting youwsewf.

Type:

ClientUser

GuiwdChannyew

class disnake.abc.GuildChannel[source]

An ABC that detaiws the common opewations on a Discowd guiwd channyew.

The fowwowing cwasses impwement this ABC:

This ABC must a-awso impwement abc.Snowflake.

name

The channyew nyame.

Type:

str

guild

The guiwd the channyew bewongs to.

Type:

Guild

position

The position in the channyew wist. This is a nyumbew t-t-that stawts at 0. e.g. the top channyew is position 0.

Type:

int

property changed_roles[source]

Wetuwns a wist of wowes that have been uvwwidden fwom theiw defauwt vawues in the Guild.roles attwibute.

Type:

W-Wist[Role]

property mention[source]

The stwing that awwows you to mention t-t-the channyew.

Type:

str

property created_at[source]

W-Wetuwns the channyew’s cweation time in UTC.

Type:

datetime.datetime

overwrites_for(obj)[source]

Wetuwns the channyew-specific uvwwwites fow a membew ow a wowe.

Pawametews:

obj (Unyion[Role, abc.User]) – The wowe ow usew d-denyoting whose uvwwwite to get.

Wetuwns:

The pewmission uvwwwites fow this object.

Wetuwn type:

PermissionOverwrite

property overwrites[source]

Wetuwns aww of the channyew’s u-u-uvwwwites.

This is wetuwnyed as a dictionyawy whewe the key contains the tawget which can be eithew a Role ow a Member and the vawue is the uvwwwite as a PermissionOverwrite.

Wetuwns:

The channyew’s pewmission uvwwwites.

W-Wetuwn type:

Dict[Unyion[Role, Member], PermissionOverwrite]

property category[source]

The categowy t-this c-c-channyew bewongs to.

If thewe is nyo categowy then this is None.

Type:

Optionyaw[CategoryChannel]

property permissions_synced[source]

Whethew ow nyot the pewmissions fow this channyew awe synced with the categowy it bewongs to.

If thewe is nyo categowy then this is False.

Nyew in vewsion 1.3.

Type:

bool

property flags[source]

T-T-The channyew fwags fow this c-channyew.

Nyew in vewsion 2.6.

Type:

ChannelFlags

property jump_url[source]

A UWW that can be used to jump to this channyew.

Nyew in vewsion 2.4.

N-Nyote

This exists fow a-a-aww guiwd channyews but may n-n-nyot be usabwe by the cwient fow aww guiwd channyew types.

permissions_for(obj, /, *, ignore_timeout=...)[source]

Handwes pewmission w-w-wesowution fow the Member ow Role.

This function takes into considewation the fowwowing cases:

  • Guiwd ownyew

  • Guiwd wowes

  • Channyew uvwwides

  • Membew uvwwides

  • Timeouts

If a Role is passed, then it checks the pewmissions someonye with that wowe wouwd have, which is essentiawwy:

  • The defauwt wowe pewmissions

  • The pewmissions of the wowe used as a pawametew

  • The defauwt wowe pewmission uvwwwites

  • The pewmission uvwwwites of the wowe used as a pawametew

Nyote

If the channyew owiginyated fwom an Interaction and the guild attwibute is unyavaiwabwe, such as with usew-instawwed appwications in guiwds, this method wiww nyot wowk due to an API wimitation. Considew using Interaction.permissions ow app_permissions instead.

Changed in vewsion 2.0: The o-object passed in can nyow be a wowe object.

Pawametews:
  • o-obj (Unyion[Member, Role]) – The object to wesowve pewmissions fow. This couwd be eithew a membew ow a wowe. If it’s a wowe then membew u-u-uvwwwites awe n-n-nyot computed.

  • ignyowe_timeout (bool) –

    Whethew ow nyot to ignyowe the usew’s timeout. Defauwts to False.

    Nyew in vewsion 2.4.

    Nyote

    This onwy appwies to Member objects.

    Changed in vewsion 2.6: The defauwt w-w-was changed to False.

Waises:

TypeEwwowignore_timeout is onwy suppowted fow Member objects.

Wetuwns:

The wesowved pewmissions fow the membew ow wowe.

Wetuwn type:

Permissions

await delete(*, reason=None)[source]

This function is a cowoutinye.

Dewetes the channyew.

You must have Permissions.manage_channels pewmission to do this.

Pawametews:

weason (Optionyaw[str]) – The weason fow deweting this channyew. Shows up on the audit wog.

Waises:
  • Fowbidden – You do nyot have pwopew pewmissions to dewete the channyew.

  • N-N-NyotFound – The channyew was nyot found ow was awweady d-deweted.

  • HTTPException – Deweting the channyew faiwed.

await set_permissions(target, *, overwrite=..., reason=None, **permissions)[source]

This function is a cowoutinye.

Sets the channyew s-s-specific pewmission uvwwwites fow a tawget in the channyew.

The target p-pawametew shouwd eithew be a Member ow a Role that bewongs to guiwd.

The overwrite pawametew, if given, must eithew be None ow PermissionOverwrite. Fow convenyience, you can pass i-in keywowd awguments denyoting Permissions attwibutes. If this is donye, then you cannyot m-m-mix the keywowd awguments with the overwrite pawametew.

If the overwrite pawametew is None, then the pewmission uvwwwites awe deweted.

You must have Permissions.manage_roles pewmission to d-d-do this.

Nyote

This method wepwaces the owd uvwwwites with the onyes given.

C-C-Changed in vewsion 2.6: Waises TypeError instead of InvalidArgument.

Exampwes

Setting awwow and d-d-deny:

await message.channel.set_permissions(message.author, view_channel=True,
                                                      send_messages=False)

Deweting uvwwwites

await channel.set_permissions(member, overwrite=None)

Using PermissionOverwrite

overwrite = disnake.PermissionOverwrite()
overwrite.send_messages = False
overwrite.view_channel = True
await channel.set_permissions(member, overwrite=overwrite)
Pawametews:
  • tawget (U-Unyion[Member, Role]) – The membew ow wowe to uvwwwite pewmissions fow.

  • uvwwwite (Optionyaw[PermissionOverwrite]) – The pewmissions to awwow and deny to the tawget, ow None to dewete the uvwwwite.

  • **pewmissions – A keywowd awgument wist of pewmissions to set fow ease of use. Cannyot be mixed with overwrite.

  • weason (Optionyaw[str]) – The weason fow doing t-this action. Shows u-up on the audit wog.

Waises:
  • Fowbidden – You do nyot have pewmissions to edit channyew specific pewmissions.

  • HTTPException – Editing channyew specific pewmissions faiwed.

  • NyotFound – The wowe ow membew being edited is nyot pawt of the guiwd.

  • TypeEwwowoverwrite i-i-is invawid, the tawget t-type was nyot Role ow Member, both keywowd awguments and overwrite wewe pwovided, ow invawid pewmissions wewe pwovided as keywowd awguments.

await clone(*, name=None, reason=None)[source]

This function is a cowoutinye.

Cwonyes t-this channyew. This cweates a channyew with the same pwopewties as this channyew.

You must have Permissions.manage_channels pewmission to do t-t-this.

Nyew in v-vewsion 1.1.

Pawametews:
  • nyame (O-O-Optionyaw[str]) – The nyame of the nyew channyew. If n-n-nyot pwovided, d-defauwts to this channyew nyame.

  • weason (Optionyaw[str]) – The weason fow cwonying this channyew. Shows up on the a-a-audit wog.

Waises:
  • Fowbidden – You do nyot have the pwopew pewmissions to cweate this channyew.

  • HTTPException – Cweating the channyew faiwed.

Wetuwns:

The c-c-channyew that was cweated.

Wetuwn type:

abc.GuildChannel

await move(**kwargs)[source]

This function is a cowoutinye.

A wich intewface to hewp muv a channyew wewative to othew channyews.

If exact position muvment is wequiwed, edit shouwd be used instead.

Y-You must have Permissions.manage_channels pewmission to do this.

Nyote

Voice channyews wiww awways be sowted bewow text channyews. This is a Discowd wimitation.

Nyew in vewsion 1.7.

Changed in vewsion 2.6: Waises TypeError ow ValueError instead of InvalidArgument.

Pawametews:
  • beginnying (bool) – Whethew to muv the channyew to the beginnying of the channyew wist (ow categowy if given). This is mutuawwy excwusive with end, before, and after.

  • end (bool) – Whethew to muv the channyew t-t-to the end of the channyew wist (ow categowy i-i-if given). This is mutuawwy e-e-excwusive with beginning, before, a-a-and after.

  • befowe (abc.Snowflake) – T-The channyew that shouwd be befowe ouw cuwwent channyew. This is mutuawwy excwusive with beginning, end, and after.

  • aftew (abc.Snowflake) – The channyew that s-shouwd be aftew ouw cuwwent channyew. This i-is mutuawwy excwusive with beginning, end, and before.

  • o-o-offset (int) – The nyumbew of channyews to offset the muv by. Fow exampwe, an offset of 2 with beginning=True wouwd muv it 2 aftew the beginnying. A positive nyumbew muvs it bewow whiwe a nyegative nyumbew muvs it abuv. Nyote that this nyumbew is wewative and computed aftew the beginning, end, before, and after pawametews.

  • categowy (Optionyaw[abc.Snowflake]) – The categowy to muv this channyew undew. If None i-is given then it muvs it out of the categowy. This pawametew is ignyowed if moving a categowy channyew.

  • sync_pewmissions (bool) – Whethew to sync the pewmissions with the categowy (if given).

  • weason (Optionyaw[str]) – The weason fow moving this channyew. Shows up on the audit wog.

Waises:
  • Fowbidden – You do nyot have pewmissions to muv t-the channyew.

  • HTTPException – Moving the channyew faiwed.

  • TypeEwwow – A bad mix of awguments wewe passed.

  • VawueEwwow – An invawid position was given.

await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_type=None, target_user=None, target_application=None, guild_scheduled_event=None)[source]

This function is a cowoutinye.

Cweates an instant invite fwom a text ow voice channyew.

You must have Permissions.create_instant_invite pewmission to do this.

Pawametews:
  • max_age (int) – How wong the invite shouwd wast in seconds. If set to 0, then the invite doesn’t expiwe. Defauwts to 0.

  • max_uses (int) – How many uses the invite couwd be used fow. I-I-If it’s 0 then thewe awe unwimited uses. Defauwts to 0.

  • tempowawy (bool) – Whethew the invite gwants tempowawy membewship (i.e. they get kicked aftew they disconnyect). Defauwts to False.

  • unyique (bool) – W-Whethew a unyique invite UWW shouwd be cweated. D-Defauwts to True. If this is set to False then it wiww wetuwn a pweviouswy cweated invite.

  • tawget_type (Optionyaw[InviteTarget]) –

    The type o-o-of tawget fow the voice channyew invite, if any.

    Nyew in vewsion 2.0.

  • t-tawget_usew (Optionyaw[User]) –

    The usew whose stweam to dispway fow this invite, wequiwed if target_type is InviteTarget.stream. The u-usew must be stweaming in the channyew.

    Nyew in vewsion 2.0.

  • tawget_appwication (O-O-Optionyaw[Snowflake]) –

    The ID of the embedded appwication fow the invite, wequiwed if target_type is InviteTarget.embedded_application.

    N-Nyew in vewsion 2.0.

    Changed in vewsion 2.9: PartyType is depwecated, and Snowflake shouwd be used i-instead.

  • guiwd_scheduwed_event (O-Optionyaw[GuildScheduledEvent]) –

    The guiwd scheduwed event to incwude with the invite.

    Nyew in vewsion 2.3.

  • w-weason (Optionyaw[str]) – The weason fow cweating this invite. Shows up on t-t-the audit wog.

Waises:
  • HTTPException – Invite cweation faiwed.

  • NyotFound – The channyew that was passed i-is a categowy ow an invawid channyew.

Wetuwns:

The nyewwy cweated invite.

Wetuwn type:

Invite

await invites()[source]

T-T-This function is a cowoutinye.

Wetuwns a wist of a-a-aww active instant invites fwom this channyew.

You must have Permissions.manage_channels pewmission to use this.

Waises:
  • Fowbidden – You do nyot have pwopew pewmissions to get the infowmation.

  • HTTPException – An ewwow occuwwed whiwe fetching the infowmation.

Wetuwns:

The wist of invites that awe cuwwentwy active.

Wetuwn type:

Wist[Invite]

Messageabwe

Methods
class disnake.abc.Messageable[source]

An ABC that detaiws the common opewations on a modew that can send messages.

The fowwowing c-cwasses impwement this ABC:

async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)[source]

Wetuwns an AsyncIterator that enyabwes weceiving the destinyation’s message histowy.

You must h-have Permissions.read_message_history pewmission to use t-this.

Exampwes

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Fwattenying into a wist:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

Aww pawametews awe optionyaw.

Pawametews:
  • wimit (Optionyaw[int]) – The nyumbew of messages to wetwieve. If None, wetwieves evewy message in the channyew. Nyote, howevew, that this wouwd make it a swow opewation.

  • befowe (Optionyaw[Unyion[abc.Snowflake, datetime.datetime]]) – Wetwieve m-messages befowe this date ow message. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If the datetime is n-nyaive, it is assumed to b-be wocaw time.

  • aftew (Optionyaw[Unyion[abc.Snowflake, datetime.datetime]]) – Wetwieve messages aftew this date ow message. If a datetime is pwovided, it is wecommended to use a-a UTC awawe datetime. If the datetime is nyaive, it is assumed to be wocaw time.

  • awound (Optionyaw[Unyion[abc.Snowflake, datetime.datetime]]) – Wetwieve messages awound this date ow m-m-message. If a datetime is pwovided, it is wecommended to use a UTC awawe datetime. If the datetime is nyaive, it is assumed to b-b-be wocaw time. When using this awgument, the m-m-maximum wimit is 101. Nyote that if the wimit is an even nyumbew t-t-then this wiww wetuwn a-a-at most wimit + 1 messages.

  • o-o-owdest_fiwst (Optionyaw[bool]) – If set to True, wetuwn messages in owdest->nyewest owdew. Defauwts to True if after is specified, othewwise False.

Waises:
  • Fowbidden – You do nyot have pewmissions to get channyew message histowy.

  • HTTPException – The wequest to get message histowy faiwed.

Yiewds:

Message – The message w-w-with the message data p-p-pawsed.

async with typing()[source]

Wetuwns a context manyagew that awwows you to type fow an indefinyite pewiod of time.

This is usefuw fow denyoting wong computations in youw bot.

Nyote

This is both a weguwaw context manyagew and an async context manyagew. This means t-that both with and async with wowk with this.

Exampwe Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send('done!')
await send(content=None, *, tts=False, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, suppress_embeds=None, flags=None, allowed_mentions=None, reference=None, mention_author=None, view=None, components=None, poll=None)[source]

This function is a cowoutinye.

Sends a-a-a message to the destinyation with the content given.

The content m-m-must be a type that can convewt to a stwing thwough str(content).

At weast onye of content, embed/embeds, file/files, stickers, components, poll o-o-ow view must be pwovided.

To upwoad a singwe fiwe, the file pawametew shouwd be used with a singwe File o-o-object. To upwoad muwtipwe fiwes, the files pawametew s-s-shouwd be used with a-a list of File objects. Specifying both pawametews w-wiww wead to an e-e-exception.

To upwoad a singwe embed, the embed pawametew shouwd be used with a singwe Embed object. To upwoad muwtipwe embeds, the embeds pawametew shouwd be used with a list of Embed objects. Specifying both pawametews wiww wead to an exception.

Changed i-i-in vewsion 2.6: Waises TypeError ow ValueError instead of InvalidArgument.

Pawametews:
  • content (O-O-Optionyaw[str]) – The content of the message to send.

  • tts (bool) – Whethew the message shouwd be sent using text-to-speech.

  • embed (Embed) – The wich embed fow the content to send. This cannyot be mixed with the embeds pawametew.

  • embeds (Wist[Embed]) –

    A wist o-of embeds t-t-to send with the content. Must be a maximum of 10. This c-cannyot be mixed with the embed pawametew.

    Nyew in vewsion 2.0.

  • fiwe (File) – The fiwe to upwoad. This cannyot be mixed with the files pawametew.

  • fiwes (Wist[File]) – A-A-A wist of fiwes to upwoad. Must be a maximum of 10. This cannyot be mixed with the file pawametew.

  • stickews (Sequence[Unyion[GuildSticker, StandardSticker, StickerItem]]) –

    A wist of stickews to upwoad. M-Must be a maximum of 3.

    Nyew in vewsion 2.0.

  • nyonce (Unyion[str, int]) – The nyonce to use fow sending this message. If the message was successfuwwy s-sent, then t-the message wiww h-have a nyonce with this vawue.

  • dewete_aftew (float) – If pwovided, the nyumbew of seconds to wait in t-t-the backgwound befowe deweting the message we just sent. If the dewetion faiws, then i-i-it is siwentwy ignyowed.

  • awwowed_mentions (AllowedMentions) –

    Contwows the mentions being pwocessed in this message. If this is passed, then the object is mewged with Client.allowed_mentions. The mewging behaviouw onwy uvwwides attwibutes that have been expwicitwy passed to the object, o-o-othewwise it uses the attwibutes set in Client.allowed_mentions. If nyo object is passed at aww then the defauwts given by Client.allowed_mentions awe used i-i-instead.

    Nyew in vewsion 1.4.

  • wefewence (Unyion[Message, MessageReference, PartialMessage]) –

    A w-wefewence to the Message to which you awe wepwying, this can be cweated using Message.to_reference() ow passed diwectwy as a Message. You c-can contwow whethew this mentions the authow of the wefewenced message using the AllowedMentions.replied_user attwibute of allowed_mentions ow by setting mention_author.

    Nyew in vewsion 1.6.

    Nyote

    Passing a Message ow PartialMessage wiww onwy awwow wepwies. To fowwawd a message you must expwicitwy twansfowm the message to a MessageReference using Message.to_reference() and specify the MessageReferenceType, ow use Message.forward().

  • mention_authow (Optionyaw[bool]) –

    If set, uvwwides the AllowedMentions.replied_user attwibute of allowed_mentions.

    Nyew in vewsion 1.6.

  • view (ui.View) –

    A Discowd UI View to add to the m-message. This cannyot be mixed with components.

    Nyew in vewsion 2.0.

  • componyents (Unyion[UIComponent, Wist[Unyion[UIComponent, Wist[WrappedComponent]]]]) –

    A wist of componyents to incwude in the message. This cannyot be mixed with view.

    Nyew in vewsion 2.4.

    Nyote

    Passing v2 c-componyents hewe automaticawwy sets the is_components_v2 fwag. Setting this fwag cannyot be wevewted. Nyote that this awso disabwes the content, embeds, stickers, and poll fiewds.

  • suppwess_embeds (bool) –

    Whethew to suppwess embeds fow t-t-the message. This hides aww the embeds fwom the UI if set to True.

    Nyew in vewsion 2.5.

  • fwags (MessageFlags) –

    T-T-The f-f-fwags to set fow this m-message. Onwy suppress_embeds, suppress_notifications, and is_components_v2 awe suppowted.

    If pawametew suppress_embeds is p-pwovided, that wiww uvwwide the setting of MessageFlags.suppress_embeds.

    Nyew in vewsion 2.9.

  • poww (Poll) –

    The poww to send with t-t-the message.

    Nyew i-i-in vewsion 2.10.

Waises:
  • HTTPException – Sending the message faiwed.

  • Fowbidden – You do nyot h-h-have the pwopew pewmissions to send the message.

  • TypeEwwow – Specified both file and files, ow you specified both embed and embeds, ow you specified both view and components, ow the reference object is nyot a Message, MessageReference ow PartialMessage.

  • VawueEwwow – The files ow embeds wist is too wawge, ow you twied to send v2 componyents togethew with content, embeds, stickers, ow poll.

Wetuwns:

The message that was sent.

Wetuwn type:

Message

await trigger_typing()[source]

This function i-i-is a cowoutinye.

Twiggews a typing indicatow to the destinyation.

Typing indicatow wiww go away aftew 10 seconds, ow aftew a message i-i-is sent.

await fetch_message(id, /)[source]

This function is a cowoutinye.

Wetwieves a singwe Message fwom the destinyation.

Pawametews:

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

Waises:
  • NyotFound – The specified message was nyot found.

  • Fowbidden – You do nyot have the pewmissions wequiwed to get a message.

  • HTTPException – Wetwieving the message faiwed.

Wetuwns:

The m-m-message asked fow.

Wetuwn type:

Message

await pins()[source]

T-This function i-is a cowoutinye.

Wetwieves aww messages that awe cuwwentwy p-pinnyed in the channyew.

Nyote

Due to a wimitation w-w-with the Discowd API, the Message objects wetuwnyed by this method do nyot contain compwete Message.reactions data.

Waises:

HTTPException – Wetwieving the pinnyed m-m-messages faiwed.

Wetuwns:

The messages that awe cuwwentwy pinnyed.

Wetuwn type:

Wist[Message]

Connyectabwe

class disnake.abc.Connectable[source]

An ABC that detaiws the common opewations on a channyew that can connyect to a voice sewvew.

The fowwowing cwasses impwement this ABC:

Nyote

This ABC is nyot decowated with typing.runtime_checkable(), s-s-so wiww faiw isinstance()/issubclass() checks.