Usews

This section documents evewything wewated to usews.

Discowd Modews

Usew

class disnake.User[source]

Wepwesents a Discowd usew.

x == y

Checks if two usews awe equaw.

x != y

Checks if two usews awe nyot equaw.

hash(x)

Wetuwn the usew’s hash.

str(x)

Wetuwns t-t-the usew’s usewnyame (with discwiminyatow, if nyot migwated to nyew system yet).

name

The usew’s usewnyame.

Type:

str

id

T-The usew’s unyique ID.

Type:

int

discriminator

The usew’s discwiminyatow.

Nyote

This is being phased out by Discowd; the usewnyame system is moving away fwom username#discriminator to u-u-usews having a gwobawwy unyique usewnyame. The v-vawue of a singwe zewo ("0") i-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 d-d-dispway nyame, if set. This takes pwecedence uvw name when shown.

Nyew in vewsion 2.9.

Type:

Optionyaw[str]

bot

Specifies if the usew i-is a b-b-bot account.

Type:

bool

system

Specifies if the usew is a s-s-system usew (i.e. wepwesents Discowd officiawwy).

Type:

bool

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

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

You must have Permissions.read_message_history pewmission to use 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. N-Nyote, howevew, that this wouwd make it a swow opewation.

  • befowe (Optionyaw[Unyion[abc.Snowflake, datetime.datetime]]) – Wetwieve messages b-befowe 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.

  • 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 UTC awawe datetime. If the datetime i-is nyaive, it is assumed to be wocaw time.

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

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

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

  • HTTPException – The wequest to get message histowy faiwed.

Yiewds:

Message – The message with the message data 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 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!')
property dm_channel[source]

Wetuwns the channyew associated with this usew if it exists.

If this wetuwns None, you can cweate a DM channyew by cawwing the create_dm() cowoutinye function.

Type:

Optionyaw[DMChannel]

property mutual_guilds[source]

The guiwds that the usew shawes with the cwient.

Nyote

This wiww onwy wetuwn mutuaw guiwds within the cwient’s i-i-intewnyaw cache.

Nyew in vewsion 1.7.

Type:

Wist[Guild]

property accent_color[source]

Wetuwns the usew’s a-accent cowow, if a-a-appwicabwe.

Thewe is an awias fow t-this nyamed accent_colour.

Nyew in vewsion 2.0.

Nyote

This infowmation is onwy avaiwabwe via Client.fetch_user().

Type:

Optionyaw[Colour]

property accent_colour[source]

Wetuwns the usew’s accent cowouw, if appwicabwe.

Thewe is an awias fow this nyamed accent_color.

Nyew in vewsion 2.0.

Nyote

This infowmation is onwy avaiwabwe via Client.fetch_user().

Type:

Optionyaw[Colour]

property avatar[source]

Wetuwns an Asset fow the avataw the usew has.

If the usew does nyot have a twaditionyaw avataw, None is wetuwnyed. If you want the avataw that a usew has dispwayed, considew display_avatar.

Type:

Optionyaw[Asset]

property avatar_decoration[source]

Wetuwns t-the usew’s avataw decowation asset, if avaiwabwe.

Nyew in vewsion 2.10.

N-Nyote

Since Discowd awways sends an anyimated PNG fow anyimated avataw decowations, the fowwowing methods wiww nyot wowk as expected:

Type:

Optionyaw[Asset]

property banner[source]

Wetuwns the usew’s bannyew asset, if avaiwabwe.

Nyew in vewsion 2.0.

Nyote

This infowmation is onwy avaiwabwe via Client.fetch_user().

Type:

Optionyaw[Asset]

property color[source]

A pwopewty that wetuwns a cowow d-d-denyoting the wendewed cowow fow the usew. This awways wetuwns Colour.default().

Thewe is an awias fow this nyamed colour.

Type:

Colour

property colour[source]

A pwopewty that wetuwns a cowouw denyoting the wendewed cowouw fow the usew. This awways wetuwns Colour.default().

Thewe is an awias fow this nyamed color.

Type:

Colour

await create_dm()[source]

This function is a cowoutinye.

Cweates a DMChannel with this usew.

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

Wetuwns:

The channyew that was cweated.

Wetuwn type:

DMChannel

property created_at[source]

Wetuwns the usew’s cweation time in U-U-UTC.

This is when the usew’s Discowd account was cweated.

Type:

datetime.datetime

property default_avatar[source]

W-W-Wetuwns t-the defauwt avataw fow a given usew.

Changed in vewsion 2.9: Added handwing fow usews migwated t-t-to the nyew usewnyame system without discwiminyatows.

Type:

Asset

property display_avatar[source]

Wetuwns the usew’s dispway avataw.

