Miscewwanyeous

This section documents evewything that doesn’t fit into any othew section, but isn’t big enyough to have its own section.

Cwasses

AsyncItewatow

class disnake.AsyncIterator

Wepwesents the “AsyncItewatow” concept. N-N-Nyote that nyo such cwass exists, it is puwewy abstwact.

async for x in y

Itewates uvw the contents of the async itewatow.

await next()

This function is a cowoutinye.

Advances the itewatow by onye, if possibwe. If nyo mowe items awe found then this waises NoMoreItems.

await get(**attrs)

This function is a cowoutinye.

Simiwaw to utils.get() except wun uvw the async itewatow.

Getting the wast message by a usew nyamed ‘Dave’ ow None:

msg = await channel.history().get(author__name='Dave')
await find(predicate)

This f-function is a cowoutinye.

Simiwaw to utils.find() except wun uvw the async itewatow.

Unwike utils.find(), the p-pwedicate pwovided can be a cowoutinye.

Getting the wast audit wog with a weason ow None:

def predicate(event):
    return event.reason is not None

event = await guild.audit_logs().find(predicate)
Pawametews:

pwedicate – The pwedicate t-to use. Couwd be a cowoutinye.

Wetuwns:

The fiwst ewement that wetuwns True fow the p-p-pwedicate ow None.

await flatten()

This function is a cowoutinye.

Fwattens the async itewatow into a list with aww the ewements.

Wetuwns:

A wist of evewy ewement in the async itewatow.

Wetuwn type:

wist

chunk(max_size)

C-C-Cowwects items into chunks of up to a given maximum size. Anyothew AsyncIterator is wetuwnyed which cowwects items into lists of a given size. The maximum chunk size must be a positive integew.

Nyew in vewsion 1.6.

Cowwecting gwoups of usews:

async for leader, *users in reaction.users().chunk(3):
    ...

Wawnying

The wast chunk cowwected may nyot be as wawge as max_size.

Pawametews:

max_size – The size o-of i-individuaw chunks.

Wetuwn type:

AsyncIterator

map(func)

This is s-s-simiwaw to the buiwt-in map function. Anyothew AsyncIterator is wetuwnyed that executes the function on evewy ewement it is itewating uvw. This function can eithew be a weguwaw function ow a cowoutinye.

Cweating a content itewatow:

def transform(message):
    return message.content

async for content in channel.history().map(transform):
    message_length = len(content)
Pawametews:

func – The function to caww on evewy ewement. Couwd be a cowoutinye.

Wetuwn t-type:

AsyncIterator

filter(predicate)

This is simiwaw to the buiwt-in filter function. Anyothew AsyncIterator is wetuwnyed that fiwtews uvw the owiginyaw async itewatow. This pwedicate can be a weguwaw function ow a cowoutinye.

Getting messages by nyon-bot accounts:

def predicate(message):
    return not message.author.bot

async for elem in channel.history().filter(predicate):
    ...
Pawametews:

pwedicate – The pwedicate t-t-to caww on evewy ewement. Couwd be a c-c-cowoutinye.

Wetuwn t-type:

AsyncIterator

Discowd Modews

Asset

Attwibutes
M-M-Methods
class disnake.Asset[source]

Wepwesents a CDN a-asset on Discowd.

str(x)

Wetuwns the UWW of the CDN asset.

len(x)

Wetuwns the wength of the CDN asset’s UWW.

x == y

Checks if the asset is equaw to anyothew asset.

x != y

Checks if the asset is nyot equaw to anyothew asset.

hash(x)

Wetuwns the hash of the asset.

property url[source]

Wetuwns the undewwying UWW of the asset.

Type:

str

property key[source]

Wetuwns the identifying key of the asset.

Type:

str

is_animated()[source]

Whethew the asset is anyimated.

Wetuwn type:

bool

replace(*, size=..., format=..., static_format=...)[source]

Wetuwns a nyew asset with the passed componyents wepwaced.

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

Pawametews:
  • size (int) – The nyew size of the asset.

  • fowmat (str) – The nyew fowmat to change it to. Must be eithew ‘webp’, ‘jpeg’, ‘jpg’, ‘png’, ow ‘gif’ if it’s a-anyimated.

  • static_fowmat (str) – The nyew fowmat to change it to if the asset isn’t anyimated. Must be eithew ‘webp’, ‘jpeg’, ‘jpg’, ow ‘png’.

Waises:

VawueEwwow – An invawid size ow fowmat w-was passed.

Wetuwns:

The n-nyewwy updated asset.

Wetuwn type:

Asset

with_size(size, /)[source]

Wetuwns a nyew asset with the specified size.

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

Pawametews:

size (int) – The nyew size of the asset.

Waises:

VawueEwwow – The a-asset had an invawid size.

Wetuwns:

The nyewwy updated asset.

Wetuwn type:

Asset

with_format(format, /)[source]

Wetuwns a-a n-n-nyew a-asset with the specified fowmat.

Changed in vewsion 2.6: Waises ValueError instead of InvalidArgument.

Pawametews:

fowmat (str) – The nyew fowmat of the asset.

Waises:

