Abstract Base Classes¶
This section documents everything under disnake.abc.*.
Abstract Base Classes (commonly referred to as ABC) are classes that other classes can inherit to get or override specific behaviour. Read more about them here.
Classes¶
Snowflake¶
User¶
- class disnake.abc.User[source]¶
- An ABC that details the common operations on a Discord user. - The following classes implement this ABC: - This ABC must also implement - Snowflake.- discriminator¶
- The user’s discriminator. - Note - This is being phased out by Discord; the username system is moving away from - username#discriminatorto users having a globally unique username. The value of a single zero (- "0") indicates that the user has been migrated to the new system. See the help article for details.- Type:
 
 
PrivateChannel¶
GuildChannel¶
- asyncclone
- asynccreate_invite
- asyncdelete
- asyncinvites
- asyncmove
- defoverwrites_for
- defpermissions_for
- asyncset_permissions
- class disnake.abc.GuildChannel[source]¶
- An ABC that details the common operations on a Discord guild channel. - The following classes implement this ABC: - This ABC must also implement - abc.Snowflake.- position¶
- The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0. - Type:
 
 - property changed_roles[source]¶
- Returns a list of roles that have been overridden from their default values in the - Guild.rolesattribute.- Type:
- List[ - Role]
 
 - overwrites_for(obj)[source]¶
- Returns the channel-specific overwrites for a member or a role. 
 - property overwrites[source]¶
- Returns all of the channel’s overwrites. - This is returned as a dictionary where the key contains the target which can be either a - Roleor a- Memberand the value is the overwrite as a- PermissionOverwrite.- Returns:
- The channel’s permission overwrites. 
- Return type:
- Dict[Union[ - Role,- Member],- PermissionOverwrite]
 
 - property category[source]¶
- The category this channel belongs to. - If there is no category then this is - None.- Type:
- Optional[ - CategoryChannel]
 
 - property permissions_synced[source]¶
- Whether or not the permissions for this channel are synced with the category it belongs to. - If there is no category then this is - False.- New in version 1.3. - Type:
 
 - property jump_url[source]¶
- A URL that can be used to jump to this channel. - New in version 2.4. - Note - This exists for all guild channels but may not be usable by the client for all guild channel types. 
 - permissions_for(obj, /, *, ignore_timeout=...)[source]¶
- Handles permission resolution for the - Memberor- Role.- This function takes into consideration the following cases: - Guild owner 
- Guild roles 
- Channel overrides 
- Member overrides 
- Timeouts 
 - If a - Roleis passed, then it checks the permissions someone with that role would have, which is essentially:- The default role permissions 
- The permissions of the role used as a parameter 
- The default role permission overwrites 
- The permission overwrites of the role used as a parameter 
 - Note - If the channel originated from an - Interactionand the- guildattribute is unavailable, such as with user-installed applications in guilds, this method will not work due to an API limitation. Consider using- Interaction.permissionsor- app_permissionsinstead.- Changed in version 2.0: The object passed in can now be a role object. - Parameters:
- obj (Union[ - Member,- Role]) – The object to resolve permissions for. This could be either a member or a role. If it’s a role then member overwrites are not computed.
- ignore_timeout ( - bool) –- Whether or not to ignore the user’s timeout. Defaults to - False.- New in version 2.4. - Note - This only applies to - Memberobjects.- Changed in version 2.6: The default was changed to - False.
 
- Raises:
- TypeError – - ignore_timeoutis only supported for- Memberobjects.
- Returns:
- The resolved permissions for the member or role. 
- Return type:
 
 - await delete(*, reason=None)[source]¶
- This function is a coroutine. - Deletes the channel. - You must have - Permissions.manage_channelspermission to do this.- Parameters:
- reason (Optional[ - str]) – The reason for deleting this channel. Shows up on the audit log.
- Raises:
- Forbidden – You do not have proper permissions to delete the channel. 
- NotFound – The channel was not found or was already deleted. 
- HTTPException – Deleting the channel failed. 
 
 
 - await set_permissions(target, *, overwrite=..., reason=None, **permissions)[source]¶