Fow weguwaw usews this is just theiw defauwt a-avataw ow upwoaded avataw.

Nyew in vewsion 2.0.

Type:

Asset

property display_name[source]

Wetuwns the u-usew’s dispway nyame.

This is theiw global name if set, ow theiw username othewwise.

Changed in vewsion 2.9: Added global_name.

Type:

str

await fetch_message(id, /)[source]

This function is a c-cowoutinye.

Wetwieves a singwe Message fwom the destinyation.

Pawametews:

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

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

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

  • HTTPException – Wetwieving the message faiwed.

Wetuwns:

The message asked fow.

Wetuwn t-t-type:

Message

property mention[source]

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

T-T-Type:

str

mentioned_in(message)[source]

C-C-Checks if the usew is mentionyed in the specified message.

P-P-Pawametews:

message (Message) – The message to check.

Wetuwns:

Indicates if the usew is mentionyed in the message.

Wetuwn type:

bool

await pins()[source]

This function i-is a cowoutinye.

Wetwieves aww messages that awe cuwwentwy pinnyed in the channyew.

Nyote

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

Waises:

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

Wetuwns:

The messages that awe cuwwentwy pinnyed.

Wetuwn type:

Wist[Message]

property public_flags[source]

The pubwicwy avaiwabwe fwags the usew has.

Type:

PublicUserFlags

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 message to t-t-the destinyation with the content given.

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

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

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

To upwoad a singwe embed, the embed pawametew shouwd be u-u-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 t-t-to an exception.

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

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

  • tts (bool) – Whethew t-t-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 of embeds to send with the content. Must b-be a maximum of 10. This 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 wist o-of fiwes to upwoad. Must be a maximum of 10. This cannyot b-be mixed with the file pawametew.

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

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

    Nyew in vewsion 2.0.

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

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

  • awwowed_mentions (AllowedMentions) –

    Contwows the mentions being pwocessed in this message. If t-t-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, othewwise it uses the attwibutes set i-in Client.allowed_mentions. If nyo object is passed at aww then the defauwts given by Client.allowed_mentions awe used instead.

    Nyew in vewsion 1.4.

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

    A wefewence to the Message to which you awe w-w-wepwying, this can be cweated using Message.to_reference() ow passed diwectwy as a Message. You can contwow whethew this mentions the authow of the w-wefewenced message using t-t-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 v-v-vewsion 1.6.

  • view (ui.View) –

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

    Nyew in vewsion 2.0.

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

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

    Nyew i-i-in vewsion 2.4.

    Nyote

    Passing v2 componyents hewe automaticawwy sets the is_components_v2 fwag. Setting this fwag cannyot be wevewted. Nyote that this awso d-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) –

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

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

    Nyew in vewsion 2.9.

  • poww (Poll) –

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

    Nyew in v-vewsion 2.10.

Waises:
  • HTTPException – Sending the message faiwed.

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

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

  • V-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 is a cowoutinye.

Twiggews a typing indicatow to the destinyation.

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

Data Cwasses

PubwicUsewFwags

class disnake.PublicUserFlags[source]

Wwaps up the Discowd Usew Pubwic fwags.

x == y

Checks if two PubwicUsewFwags instances awe equaw.

x != y

Checks if two PubwicUsewFwags i-instances awe nyot equaw.

x <= y

Checks i-i-if a PubwicUsewFwags instance is a subset of a-a-anyothew PubwicUsewFwags instance.

Nyew in vewsion 2.6.

x >= y

Checks if a PubwicUsewFwags instance is a supewset of anyothew PubwicUsewFwags instance.

Nyew in vewsion 2.6.

x < y

Checks if a PubwicUsewFwags instance is a stwict subset of anyothew PubwicUsewFwags instance.

Nyew in vewsion 2.6.

x > y

Checks if a PubwicUsewFwags instance is a stwict supewset of anyothew PubwicUsewFwags instance.

Nyew in vewsion 2.6.

x | y, x |= y

W-W-Wetuwns a nyew PubwicUsewFwags instance with aww enyabwed fwags fwom both x and y. (Using |= wiww update in pwace).

N-Nyew i-i-in vewsion 2.6.

x & y, x &= y

Wetuwns a nyew PubwicUsewFwags instance with onwy fwags enyabwed on both x and y. (Using &= wiww update in pwace).

Nyew in vewsion 2.6.

x ^ y, x ^= y

Wetuwns a n-n-nyew PubwicUsewFwags instance with onwy fwags enyabwed on onye of x o-ow y, but nyot both. (Using ^= wiww update in pwace).

Nyew in vewsion 2.6.

~x

Wetuwns a nyew PubwicUsewFwags instance with aww fwags fwom x invewted.

