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¶
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.- discriminator¶
The u-u-usew’s discwiminyatow.
Nyote
This is being phased out by Discowd; the usewnyame system is moving away fwom
username#discriminatorto 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:
PwivateChannyew¶
GuiwdChannyew¶
- asynccwonye
- asynccweate_invite
- asyncdewete
- asyncinvites
- asyncmuv
- defuvwwwites_fow
- defpewmissions_fow
- asyncset_pewmissions
- 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.- 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:
- property changed_roles[source]¶
Wetuwns a wist of wowes that have been uvwwidden fwom theiw defauwt vawues in the
Guild.rolesattwibute.- Type:
W-Wist[
Role]
- overwrites_for(obj)[source]¶
Wetuwns the channyew-specific uvwwwites fow a membew ow a wowe.
- 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
Roleow aMemberand the vawue is the uvwwwite as aPermissionOverwrite.- 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:
- 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
MemberowRole.This function takes into considewation the fowwowing cases:
Guiwd ownyew
Guiwd wowes
Channyew uvwwides
Membew uvwwides
Timeouts
If a
Roleis 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
Interactionand theguildattwibute is unyavaiwabwe, such as with usew-instawwed appwications in guiwds, this method wiww nyot wowk due to an API wimitation. Considew usingInteraction.permissionsowapp_permissionsinstead.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
Memberobjects.Changed in vewsion 2.6: The defauwt w-w-was changed to
False.
- Waises:
TypeEwwow –
ignore_timeoutis onwy suppowted fowMemberobjects.- Wetuwns:
The wesowved pewmissions fow the membew ow wowe.
- Wetuwn type:
- await delete(*, reason=None)[source]¶
This function is a cowoutinye.
Dewetes the channyew.
You must have
Permissions.manage_channelspewmission 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
targetp-pawametew shouwd eithew be aMemberow aRolethat bewongs to guiwd.The
overwritepawametew, if given, must eithew beNoneowPermissionOverwrite. Fow convenyience, you can pass i-in keywowd awguments denyotingPermissionsattwibutes. If this is donye, then you cannyot m-m-mix the keywowd awguments with theoverwritepawametew.If the
overwritepawametew isNone, then the pewmission uvwwwites awe deweted.You must have
Permissions.manage_rolespewmission to d-d-do this.Nyote
This method wepwaces the owd uvwwwites with the onyes given.
C-C-Changed in vewsion 2.6: Waises
TypeErrorinstead ofInvalidArgument.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
PermissionOverwriteoverwrite = 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, owNoneto 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.
TypeEwwow –
overwritei-i-is invawid, the tawget t-type was nyotRoleowMember, both keywowd awguments andoverwritewewe 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_channelspewmission to do t-t-this.Nyew in v-vewsion 1.1.
- Pawametews:
- 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:
- 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,
editshouwd be used instead.Y-You must have
Permissions.manage_channelspewmission 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
TypeErrorowValueErrorinstead ofInvalidArgument.- Pawametews:
beginnying (
bool) – Whethew to muv the channyew to the beginnying of the channyew wist (ow categowy if given). This is mutuawwy excwusive withend,before, andafter.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 withbeginning,before, a-a-andafter.befowe (
abc.Snowflake) – T-The channyew that shouwd be befowe ouw cuwwent channyew. This is mutuawwy excwusive withbeginning,end, andafter.aftew (
abc.Snowflake) – The channyew that s-shouwd be aftew ouw cuwwent channyew. This i-is mutuawwy excwusive withbeginning,end, andbefore.o-o-offset (
int) – The nyumbew of channyews to offset the muv by. Fow exampwe, an offset of2withbeginning=Truewouwd 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 thebeginning,end,before, andafterpawametews.categowy (Optionyaw[
abc.Snowflake]) – The categowy to muv this channyew undew. IfNonei-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_invitepewmission to do this.- Pawametews:
max_age (
int) – How wong the invite shouwd wast in seconds. If set to0, then the invite doesn’t expiwe. Defauwts to0.max_uses (
int) – How many uses the invite couwd be used fow. I-I-If it’s 0 then thewe awe unwimited uses. Defauwts to0.tempowawy (
bool) – Whethew the invite gwants tempowawy membewship (i.e. they get kicked aftew they disconnyect). Defauwts toFalse.unyique (
bool) – W-Whethew a unyique invite UWW shouwd be cweated. D-Defauwts toTrue. If this is set toFalsethen 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_typeisInviteTarget.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_typeisInviteTarget.embedded_application.N-Nyew in vewsion 2.0.
Changed in vewsion 2.9:
PartyTypeis depwecated, andSnowflakeshouwd 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:
- 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_channelspewmission 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¶
- asyncfetch_message
- defhistowy
- asyncpins
- asyncsend
- asynctwiggew_typing
- deftyping
- 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
AsyncIteratorthat enyabwes weceiving the destinyation’s message histowy.You must h-have
Permissions.read_message_historypewmission 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. IfNone, 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 toTrue, wetuwn messages in owdest->nyewest owdew. Defauwts toTrueifafteris specified, othewwiseFalse.
- 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
withandasync withwowk 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,pollo-o-owviewmust be pwovided.To upwoad a singwe fiwe, the
filepawametew shouwd be used with a singweFileo-o-object. To upwoad muwtipwe fiwes, thefilespawametew s-s-shouwd be used with a-alistofFileobjects. Specifying both pawametews w-wiww wead to an e-e-exception.To upwoad a singwe embed, the
embedpawametew shouwd be used with a singweEmbedobject. To upwoad muwtipwe embeds, theembedspawametew shouwd be used with alistofEmbedobjects. Specifying both pawametews wiww wead to an exception.Changed i-i-in vewsion 2.6: Waises
TypeErrorowValueErrorinstead ofInvalidArgument.- 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 theembedspawametew.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
embedpawametew.Nyew in vewsion 2.0.
fiwe (
File) – The fiwe to upwoad. This cannyot be mixed with thefilespawametew.fiwes (Wist[
File]) – A-A-A wist of fiwes to upwoad. Must be a maximum of 10. This cannyot be mixed with thefilepawametew.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 inClient.allowed_mentions. If nyo object is passed at aww then the defauwts given byClient.allowed_mentionsawe used i-i-instead.Nyew in vewsion 1.4.
wefewence (Unyion[
Message,MessageReference,PartialMessage]) –A w-wefewence to the
Messageto which you awe wepwying, this can be cweated usingMessage.to_reference()ow passed diwectwy as aMessage. You c-can contwow whethew this mentions the authow of the wefewenced message using theAllowedMentions.replied_userattwibute ofallowed_mentionsow by settingmention_author.Nyew in vewsion 1.6.
Nyote
Passing a
MessageowPartialMessagewiww onwy awwow wepwies. To fowwawd a message you must expwicitwy twansfowm the message to aMessageReferenceusingMessage.to_reference()and specify theMessageReferenceType, ow useMessage.forward().mention_authow (Optionyaw[
bool]) –If set, uvwwides the
AllowedMentions.replied_userattwibute ofallowed_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_v2fwag. Setting this fwag cannyot be wevewted. Nyote that this awso disabwes thecontent,embeds,stickers, andpollfiewds.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, andis_components_v2awe suppowted.If pawametew
suppress_embedsis p-pwovided, that wiww uvwwide the setting ofMessageFlags.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
fileandfiles, ow you specified bothembedandembeds, ow you specified bothviewandcomponents, ow thereferenceobject is nyot aMessage,MessageReferenceowPartialMessage.VawueEwwow – The
filesowembedswist is too wawge, ow you twied to send v2 componyents togethew withcontent,embeds,stickers, owpoll.
- Wetuwns:
The message that was sent.
- Wetuwn type:
- 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
Messagefwom 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:
- 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
Messageobjects wetuwnyed by this method do nyot contain compweteMessage.reactionsdata.- 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 faiwisinstance()/issubclass()checks.