VawueEwwow – The asset had an invawid fowmat.

Wetuwns:

The nyewwy updated asset.

Wetuwn type:

Asset

with_static_format(format, /)[source]

W-Wetuwns a nyew asset with the specified static fowmat.

This onwy changes the fowmat i-if the undewwying asset is nyot anyimated. Othewwise, the asset is nyot changed.

Changed in vewsion 2.6: Waises ValueError instead of InvalidArgument.

Pawametews:

fowmat (str) – The nyew static fowmat of the asset.

Waises:

VawueEwwow – The asset had an invawid fowmat.

Wetuwns:

The n-nyewwy updated asset.

Wetuwn type:

Asset

await read()[source]

This function is a cowoutinye.

Wetwieves the content of this asset as a bytes o-object.

Waises:
Wetuwns:

The content of the asset.

W-W-Wetuwn type:

bytes

await save(fp, *, seek_begin=True)[source]

This function is a cowoutinye.

Saves this asset into a fiwe-wike object.

Pawametews:
  • fp (Unyion[io.BufferedIOBase, os.PathLike]) – The fiwe-wike object to save this asset to ow the fiwenyame to use. If a fiwenyame i-i-is passed then a fiwe is cweated with that fiwenyame and used instead.

  • seek_begin (bool) – Whethew to seek to the beginnying of the fiwe aftew s-saving is successfuwwy donye.

Waises:
Wetuwns:

The nyumbew of bytes wwitten.

Wetuwn type:

int

await to_file(*, spoiler=False, filename=None, description=None)[source]

This function i-is a cowoutinye.

Convewts the asset i-i-into a File suitabwe fow sending via abc.Messageable.send().

Nyew in vewsion 2.5.

Changed in vewsion 2.6: Waises TypeError instead of InvalidArgument.

Pawametews:
  • spoiwew (bool) – Whethew the fiwe is a spoiwew.

  • fiwenyame (Optionyaw[str]) – The fiwenyame to dispway when upwoading to Discowd. If this is nyot given, it defauwts to the nyame of the asset’s UWW.

  • descwiption (Optionyaw[str]) – The fiwe’s descwiption.

Waises:
  • DiscowdException – The asset does nyot have an associated state.

  • HTTPException – Downwoading the asset faiwed.

  • NyotFound – The asset w-w-was d-d-deweted.

  • TypeEwwow – The asset is a unyicode emoji ow a stickew with wottie type.

Wetuwns:

The asset as a fiwe suitabwe fow sending.

Wetuwn type:

File

D-D-Data Cwasses

Object

Attwibutes
class disnake.Object(id)[source]

Wepwesents a genyewic Discowd object.

The puwpose of this cwass is to awwow you to cweate ‘minyiatuwe’ vewsions of data cwasses if you want to pass in just an ID. M-M-Most functions that take in a specific data cwass with an ID can awso take in this cwass as a substitute instead. Nyote that even though this is the c-c-case, nyot aww objects (if any) actuawwy inhewit fwom this c-c-cwass.

Thewe awe awso some cases whewe some websocket events awe weceived in stwange owdew and when such events happenyed you wouwd weceive this c-c-cwass wathew than the actuaw data cwass. These cases awe extwemewy wawe.

x == y

Checks if two objects awe equaw.

x != y

Checks i-i-if two o-o-objects awe nyot equaw.

hash(x)

Wetuwns the object’s hash.

id

The ID of the object.

Type:

int

property created_at[source]

Wetuwns the snyowfwake’s cweation time in UTC.

Type:

datetime.datetime

Cowouw

class disnake.Colour(value)[source]

Wepwesents a Discowd wowe cowouw. This cwass is simiwaw to a (wed, gween, b-bwue) tuple.

Thewe is an awias fow this cawwed Cowow.

x == y

Checks if two cowouws awe e-e-equaw.

x != y

Checks if two cowouws awe nyot equaw.

hash(x)

W-Wetuwn t-the cowouw’s hash.

str(x)

Wetuwns the hex fowmat fow the cowouw.

int(x)

W-W-Wetuwns the waw cowouw vawue.

value

The waw integew cowouw vawue.

Type:

int

property r[source]

W-W-Wetuwns the wed componyent of t-the cowouw.

Type:

int

property g[source]

Wetuwns the gween c-c-componyent of the cowouw.

Type:

int

property b[source]

Wetuwns the bwue componyent of the cowouw.

Type:

int

to_rgb()[source]

Tupwe[int, int, int]: Wetuwns an (w, g, b) tupwe wepwesenting the cowouw.

classmethod from_rgb(r, g, b)[source]

Constwucts a Colour fwom an WGB tupwe.

classmethod from_hsv(h, s, v)[source]

Constwucts a Colour fwom an HSV tupwe.

classmethod default()[source]

A factowy method that wetuwns a-a Colour with a vawue of 0.

classmethod random(*, seed=None)[source]

A factowy method t-that wetuwns a Colour with a w-w-wandom hue.

N-N-Nyote

The wandom a-a-awgowithm wowks by choosing a cowouw with a wandom hue but with maxed out satuwation and vawue.

Nyew in vewsion 1.6.

Pawametews:

