PrimaryGuild¶
- class disnake.PrimaryGuild[source]¶
Represents a user’s primary guild.
New in version 2.11.
This section documents everything related to users.
Represents a Discord user.
Checks if two users are equal.
Checks if two users are not equal.
Return the user’s hash.
Returns the user’s username (with discriminator, if not migrated to new system yet).
The user’s discriminator.
Note
This is being phased out by Discord; the username system is moving away from username#discriminator
to 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.
The user’s global display name, if set.
This takes precedence over name
when shown.
New in version 2.9.
Optional[str
]
Returns an AsyncIterator
that enables receiving the destination’s message history.
You must have Permissions.read_message_history
permission 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.
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 True
if
after
is specified, otherwise False
.
Forbidden – You do not have permissions to get channel message history.
HTTPException – The request to get message history failed.
Message
– The message with the message data parsed.
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 with
and async with
work with this.
Example Usage:
async with channel.typing():
# simulate something heavy
await asyncio.sleep(10)
await channel.send('done!')
Returns the channel associated with this user if it exists.
If this returns None
, you can create a DM channel by calling the
create_dm()
coroutine function.
Optional[DMChannel
]
The guilds that the user shares with the client.
Note
This will only return mutual guilds within the client’s internal cache.
New in version 1.7.
List[Guild
]
This function is a coroutine.
Creates a DMChannel
with this user.
This should be rarely called, as this is done transparently for most people.
The channel that was created.
Returns the user’s accent color, if applicable.
There is an alias for this named accent_colour
.
New in version 2.0.
Note
This information is only available via Client.fetch_user()
.
Optional[Colour
]
Returns the user’s accent colour, if applicable.
There is an alias for this named accent_color
.
New in version 2.0.
Note
This information is only available via Client.fetch_user()
.
Optional[Colour
]
Returns an Asset
for the avatar the user has.
If the user does not have a traditional avatar, None
is returned.
If you want the avatar that a user has displayed, consider display_avatar
.
Optional[Asset
]
Returns the user’s avatar decoration asset, if available.
New in version 2.10.
Note
Since Discord always sends an animated PNG for animated avatar decorations, the following methods will not work as expected:
Optional[Asset
]
Returns the user’s banner asset, if available.
New in version 2.0.
Note
This information is only available via Client.fetch_user()
.
Optional[Asset
]
A property that returns a color denoting the rendered color
for the user. This always returns Colour.default()
.
There is an alias for this named colour
.
A property that returns a colour denoting the rendered colour
for the user. This always returns Colour.default()
.
There is an alias for this named color
.
Returns the user’s creation time in UTC.
This is when the user’s Discord account was created.
Returns the default avatar for a given user.
Changed in version 2.9: Added handling for users migrated to the new username system without discriminators.
Returns the user’s display avatar.
For regular users this is just their default avatar or uploaded avatar.
New in version 2.0.
Returns the user’s display name.
This is their global name
if set,
or their username
otherwise.
Changed in version 2.9: Added global_name
.
This function is a coroutine.
Retrieves a single Message
from the destination.
id (int
) – The message ID to look for.
NotFound – The specified message was not found.
Forbidden – You do not have the permissions required to get a message.
HTTPException – Retrieving the message failed.
The message asked for.
Returns an AsyncIterator
that enables receiving the destination’s pinned messages.
You must have the Permissions.read_message_history
and Permissions.view_channel
permissions to use this.
Note
Due to a limitation with the Discord API, the Message
objects returned by this method do not contain complete
Message.reactions
data.
Changed in version 2.11: Now returns an AsyncIterator
to support changes in Discord’s API.
await
ing 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.
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.
HTTPException – Retrieving the pinned messages failed.
Message
– The pinned message from the parsed message data.
Returns the user’s primary guild, if any.
New in version 2.11.
Optional[PrimaryGuild
]
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
, poll
or view
must be provided.
To upload a single file, the file
parameter should be used with a
single File
object. To upload multiple files, the files
parameter should be used with a list
of File
objects.
Specifying both parameters will lead to an exception.
To upload a single embed, the embed
parameter should be used with a
single Embed
object. To upload multiple embeds, the embeds
parameter should be used with a list
of Embed
objects.
Specifying both parameters will lead to an exception.
Changed in version 2.6: Raises TypeError
or ValueError
instead of InvalidArgument
.
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
embeds
parameter.
embeds (List[Embed
]) –
A list of embeds to send with the content. Must be a maximum of 10.
This cannot be mixed with the embed
parameter.
New in version 2.0.
file (File
) – The file to upload. This cannot be mixed with the files
parameter.
files (List[File
]) – A list of files to upload. Must be a maximum of 10.
This cannot be mixed with the file
parameter.
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_mentions
are used instead.
New in version 1.4.
reference (Union[Message
, MessageReference
, PartialMessage
]) –
A reference to the Message
to 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_user
attribute of allowed_mentions
or by setting mention_author
.
New in version 1.6.
Note
Passing a Message
or PartialMessage
will only allow replies. To forward a message
you must explicitly transform the message to a MessageReference
using Message.to_reference()
and specify the MessageReferenceType
,
or use Message.forward()
.
mention_author (Optional[bool
]) –
If set, overrides the AllowedMentions.replied_user
attribute 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_v2
flag.
Setting this flag cannot be reverted. Note that this also disables the
content
, embeds
, stickers
, and poll
fields.
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_v2
are supported.
If parameter suppress_embeds
is 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.
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
TypeError – Specified both file
and files
,
or you specified both embed
and embeds
,
or you specified both view
and components
,
or the reference
object is not a Message
,
MessageReference
or PartialMessage
.
ValueError – The files
or embeds
list is too large, or
you tried to send v2 components together with content
, embeds
, stickers
, or poll
.
The message that was sent.
Represents the decoration behind the name of a user that appears in the server, DM and DM group members list.
New in version 2.11.
The background color of the nameplate.
Wraps up the Discord User Public flags.
Checks if two PublicUserFlags instances are equal.
Checks if two PublicUserFlags instances are not equal.
Checks if a PublicUserFlags instance is a subset of another PublicUserFlags instance.
New in version 2.6.
Checks if a PublicUserFlags instance is a superset of another PublicUserFlags instance.
New in version 2.6.
Checks if a PublicUserFlags instance is a strict subset of another PublicUserFlags instance.
New in version 2.6.
Checks if a PublicUserFlags instance is a strict superset of another PublicUserFlags instance.
New in version 2.6.
Returns a new PublicUserFlags instance with all enabled flags from both x and y.
(Using |=
will update in place).
New in version 2.6.
Returns a new PublicUserFlags instance with only flags enabled on both x and y.
(Using &=
will update in place).
New in version 2.6.
Returns a new PublicUserFlags instance with only flags enabled on one of x or y, but not both.
(Using ^=
will update in place).
New in version 2.6.
Returns a new PublicUserFlags instance with all flags from x inverted.
New in version 2.6.
Return the flag’s hash.
Returns an iterator of (name, value)
pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
Additionally supported are a few operations on class attributes.
Returns a PublicUserFlags instance with all provided flags enabled.
New in version 2.6.
Returns a PublicUserFlags instance with all flags except y
inverted from their default value.
New in version 2.6.
New in version 1.4.
The raw value. This value is a bit array field of a 53-bit integer representing the currently available flags. You should query flags via the properties rather than using this raw value.
An alias for verified_bot_developer
.
New in version 1.5.
Returns True
if the user is a Discord Moderator Programs Alumni.
New in version 2.8.
An alias for moderator_programs_alumni
.
New in version 2.0.
Returns True
if the user is a bot that only uses HTTP interactions.
New in version 2.3.
Wraps up Discord Member flags.
Checks if two MemberFlags instances are equal.
Checks if two MemberFlags instances are not equal.
Checks if a MemberFlags instance is a subset of another MemberFlags instance.
Checks if a MemberFlags instance is a superset of another MemberFlags instance.
Checks if a MemberFlags instance is a strict subset of another MemberFlags instance.
Checks if a MemberFlags instance is a strict superset of another MemberFlags instance.
Returns a new MemberFlags instance with all enabled flags from both x and y.
(Using |=
will update in place).
Returns a new MemberFlags instance with only flags enabled on both x and y.
(Using &=
will update in place).
Returns a new MemberFlags instance with only flags enabled on one of x or y, but not both.
(Using ^=
will update in place).
Returns a new MemberFlags instance with all flags from x inverted.
Returns the flag’s hash.
Returns an iterator of (name, value)
pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.
Additionally supported are a few operations on class attributes.
Returns a MemberFlags instance with all provided flags enabled.
Returns a MemberFlags instance with all flags except y
inverted from their default value.
New in version 2.8.
The raw value. You should query flags via the properties rather than using this raw value.
Returns True
if the member is able to bypass guild verification requirements.
Returns True
if the member is a guest and can only access the voice channel they were invited to.
New in version 2.10.
Returns True
if the member has started the Server Guide actions.
New in version 2.10.
Returns True
if the member has completed the Server Guide actions.
New in version 2.10.
Returns True
if the member’s username, display name, or nickname is blocked by AutoMod.
New in version 2.10.
Returns True
if the member has dismissed the DM settings upsell.
New in version 2.10.
Represents a user’s primary guild.
New in version 2.11.
Represents Discord user flags.
The user is a Discord Employee.
The user is a Discord Partner.
The user is a HypeSquad Events member.
The user is a Bug Hunter.
The user has SMS recovery for Multi Factor Authentication enabled.
The user has dismissed the Discord Nitro promotion.
The user is a HypeSquad Bravery member.
The user is a HypeSquad Brilliance member.
The user is a HypeSquad Balance member.
The user is an Early Supporter.
The user is a Team User.
The user is a system user (i.e. represents Discord officially).
The user has an unread system message.
The user is a Bug Hunter Level 2.
The user is a Verified Bot.
The user is an Early Verified Bot Developer.
The user is a Discord Certified Moderator.
The user is a bot that only uses HTTP interactions.
New in version 2.3.
The user is marked as a spammer.
New in version 2.3.
The user is an Active Developer.
New in version 2.8.
Represents the default avatar of a Discord User
.
Represents the default avatar with the color blurple. See also Colour.blurple
.
Represents the default avatar with the color grey. See also Colour.greyple
.
Represents the default avatar with the color green. See also Colour.green
.
Represents the default avatar with the color orange. See also Colour.orange
.
Represents the default avatar with the color red. See also Colour.red
.
Represents the default avatar with the color fuchsia. See also Colour.fuchsia
.
New in version 2.9.
Specifies the palette of a Nameplate
.
New in version 2.11.
Crimson color palette.
Berry color palette.
Sky color palette.
Teal color palette.
Forest color palette.
Bubble gum color palette.
Violet color palette.
Cobalt color palette.
Clover color palette.
Lemon color palette.
White color palette.