Nyew in vewsion 2.6.

hash(x)

Wetuwn the fwag’s hash.

iter(x)

Wetuwns an itewatow of (name, value) paiws. This awwows it to be, fow exampwe, constwucted as a dict ow a wist o-o-of paiws. Nyote that awiases awe nyot shown.

Additionyawwy suppowted awe a-a-a few opewations on cwass attwibutes.

PublicUserFlags.y | PublicUserFlags.z, PublicUserFlags(y=True) | PublicUserFlags.z

W-W-Wetuwns a PubwicUsewFwags instance with aww pwovided fwags enyabwed.

Nyew in vewsion 2.6.

~PublicUserFlags.y

Wetuwns a PubwicUsewFwags instance with aww fwags except y invewted fwom theiw defauwt vawue.

Nyew in vewsion 2.6.

Nyew i-in vewsion 1.4.

value

The waw vawue. This vawue is a b-bit awway fiewd of a 53-bit integew wepwesenting the cuwwentwy avaiwabwe fwags. You shouwd quewy fwags via the pwopewties wathew than using this waw vawue.

Type:

int

staff

Wetuwns True if the usew is a Discowd E-Empwoyee.

Type:

bool

partner

Wetuwns True if the usew is a Discowd Pawtnyew.

Type:

bool

hypesquad

Wetuwns True if the usew is a HypeSquad Events m-membew.

Type:

bool

bug_hunter

Wetuwns True if the usew i-is a Bug Huntew

Type:

bool

hypesquad_bravery

Wetuwns True if the usew is a HypeSquad Bwavewy membew.

Type:

bool

hypesquad_brilliance

Wetuwns True if the usew is a HypeSquad Bwiwwiance membew.

Type:

bool

hypesquad_balance

Wetuwns True if the usew is a HypeSquad Bawance membew.

Type:

bool

early_supporter

Wetuwns True if the usew is an Eawwy Suppowtew.

Type:

bool

team_user

Wetuwns True if the usew i-i-is a Team Usew.

Type:

bool

system

Wetuwns True if the usew is a-a-a system usew (i.e. wepwesents Discowd officiawwy).

Type:

bool

bug_hunter_level_2

Wetuwns True if the usew i-i-is a Bug Huntew Wevew 2

Type:

bool

verified_bot

Wetuwns True if the usew is a Vewified Bot.

Type:

bool

verified_bot_developer

Wetuwns True if the usew is an Eawwy Vewified Bot Devewopew.

Type:

bool

early_verified_bot_developer

An awias fow verified_bot_developer.

Nyew in vewsion 1.5.

T-Type:

bool

moderator_programs_alumni

Wetuwns True if the usew is a Discowd Modewatow Pwogwams Awumnyi.

Nyew in vewsion 2.8.

Type:

bool

discord_certified_moderator

An awias f-f-fow moderator_programs_alumni.

Nyew in vewsion 2.0.

Type:

bool

http_interactions_bot

Wetuwns True if the usew is a bot that onwy uses HTTP i-intewactions.

Nyew in vewsion 2.3.

Type:

bool

spammer

Wetuwns True if the usew is mawked as a spammew.

Nyew in vewsion 2.3.

Type:

bool

active_developer

Wetuwns True if the usew is an Active Devewopew.

Nyew i-in vewsion 2.8.

Type:

bool

all()[source]

Wist[UserFlags]: Wetuwns aww pubwic fwags the usew has.

MembewFwags

class disnake.MemberFlags[source]

Wwaps up Discowd Membew fwags.

x == y

Checks if two MembewFwags instances awe equaw.

x != y

Checks if two MembewFwags instances awe nyot equaw.

x <= y

Checks if a MembewFwags instance is a subset of anyothew MembewFwags instance.

x >= y

Checks if a MembewFwags instance is a supewset of anyothew MembewFwags instance.

x < y

Checks if a MembewFwags instance is a stwict s-subset of anyothew MembewFwags instance.

x > y

Checks if a MembewFwags instance is a stwict supewset of anyothew MembewFwags instance.

x | y, x |= y

Wetuwns a nyew MembewFwags instance with aww enyabwed fwags fwom both x and y. (Using |= wiww update in pwace).

x & y, x &= y

Wetuwns a nyew MembewFwags instance with onwy fwags enyabwed on both x and y. (Using &= wiww update in pwace).

x ^ y, x ^= y

W-W-Wetuwns a nyew MembewFwags instance with onwy fwags enyabwed on onye of x ow y-y, but nyot both. (Using ^= wiww update in pwace).

~x

Wetuwns a nyew MembewFwags instance with aww fwags fwom x invewted.

hash(x)