- This function is a coroutine. - Sets the channel specific permission overwrites for a target in the channel. - The - targetparameter should either be a- Memberor a- Rolethat belongs to guild.- The - overwriteparameter, if given, must either be- Noneor- PermissionOverwrite. For convenience, you can pass in keyword arguments denoting- Permissionsattributes. If this is done, then you cannot mix the keyword arguments with the- overwriteparameter.- If the - overwriteparameter is- None, then the permission overwrites are deleted.- You must have - Permissions.manage_rolespermission to do this.- Note - This method replaces the old overwrites with the ones given. - Changed in version 2.6: Raises - TypeErrorinstead of- InvalidArgument.- Examples - Setting allow and deny: - await message.channel.set_permissions(message.author, view_channel=True, send_messages=False) - Deleting overwrites - 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) - Parameters:
- target (Union[ - Member,- Role]) – The member or role to overwrite permissions for.
- overwrite (Optional[ - PermissionOverwrite]) – The permissions to allow and deny to the target, or- Noneto delete the overwrite.
- **permissions – A keyword argument list of permissions to set for ease of use. Cannot be mixed with - overwrite.
- reason (Optional[ - str]) – The reason for doing this action. Shows up on the audit log.
 
- Raises:
- Forbidden – You do not have permissions to edit channel specific permissions. 
- HTTPException – Editing channel specific permissions failed. 
- NotFound – The role or member being edited is not part of the guild. 
- TypeError – - overwriteis invalid, the target type was not- Roleor- Member, both keyword arguments and- overwritewere provided, or invalid permissions were provided as keyword arguments.
 
 
 - await clone(*, name=None, reason=None)[source]¶
- This function is a coroutine. - Clones this channel. This creates a channel with the same properties as this channel. - You must have - Permissions.manage_channelspermission to do this.- New in version 1.1. - Parameters:
- Raises:
- Forbidden – You do not have the proper permissions to create this channel. 
- HTTPException – Creating the channel failed. 
 
- Returns:
- The channel that was created. 
- Return type:
 
 - await move(**kwargs)[source]¶
- This function is a coroutine. - A rich interface to help move a channel relative to other channels. - If exact position movement is required, - editshould be used instead.- You must have - Permissions.manage_channelspermission to do this.- Note - Voice channels will always be sorted below text channels. This is a Discord limitation. - New in version 1.7. - Changed in version 2.6: Raises - TypeErroror- ValueErrorinstead of- InvalidArgument.- Parameters:
- beginning ( - bool) – Whether to move the channel to the beginning of the channel list (or category if given). This is mutually exclusive with- end,- before, and- after.
- end ( - bool) – Whether to move the channel to the end of the channel list (or category if given). This is mutually exclusive with- beginning,- before, and- after.
- before ( - abc.Snowflake) – The channel that should be before our current channel. This is mutually exclusive with- beginning,- end, and- after.
- after ( - abc.Snowflake) – The channel that should be after our current channel. This is mutually exclusive with- beginning,- end, and- before.
- offset ( - int) – The number of channels to offset the move by. For example, an offset of- 2with- beginning=Truewould move it 2 after the beginning. A positive number moves it below while a negative number moves it above. Note that this number is relative and computed after the- beginning,- end,- before, and- afterparameters.
- category (Optional[ - abc.Snowflake]) – The category to move this channel under. If- Noneis given then it moves it out of the category. This parameter is ignored if moving a category channel.
- sync_permissions ( - bool) – Whether to sync the permissions with the category (if given).
- reason (Optional[ - str]) – The reason for moving this channel. Shows up on the audit log.
 
- Raises:
- Forbidden – You do not have permissions to move the channel. 
- HTTPException – Moving the channel failed. 
- TypeError – A bad mix of arguments were passed. 
- ValueError – An invalid 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 coroutine. - Creates an instant invite from a text or voice channel. - You must have - Permissions.create_instant_invitepermission to do this.- Parameters:
- max_age ( - int) – How long the invite should last in seconds. If set to- 0, then the invite doesn’t expire. Defaults to- 0.
- max_uses ( - int) – How many uses the invite could be used for. If it’s 0 then there are unlimited uses. Defaults to- 0.
- temporary ( - bool) – Whether the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults to- False.
- unique ( - bool) – Whether a unique invite URL should be created. Defaults to- True. If this is set to- Falsethen it will return a previously created invite.
- target_type (Optional[ - InviteTarget]) –- The type of target for the voice channel invite, if any. - New in version 2.0. 
- target_user (Optional[ - User]) –- The user whose stream to display for this invite, required if - target_typeis- InviteTarget.stream. The user must be streaming in the channel.- New in version 2.0. 
- target_application (Optional[ - Snowflake]) –- The ID of the embedded application for the invite, required if - target_typeis- InviteTarget.embedded_application.- New in version 2.0. - Changed in version 2.9: - PartyTypeis deprecated, and- Snowflakeshould be used instead.
- guild_scheduled_event (Optional[ - GuildScheduledEvent]) –- The guild scheduled event to include with the invite. - New in version 2.3. 
- reason (Optional[ - str]) – The reason for creating this invite. Shows up on the audit log.
 