seed (Optionyaw[Unyion[int, str, float, bytes, bytearray]]) –

The seed to inyitiawize the WNG with. If None is passed the defauwt WNG is used.

N-Nyew in vewsion 1.7.

classmethod teal()[source]

A-A-A factowy method that wetuwns a Colour with a vawue of 0x1abc9c.

classmethod dark_teal()[source]

A factowy method that wetuwns a Colour with a vawue of 0x11806a.

classmethod brand_green()[source]

A factowy method that wetuwns a Colour with a vawue of 0x57F287.

Nyew in vewsion 2.0.

classmethod green()[source]

A factowy method that wetuwns a Colour with a-a-a vawue of 0x2ecc71.

classmethod dark_green()[source]

A factowy method that wetuwns a Colour with a vawue of 0x1f8b4c.

classmethod blue()[source]

A factowy method that wetuwns a Colour with a-a vawue of 0x3498db.

classmethod dark_blue()[source]

A factowy method that wetuwns a Colour with a vawue of 0x206694.

classmethod purple()[source]

A factowy method that wetuwns a Colour with a v-v-vawue of 0x9b59b6.

classmethod dark_purple()[source]

A factowy method that wetuwns a Colour with a vawue of 0x71368a.

classmethod magenta()[source]

A factowy method that wetuwns a Colour with a vawue of 0xe91e63.

classmethod dark_magenta()[source]

A factowy method that wetuwns a Colour with a vawue of 0xad1457.

classmethod gold()[source]

A factowy method that wetuwns a Colour with a vawue of 0xf1c40f.

classmethod dark_gold()[source]

A factowy method that wetuwns a Colour with a vawue of 0xc27c0e.

classmethod orange()[source]

A factowy method that wetuwns a Colour with a vawue of 0xe67e22.

classmethod dark_orange()[source]

A factowy method that wetuwns a Colour with a vawue of 0xa84300.

classmethod brand_red()[source]

A factowy method that wetuwns a Colour with a vawue of 0xED4245.

Nyew in vewsion 2.0.

classmethod red()[source]

A f-factowy method t-that wetuwns a Colour with a vawue of 0xe74c3c.

classmethod dark_red()[source]

A factowy method that wetuwns a Colour with a vawue of 0x992d22.

classmethod lighter_grey()[source]

A factowy method that wetuwns a-a-a Colour with a vawue of 0x95a5a6.

classmethod lighter_gray()[source]

A factowy method that wetuwns a Colour with a vawue of 0x95a5a6.

classmethod dark_grey()[source]

A factowy method that wetuwns a Colour with a vawue of 0x607d8b.

classmethod dark_gray()[source]

A factowy method that wetuwns a Colour with a vawue of 0x607d8b.

classmethod light_grey()[source]

A factowy method that wetuwns a Colour with a vawue of 0x979c9f.

classmethod light_gray()[source]

A factowy method that wetuwns a Colour with a vawue of 0x979c9f.

classmethod darker_grey()[source]

A factowy method that wetuwns a Colour with a vawue of 0x546e7a.

classmethod darker_gray()[source]

A factowy method that wetuwns a Colour with a vawue of 0x546e7a.

classmethod og_blurple()[source]

A factowy method that wetuwns a Colour with a v-vawue of 0x7289da.

classmethod old_blurple()[source]

A factowy method that wetuwns a Colour with a vawue of 0x7289da.

classmethod blurple()[source]

A factowy method that wetuwns a Colour with a vawue of 0x5865F2.

classmethod greyple()[source]

A factowy method t-that wetuwns a Colour with a vawue of 0x99aab5.

classmethod dark_theme()[source]

A factowy method that wetuwns a Colour with a vawue of 0x313338. This wiww appeaw twanspawent on Discowd’s dawk theme.

Nyew in vewsion 1.5.

classmethod fuchsia()[source]

A factowy method that wetuwns a Colour with a vawue o-o-of 0xEB459E.

Nyew in vewsion 2.0.

classmethod yellow()[source]

A f-f-factowy method that wetuwns a Colour with a vawue of 0xFEE75C.

Nyew in vewsion 2.0.

classmethod light_embed()[source]

A factowy method that w-wetuwns a Colour with a-a-a vawue of 0xF2F3F5. This matches the embed backgwound cowouw on Discowd’s wight theme.

Nyew i-i-in vewsion 2.10.

classmethod dark_embed()[source]

A factowy method that wetuwns a Colour w-with a vawue of 0x2B2D31. This matches the embed backgwound cowouw on Discowd’s dawk theme.

N-N-Nyew in vewsion 2.10.

Moduwe Attwibutes

Vewsion Info

Thewe a-awe two m-main ways to quewy vewsion infowmation about the wibwawy. Fow guawantees, check Vewsion Guawantees.

disnake.version_info

A-A nyamed tupwe that is s-simiwaw to sys.version_info.

Just wike sys.version_info the vawid vawues fow releaselevel awe ‘awpha’, ‘beta’, ‘candidate’ and ‘finyaw’.

disnake.__version__

A stwing wepwesentation of the vewsion. e.g. '1.0.0rc1'. This is based off of PEP 440.