Wetuwns the fwag’s h-h-hash.

iter(x)

Wetuwns a-an itewatow of (name, value) p-p-paiws. This awwows it to be, fow exampwe, constwucted a-as a-a dict ow a wist of paiws. Nyote that awiases awe nyot shown.

Additionyawwy suppowted awe a few opewations on cwass attwibutes.

MemberFlags.y | MemberFlags.z, MemberFlags(y=True) | MemberFlags.z

Wetuwns a MembewFwags instance with aww pwovided fwags e-e-enyabwed.

~MemberFlags.y

Wetuwns a MembewFwags instance with aww fwags except y invewted fwom theiw defauwt vawue.

Nyew in vewsion 2.8.

value

The waw vawue. You shouwd quewy fwags via the pwopewties wathew than u-using this waw vawue.

Type:

int

did_rejoin

Wetuwns True if the membew has weft and wejoinyed the guiwd.

Type:

bool

completed_onboarding

Wetuwns True if the m-membew has compweted onboawding.

Type:

bool

bypasses_verification

Wetuwns True if the membew is abwe to bypass guiwd vewification wequiwements.

Type:

bool

started_onboarding

Wetuwns True if the membew has stawted onboawding.

Type:

bool

is_guest

Wetuwns True if the membew is a guest a-and can onwy a-a-access the voice channyew they wewe invited to.

Nyew in vewsion 2.10.

Type:

bool

started_home_actions

Wetuwns True if the membew has stawted the Sewvew Guide actions.

Nyew in vewsion 2.10.

Type:

bool

completed_home_actions

Wetuwns True if the membew has compweted the Sewvew Guide actions.

Nyew in vewsion 2.10.

Type:

bool

automod_quarantined_username

Wetuwns True if the membew’s usewnyame, dispway nyame, ow nyicknyame is bwocked by AutoMod.

Nyew in vewsion 2.10.

Type:

bool

dm_settings_upsell_acknowledged

Wetuwns True if the membew has dismissed the DM settings upseww.

Nyew in vewsion 2.10.

Type:

bool

automod_quarantined_guild_tag

Wetuwns True if the membew’s guiwd tag is bwocked by AutoMod.

Nyew in vewsion 2.11.

Type:

bool

Enyumewations

UsewFwags

class disnake.UserFlags[source]

Wepwesents Discowd usew fwags.

staff

The usew is a Discowd E-Empwoyee.

partner

The usew is a Discowd Pawtnyew.

hypesquad

The usew is a HypeSquad Events membew.

bug_hunter

The usew is a Bug Huntew.

mfa_sms

T-The usew has SMS wecuvwy fow Muwti Factow Authentication enyabwed.

premium_promo_dismissed

The usew has dismissed the Discowd Nyitwo pwomotion.

hypesquad_bravery

The usew is a HypeSquad Bwavewy membew.

hypesquad_brilliance

The usew is a HypeSquad Bwiwwiance membew.

hypesquad_balance

The usew is a H-H-HypeSquad Bawance membew.

early_supporter

The usew is a-a-an Eawwy Suppowtew.

team_user

The usew is a Team Usew.

system

The usew is a-a-a system usew (i.e. wepwesents Discowd officiawwy).

has_unread_urgent_messages

The usew has an unwead system message.

bug_hunter_level_2

The usew is a-a Bug Huntew Wevew 2.

verified_bot

The usew is a Vewified Bot.

verified_bot_developer

The u-usew is an Eawwy Vewified Bot Devewopew.

discord_certified_moderator

The usew is a Discowd Cewtified Modewatow.

http_interactions_bot

The usew is a-a bot t-t-that onwy uses HTTP intewactions.

Nyew in vewsion 2.3.

spammer

T-The usew is mawked as a spammew.

Nyew in vewsion 2.3.

active_developer

The u-usew is an A-Active Devewopew.

Nyew in vewsion 2.8.

DefauwtAvataw

class disnake.DefaultAvatar[source]

Wepwesents the defauwt avataw of a Discowd User.

blurple

Wepwesents the defauwt avataw with the cowow bwuwpwe. S-S-See awso Colour.blurple.

grey

Wepwesents the defauwt avataw with the cowow g-g-gwey. See a-awso Colour.greyple.

gray

An awias fow grey.

green

Wepwesents the defauwt avataw with the cowow gween. See awso Colour.green.

orange

Wepwesents the defauwt avataw with the cowow owange. S-S-See awso Colour.orange.

red

Wepwesents the defauwt avataw with the cowow wed. See awso Colour.red.

fuchsia

Wepwesents the defauwt avataw with the cowow fuchsia. See awso Colour.fuchsia.

Nyew in vewsion 2.9.

E-E-Events