- Raises:
- HTTPException – Invite creation failed. 
- NotFound – The channel that was passed is a category or an invalid channel. 
 
- Returns:
- The newly created invite. 
- Return type:
 
 - await invites()[source]¶
- This function is a coroutine. - Returns a list of all active instant invites from this channel. - You must have - Permissions.manage_channelspermission to use this.- Raises:
- Forbidden – You do not have proper permissions to get the information. 
- HTTPException – An error occurred while fetching the information. 
 
- Returns:
- The list of invites that are currently active. 
- Return type:
- List[ - Invite]
 
 
Messageable¶
- asyncfetch_message
- defhistory
- defpins
- asyncsend
- asynctrigger_typing
- deftyping
- class disnake.abc.Messageable[source]¶
- An ABC that details the common operations on a model that can send messages. - The following classes implement this ABC: - async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)[source]¶
- Returns an - AsyncIteratorthat enables receiving the destination’s message history.- You must have - Permissions.read_message_historypermission to use this.- Examples - Usage - counter = 0 async for message in channel.history(limit=200): if message.author == client.user: counter += 1 - Flattening into a list: - messages = await channel.history(limit=123).flatten() # messages is now a list of Message... - All parameters are optional. - Parameters:
- limit (Optional[ - int]) – The number of messages to retrieve. If- None, retrieves every message in the channel. Note, however, that this would make it a slow operation.
- before (Optional[Union[ - abc.Snowflake,- datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.
- after (Optional[Union[ - abc.Snowflake,- datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.
- around (Optional[Union[ - abc.Snowflake,- datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number then this will return at most limit + 1 messages.
- oldest_first (Optional[ - bool]) – If set to- True, return messages in oldest->newest order. Defaults to- Trueif- afteris specified, otherwise- False.
 
- Raises:
- Forbidden – You do not have permissions to get channel message history. 
- HTTPException – The request to get message history failed. 
 
- Yields:
- Message– The message with the message data parsed.
 
 - async with typing()[source]¶
- Returns a context manager that allows you to type for an indefinite period of time. - This is useful for denoting long computations in your bot. - Note - This is both a regular context manager and an async context manager. This means that both - withand- async withwork with this.- Example 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 coroutine. - Sends a message to the destination with the content given. - The content must be a type that can convert to a string through - str(content).- At least one of - content,- embed/- embeds,- file/- files,- stickers,- components,- pollor- viewmust be provided.- To upload a single file, the - fileparameter should be used with a single- Fileobject. To upload multiple files, the- filesparameter should be used with a- listof- Fileobjects. Specifying both parameters will lead to an exception.- To upload a single embed, the - embedparameter should be used with a single- Embedobject. To upload multiple embeds, the- embedsparameter should be used with a- listof- Embedobjects. Specifying both parameters will lead to an exception.- Changed in version 2.6: Raises - TypeErroror- ValueErrorinstead of- InvalidArgument.- Parameters:
- content (Optional[ - str]) – The content of the message to send.
- tts ( - bool) – Whether the message should be sent using text-to-speech.
- embed ( - Embed) – The rich embed for the content to send. This cannot be mixed with the- embedsparameter.
- embeds (List[ - Embed]) –- A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with the - embedparameter.- New in version 2.0. 
- file ( - File) – The file to upload. This cannot be mixed with the- filesparameter.
- files (List[ - File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with the- fileparameter.
- stickers (Sequence[Union[ - GuildSticker,- StandardSticker,- StickerItem]]) –- A list of stickers to upload. Must be a maximum of 3. - New in version 2.0. 
- nonce (Union[ - str,- int]) – The nonce to use for sending this message. If the message was successfully sent, then the message will have a nonce with this value.
- delete_after ( - float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
- allowed_mentions ( - AllowedMentions) –- Controls the mentions being processed in this message. If this is passed, then the object is merged with - Client.allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in- Client.allowed_mentions. If no object is passed at all then the defaults given by- Client.allowed_mentionsare used instead.- New in version 1.4. 
- reference (Union[ - Message,- MessageReference,- PartialMessage]) –- A reference to the - Messageto which you are replying, this can be created using- Message.to_reference()or passed directly as a- Message. You can control whether this mentions the author of the referenced message using the- AllowedMentions.replied_userattribute of- allowed_mentionsor by setting- mention_author.- New in version 1.6. - Note - Passing a - Messageor- PartialMessagewill only allow replies. To forward a message you must explicitly transform the message to a- MessageReferenceusing- Message.to_reference()and specify the- MessageReferenceType, or use- Message.forward().
- mention_author (Optional[ - bool]) –- If set, overrides the - AllowedMentions.replied_userattribute of- allowed_mentions.- New in version 1.6. 
- view ( - ui.View) –- A Discord UI View to add to the message. This cannot be mixed with - components.- New in version 2.0. 
- components (Union[ - UIComponent, List[Union[- UIComponent, List[- WrappedComponent]]]]) –- A list of components to include in the message. This cannot be mixed with - view.- New in version 2.4. - Note - Passing v2 components here automatically sets the - is_components_v2flag. Setting this flag cannot be reverted. Note that this also disables the- content,- embeds,- stickers, and- pollfields.
- suppress_embeds ( - bool) –- Whether to suppress embeds for the message. This hides all the embeds from the UI if set to - True.- New in version 2.5. 
- flags ( - MessageFlags) –- The flags to set for this message. Only - suppress_embeds,- suppress_notifications, and- is_components_v2are supported.- If parameter - suppress_embedsis provided, that will override the setting of- MessageFlags.suppress_embeds.- New in version 2.9. 
- poll ( - Poll) –- The poll to send with the message. - New in version 2.10. 
 
- Raises:
- HTTPException – Sending the message failed. 
- Forbidden – You do not have the proper permissions to send the message. 
- TypeError – Specified both - fileand- files, or you specified both- embedand- embeds, or you specified both- viewand- components, or the- referenceobject is not a- Message,- MessageReferenceor- PartialMessage.
- ValueError – The - filesor- embedslist is too large, or you tried to send v2 components together with- content,- embeds,- stickers, or- poll.
 
- Returns:
- The message that was sent. 
- Return type:
 
 - await trigger_typing()[source]¶
- This function is a coroutine. - Triggers a typing indicator to the destination. - Typing indicator will go away after 10 seconds, or after a message is sent. 
 - await fetch_message(id, /)[source]¶
- This function is a coroutine. - Retrieves a single - Messagefrom the destination.- Parameters:
- id ( - int) – The message ID to look for.
- Raises:
- NotFound – The specified message was not found. 
- Forbidden – You do not have the permissions required to get a message. 
- HTTPException – Retrieving the message failed. 
 
- Returns:
- The message asked for. 
- Return type:
 
 - pins(*, limit=50, before=None)[source]¶
- Returns an - AsyncIteratorthat enables receiving the destination’s pinned messages.- You must have the - Permissions.read_message_historyand- Permissions.view_channelpermissions to use this.- Note - Due to a limitation with the Discord API, the - Messageobjects returned by this method do not contain complete- Message.reactionsdata.- Changed in version 2.11: Now returns an - AsyncIteratorto support changes in Discord’s API.- awaiting the result of this method remains supported, but only returns the last 50 pins and is deprecated in favor of- async for msg in channel.pins().- Examples - Usage - counter = 0 async for message in channel.pins(limit=100): if message.author == client.user: counter += 1 - Flattening to a list - pinned_messages = await channel.pins(limit=100).flatten() # pinned_messages is now a list of Message... - All parameters are optional. - Parameters:
- limit (Optional[ - int]) – The number of pinned messages to retrieve. If- None, retrieves every pinned message in the channel. Note, however, that this would make it a slow operation.
- before (Optional[Union[ - abc.Snowflake,- datetime.datetime]]) – Retrieve messages pinned before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.
 
- Raises:
- HTTPException – Retrieving the pinned messages failed. 
- Yields:
- Message– The pinned message from the parsed message data.
 
 
Connectable¶
- class disnake.abc.Connectable[source]¶
- An ABC that details the common operations on a channel that can connect to a voice server. - The following classes implement this ABC: - Note - This ABC is not decorated with - typing.runtime_checkable(), so will fail- isinstance()/- issubclass()checks.