Discord Models¶
Models are classes that are received from Discord and are not meant to be created by the user of the library.
危険
The classes listed below are not intended to be created by users and are also read-only.
For example, this means that you should not make your own User instances
nor should you modify the User instance yourself.
If you want to get one of these model classes instances they'd have to be through
the cache, and a common way of doing so is through the utils.find() function
or attributes of model classes that you receive from the events specified in the
Event Reference.
注釈
Nearly all classes here have __slots__ defined which means that it is impossible to have dynamic attributes to the data classes.
- defis_animated
- asyncread
- defreplace
- asyncsave
- defwith_format
- defwith_size
- defwith_static_format
- class discord.Asset(state, *, url, key, animated=False)[ソース]¶
Represents a CDN asset on Discord.
- str(x)
Returns the URL of the CDN asset.
- len(x)
Returns the length of the CDN asset's URL.
- x == y
Checks if the asset is equal to another asset.
- x != y
Checks if the asset is not equal to another asset.
- hash(x)
Returns the asset's url's hash.
This is equivalent to hash(
url).
- replace(*, size=..., format=..., static_format=...)[ソース]¶
Returns a new asset with the passed components replaced.
- パラメータ:
size (
int) -- The new size of the asset.format (
Literal['webp','jpeg','jpg','png','gif']) -- The new format to change it to. Must be either 'webp', 'jpeg', 'jpg', 'png', or 'gif' if it's animated.static_format (
Literal['webp','jpeg','jpg','png']) -- The new format to change it to if the asset isn't animated. Must be either 'webp', 'jpeg', 'jpg', or 'png'.
- 戻り値:
The newly updated asset.
- 戻り値の型:
- 例外:
InvalidArgument -- An invalid size or format was passed.
- with_size(size, /)[ソース]¶
Returns a new asset with the specified size.
- パラメータ:
size (
int) -- The new size of the asset.- 戻り値:
The new updated asset.
- 戻り値の型:
- 例外:
InvalidArgument -- The asset had an invalid size.
- with_format(format, /)[ソース]¶
Returns a new asset with the specified format.
- パラメータ:
format (
Literal['webp','jpeg','jpg','png','gif']) -- The new format of the asset.- 戻り値:
The new updated asset.
- 戻り値の型:
- 例外:
InvalidArgument -- The asset has an invalid format.
- with_static_format(format, /)[ソース]¶
Returns a new asset with the specified static format.
This only changes the format if the underlying asset is not animated. Otherwise, the asset is not changed.
- パラメータ:
format (
Literal['webp','jpeg','jpg','png']) -- The new static format of the asset.- 戻り値:
The new updated asset.
- 戻り値の型:
- 例外:
InvalidArgument -- The asset had an invalid format.
- await read()¶
This function is a coroutine.
Retrieves the content of this asset as a
bytesobject.- 戻り値:
The content of the asset.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
- await save(fp, *, seek_begin=True)¶
This function is a coroutine.
Saves this asset into a file-like object.
- パラメータ:
fp (
str|bytes|PathLike|BufferedIOBase) -- The file-like object to save this attachment to or the filename to use. If a filename is passed then a file is created with that filename and used instead.seek_begin (
bool) -- Whether to seek to the beginning of the file after saving is successfully done.
- 戻り値:
The number of bytes written.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
- class discord.Spotify[ソース]¶
Represents a Spotify listening activity from Discord. This is a special case of
Activitythat makes it easier to work with the Spotify integration.- x == y
Checks if two activities are equal.
- x != y
Checks if two activities are not equal.
- hash(x)
Returns the activity's hash.
- str(x)
Returns the string 'Spotify'.
- property type: ActivityType¶
Returns the activity's type. This is for compatibility with
Activity.It always returns
ActivityType.listening.
- property colour: Colour¶
Returns the Spotify integration colour, as a
Colour.There is an alias for this named
color
- property color: Colour¶
Returns the Spotify integration colour, as a
Colour.There is an alias for this named
colour
- class discord.VoiceState(*, data, channel=None)[ソース]¶
Represents a Discord user's voice state.
- self_stream¶
Indicates if the user is currently streaming via 'Go Live' feature.
Added in version 1.3.
- Type:
- suppress¶
Indicates if the user is suppressed from speaking.
Only applies to stage channels.
Added in version 1.7.
- Type:
- requested_to_speak_at¶
An aware datetime object that specifies the date and time in UTC that the member requested to speak. It will be
Noneif they are not requesting to speak anymore or have been accepted to speak.Only applicable to stage channels.
Added in version 1.7.
- Type:
Optional[
datetime.datetime]
- channel¶
The voice channel that the user is currently connected to.
Noneif the user is not currently in a voice channel.- Type:
Optional[Union[
VoiceChannel,StageChannel]]
- パラメータ:
data (
VoiceState)channel (
VocalGuildChannel|None)
- defcan_send
- asyncfetch_message
- defget_partial_message
- defhistory
- defpins
- asyncsend
- asynctrigger_typing
- deftyping
- class discord.PartialMessageable(state, id, type=None)[ソース]¶
Represents a partial messageable to aid with working messageable channels when only a channel ID are present.
The only way to construct this class is through
Client.get_partial_messageable().Note that this class is trimmed down and has no rich attributes.
Added in version 2.0.
- x == y
Checks if two partial messageables are equal.
- x != y
Checks if two partial messageables are not equal.
- hash(x)
Returns the partial messageable's hash.
- type¶
The channel type associated with this partial messageable, if given.
- Type:
Optional[
ChannelType]
- get_partial_message(message_id, /)[ソース]¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- await trigger_typing()¶
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.
- 戻り値の型:
- typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
Users¶
- asyncedit
- defmentioned_in
- class discord.ClientUser(*, state, data)[ソース]¶
Represents your Discord user.
- x == y
Checks if two users are equal.
- x != y
Checks if two users are not equal.
- hash(x)
Return the user's hash.
- str(x)
Returns the user's name with discriminator or global_name.
- discriminator¶
The user's discriminator. This is given when the username has conflicts.
注釈
If the user has migrated to the new username system, this will always be 0.
- Type:
- system¶
Specifies if the user is a system user (i.e. represents Discord officially).
Added in version 1.3.
- Type:
- パラメータ:
state (
ConnectionState)data (
User)
- await edit(*, username=..., avatar=..., banner=...)[ソース]¶
This function is a coroutine.
Edits the current profile of the client.
注釈
To upload an avatar or banner, a bytes-like object must be passed in that represents the image being uploaded. If this is done through a file then the file must be opened via
open('some_filename', 'rb')and the bytes-like object is given through the use offp.read().The only image formats supported for uploading are JPEG, PNG, and GIF.
バージョン 2.0 で変更: The edit is no longer in-place, instead the newly edited client user is returned.
バージョン 2.6 で変更: The
bannerkeyword-only parameter was added.- パラメータ:
username (
str) -- The new username you wish to change to.avatar (
bytes) -- A bytes-like object representing the image to upload. Could beNoneto denote no avatar.banner (
bytes) -- A bytes-like object representing the image to upload. Could beNoneto denote no banner.
- 戻り値:
The newly edited client user.
- 戻り値の型:
- 例外:
HTTPException -- Editing your profile failed.
InvalidArgument -- Wrong image format passed for
avatarorbanner.
- property accent_color: Colour | None¶
Returns the user's accent color, if applicable.
There is an alias for this named
accent_colour.Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property accent_colour: Colour | None¶
Returns the user's accent colour, if applicable.
There is an alias for this named
accent_color.Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property avatar: Asset | None¶
Returns an
Assetfor the avatar the user has.If the user does not have a traditional avatar,
Noneis returned. If you want the avatar that a user has displayed, considerdisplay_avatar.
- property avatar_decoration: Asset | None¶
Returns the user's avatar decoration, if available.
Added in version 2.5.
- property banner: Asset | None¶
Returns the user's banner asset, if available.
Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property collectibles: Collectibles | None¶
Returns the user's equipped collectibles.
Added in version 2.8.
- property color: Colour¶
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.
- property colour: 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.
- property created_at: datetime¶
Returns the user's creation time in UTC.
This is when the user's Discord account was created.
- property default_avatar: Asset¶
Returns the default avatar for a given user. This is calculated by the user's ID if they're on the new username system, otherwise their discriminator.
- property display_avatar: Asset¶
Returns the user's display avatar.
Returns the user's uploaded avatar. If the user has not uploaded any avatar, their default avatar is returned instead.
Added in version 2.0.
- property display_name: str¶
Returns the user's display name. This will be their global name if set, otherwise their username.
- property jump_url: str¶
Returns a URL that allows the client to jump to the user.
Added in version 2.0.
- mentioned_in(message)¶
Checks if the user is mentioned in the specified message.
- property nameplate: Nameplate | None¶
The user's nameplate, if the user has one equipped. Alias for
User.collectibles.nameplate.Added in version 2.7.
バージョン 2.8 で変更: Now an alias for
User.collectibles.nameplate.
- property public_flags: PublicUserFlags¶
The publicly available flags the user has.
- defcan_send
- asynccreate_dm
- asynccreate_test_entitlement
- defentitlements
- asyncfetch_message
- defhistory
- defmentioned_in
- defpins
- asyncsend
- asynctrigger_typing
- deftyping
- class discord.User(*, state, data)[ソース]¶
Represents a Discord user.
- x == y
Checks if two users are equal.
- x != y
Checks if two users are not equal.
- hash(x)
Return the user's hash.
- str(x)
Returns the user's name with discriminator or global_name.
- discriminator¶
The user's discriminator. This is given when the username has conflicts.
注釈
If the user has migrated to the new username system, this will always be "0".
- Type:
- primary_guild¶
The user's primary guild, if the user has one. Represent what guild the user's tag is from.
Added in version 2.7.
- Type:
Optional[
PrimaryGuild]
- パラメータ:
state (
ConnectionState)data (
User)
- async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- async with typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- property dm_channel: DMChannel | None¶
Returns the channel associated with this user if it exists.
If this returns
None, you can create a DM channel by calling thecreate_dm()coroutine function.
- property mutual_guilds: list[Guild]¶
The guilds that the user shares with the client.
注釈
This will only return mutual guilds within the client's internal cache.
Added in version 1.7.
- property accent_color: Colour | None¶
Returns the user's accent color, if applicable.
There is an alias for this named
accent_colour.Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property accent_colour: Colour | None¶
Returns the user's accent colour, if applicable.
There is an alias for this named
accent_color.Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property avatar: Asset | None¶
Returns an
Assetfor the avatar the user has.If the user does not have a traditional avatar,
Noneis returned. If you want the avatar that a user has displayed, considerdisplay_avatar.
- property avatar_decoration: Asset | None¶
Returns the user's avatar decoration, if available.
Added in version 2.5.
- property banner: Asset | None¶
Returns the user's banner asset, if available.
Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- property collectibles: Collectibles | None¶
Returns the user's equipped collectibles.
Added in version 2.8.
- property color: Colour¶
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.
- property colour: 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.
- await create_dm()[ソース]¶
This function is a coroutine.
Creates a
DMChannelwith this user.This should be rarely called, as this is done transparently for most people.
- 戻り値:
The channel that was created.
- 戻り値の型:
- property created_at: datetime¶
Returns the user's creation time in UTC.
This is when the user's Discord account was created.
- property default_avatar: Asset¶
Returns the default avatar for a given user. This is calculated by the user's ID if they're on the new username system, otherwise their discriminator.
- property display_avatar: Asset¶
Returns the user's display avatar.
Returns the user's uploaded avatar. If the user has not uploaded any avatar, their default avatar is returned instead.
Added in version 2.0.
- property display_name: str¶
Returns the user's display name. This will be their global name if set, otherwise their username.
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- property jump_url: str¶
Returns a URL that allows the client to jump to the user.
Added in version 2.0.
- mentioned_in(message)¶
Checks if the user is mentioned in the specified message.
- property nameplate: Nameplate | None¶
The user's nameplate, if the user has one equipped. Alias for
User.collectibles.nameplate.Added in version 2.7.
バージョン 2.8 で変更: Now an alias for
User.collectibles.nameplate.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- property public_flags: PublicUserFlags¶
The publicly available flags the user has.
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- await trigger_typing()¶
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 create_test_entitlement(sku)[ソース]¶
This function is a coroutine.
Creates a test entitlement for the user.
- パラメータ:
sku (
Snowflake) -- The SKU to create a test entitlement for.- 戻り値:
The created entitlement.
- 戻り値の型:
- entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)[ソース]¶
Returns an
AsyncIteratorthat enables fetching the user's entitlements.This is identical to
Client.entitlements()with theuserparameter.Added in version 2.6.
- パラメータ:
skus (
list[Snowflake] |None) -- Limit the fetched entitlements to entitlements that are for these SKUs.before (
Snowflake|datetime|None) -- Retrieves guilds before this date or object. 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 (
Snowflake|datetime|None) -- Retrieve guilds after this date or object. 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.limit (
int|None) -- The number of entitlements to retrieve. IfNone, retrieves every entitlement, which may be slow. Defaults to100.exclude_ended (
bool) -- Whether to limit the fetched entitlements to those that have not ended. Defaults toFalse.
- 列挙:
Entitlement-- The application's entitlements.- 例外:
HTTPException -- Retrieving the entitlements failed.
- 戻り値の型:
EntitlementIterator
- class discord.PrimaryGuild(data, state)[ソース]¶
Represents a Discord Primary Guild.
Added in version 2.7.
- x == y
Checks if two Primary Guilds are equal.
- x != y
Checks if two Primary Guilds are not equal.
バージョン 2.7.1 で変更: Primary Guilds are now comparable.
- パラメータ:
data (
PrimaryGuild)state (
ConnectionState)
Messages¶
- defis_spoiler
- asyncread
- asyncread_chunked
- asyncsave
- asyncto_file
- class discord.Attachment(*, data, state)[ソース]¶
Represents an attachment from Discord.
- str(x)
Returns the URL of the attachment.
- x == y
Checks if the attachment is equal to another attachment.
- x != y
Checks if the attachment is not equal to another attachment.
- hash(x)
Returns the attachment's unique identifier.
This is equivalent to
id.
バージョン 1.7 で変更: Attachment can now be cast to
strand is hashable.- height¶
The attachment's height, in pixels. Only applicable to images and videos.
- Type:
Optional[
int]
- title¶
The attachment's title. This is equal to the original
filename(without an extension) if special characters were filtered from it.Added in version 2.6.
- Type:
Optional[
str]
- url¶
The attachment URL. If the message this attachment was attached to is deleted, then this will 404.
- Type:
- proxy_url¶
The proxy URL. This is a cached version of the
urlin the case of images. When the message is deleted, this URL might be valid for a few minutes or not valid at all.- Type:
- content_type¶
The attachment's media type.
- Type:
Optional[
str]
- duration_secs¶
The duration of the audio file (currently for voice messages).
Added in version 2.5.
- Type:
Optional[
float]
- waveform¶
The base64 encoded bytearray representing a sampled waveform (currently for voice messages).
Added in version 2.5.
- Type:
Optional[
str]
- flags¶
Extra attributes of the attachment.
Added in version 2.5.
- Type:
- パラメータ:
data (
Attachment)state (
ConnectionState)
- await save(fp, *, seek_begin=True, use_cached=False, chunksize=None)[ソース]¶
This function is a coroutine.
Saves this attachment into a file-like object.
- パラメータ:
fp (
BufferedIOBase|PathLike) -- The file-like object to save this attachment to or the filename to use. If a filename is passed then a file is created with that filename and used instead.seek_begin (
bool) -- Whether to seek to the beginning of the file after saving is successfully done.use_cached (
bool) -- Whether to useproxy_urlrather thanurlwhen downloading the attachment. This will allow attachments to be saved after deletion more often, compared to the regular URL which is generally deleted right after the message is deleted. Note that this can still fail to download deleted attachments if too much time has passed, and it does not work on some types of attachments.chunksize (
int|None) -- The maximum size of each chunk to process. Must be a positive integer.
- 戻り値:
The number of bytes written.
- 戻り値の型:
- 例外:
HTTPException -- Saving the attachment failed.
NotFound -- The attachment was deleted.
InvalidArgument -- Argument chunksize is less than 1.
- await read(*, use_cached=False)[ソース]¶
This function is a coroutine.
Retrieves the content of this attachment as a
bytesobject.Added in version 1.1.
- パラメータ:
use_cached (
bool) -- Whether to useproxy_urlrather thanurlwhen downloading the attachment. This will allow attachments to be saved after deletion more often, compared to the regular URL which is generally deleted right after the message is deleted. Note that this can still fail to download deleted attachments if too much time has passed, and it does not work on some types of attachments.- 戻り値:
The contents of the attachment.
- 戻り値の型:
- 例外:
HTTPException -- Downloading the attachment failed.
Forbidden -- You do not have permissions to access this attachment
NotFound -- The attachment was deleted.
- await read_chunked(chunksize, *, use_cached=False)[ソース]¶
This function is a coroutine.
Retrieves the content of this attachment in chunks as a
AsyncGeneratorobject of bytes.- パラメータ:
chunksize (
int) -- The maximum size of each chunk to process. Must be a positive integer.use_cached (
bool) -- Whether to useproxy_urlrather thanurlwhen downloading the attachment. This will allow attachments to be saved after deletion more often, compared to the regular URL which is generally deleted right after the message is deleted. Note that this can still fail to download deleted attachments if too much time has passed, and it does not work on some types of attachments.
- 列挙:
bytes-- A chunk of the file.- 例外:
HTTPException -- Downloading the attachment failed.
Forbidden -- You do not have permissions to access this attachment
NotFound -- The attachment was deleted.
InvalidArgument -- Argument chunksize is less than 1.
- 戻り値の型:
- await to_file(*, use_cached=False, spoiler=False)[ソース]¶
This function is a coroutine.
Converts the attachment into a
Filesuitable for sending viaabc.Messageable.send().Added in version 1.3.
- パラメータ:
use_cached (
bool) --Whether to use
proxy_urlrather thanurlwhen downloading the attachment. This will allow attachments to be saved after deletion more often, compared to the regular URL which is generally deleted right after the message is deleted. Note that this can still fail to download deleted attachments if too much time has passed, and it does not work on some types of attachments.Added in version 1.4.
spoiler (
bool) --Whether the file is a spoiler.
Added in version 1.4.
- 戻り値:
The attachment as a file suitable for sending.
- 戻り値の型:
- 例外:
HTTPException -- Downloading the attachment failed.
Forbidden -- You do not have permissions to access this attachment
NotFound -- The attachment was deleted.
- activity
- application
- attachments
- author
- call
- channel
- channel_mentions
- clean_content
- components
- content
- created_at
- edited_at
- embeds
- flags
- guild
- id
- interaction
- interaction_metadata
- jump_url
- mention_everyone
- mentions
- nonce
- pinned
- poll
- raw_channel_mentions
- raw_mentions
- raw_role_mentions
- reactions
- reference
- role_mentions
- snapshots
- stickers
- system_content
- thread
- tts
- type
- webhook_id
- asyncadd_reaction
- asyncclear_reaction
- asyncclear_reactions
- asynccreate_thread
- asyncdelete
- asyncedit
- asyncend_poll
- asyncforward_to
- defget_component
- defis_system
- asyncpin
- asyncpublish
- asyncremove_reaction
- asyncreply
- defto_reference
- asyncunpin
- class discord.Message(*, state, channel, data)[ソース]¶
Represents a message from Discord.
- x == y
Checks if two messages are equal.
- x != y
Checks if two messages are not equal.
- hash(x)
Returns the message's hash.
- tts¶
Specifies if the message was done with text-to-speech. This can only be accurately received in
on_message()due to a discord limitation.- Type:
- type¶
The type of message. In most cases this should not be checked, but it is helpful in cases where it might be a system message for
system_content.- Type:
- author¶
A
Memberthat sent the message. Ifchannelis a private channel or the user has the left the guild, then it is aUserinstead.
- nonce¶
The value used by the discord guild and the client to verify that the message is successfully sent. This is not stored long term within Discord's servers and is only used ephemerally.
- channel¶
The
TextChannelorThreadthat the message was sent from. Could be aDMChannelorGroupChannelif it's a private message.- Type:
Union[
TextChannel,Thread,DMChannel,GroupChannel,PartialMessageable]
- reference¶
The message that this message references. This is only applicable to messages of type
MessageType.pins_add, crossposted messages created by a followed channel integration, or message replies.Added in version 1.5.
- Type:
Optional[
MessageReference]
- mention_everyone¶
Specifies if the message mentions everyone.
注釈
This does not check if the
@everyoneor the@heretext is in the message itself. Rather this boolean indicates if either the@everyoneor the@heretext is in the message and it did end up mentioning.- Type:
- mentions¶
A list of
Memberthat were mentioned. If the message is in a private message then the list will be ofUserinstead. For messages that are not of typeMessageType.default, this array can be used to aid in system messages. For more information, seesystem_content.警告
The order of the mentions list is not in any particular order, so you should not rely on it. This is a Discord limitation, not one with the library.
- Type:
List[
abc.User]
- channel_mentions¶
A list of
abc.GuildChannelthat were mentioned. If the message is in a private message then the list is always empty.- Type:
List[
abc.GuildChannel]
- role_mentions¶
A list of
Rolethat were mentioned. If the message is in a private message then the list is always empty.- Type:
List[
Role]
- webhook_id¶
If this message was sent by a webhook, then this is the webhook ID's that sent this message.
- Type:
Optional[
int]
- attachments¶
A list of attachments given to a message.
- Type:
List[
Attachment]
- flags¶
Extra features of the message.
Added in version 1.3.
- Type:
- reactions¶
Reactions to a message. Reactions can be either custom emoji or standard unicode emoji.
- Type:
List[
Reaction]
- activity¶
The activity associated with this message. Sent with Rich-Presence related messages that for example, request joining, spectating, or listening to or with another member.
It is a dictionary with the following optional keys:
type: An integer denoting the type of message activity being requested.party_id: The party ID associated with the party.
- Type:
Optional[
dict]
- application¶
The rich presence enabled application associated with this message.
It is a dictionary with the following keys:
id: A string representing the application's ID.name: A string representing the application's name.description: A string representing the application's description.icon: A string representing the icon ID of the application.cover_image: A string representing the embed's image asset ID.
- Type:
Optional[
dict]
- stickers¶
A list of sticker items given to the message.
Added in version 1.6.
- Type:
List[
StickerItem]
- interaction¶
The interaction associated with the message, if applicable.
バージョン 2.6 で非推奨: Use
interaction_metadatainstead.- Type:
Optional[
MessageInteraction]
- interaction_metadata¶
The interaction metadata associated with the message, if applicable.
Added in version 2.6.
- Type:
Optional[
InteractionMetadata]
- thread¶
The thread created from this message, if applicable.
Added in version 2.0.
- Type:
Optional[
Thread]
- poll¶
The poll associated with this message, if applicable.
Added in version 2.6.
- Type:
Optional[
Poll]
- call¶
The call information associated with this message, if applicable.
Added in version 2.6.
- Type:
Optional[
MessageCall]
- snapshots¶
The snapshots attached to this message, if applicable.
Added in version 2.7.
- Type:
Optional[List[
MessageSnapshot]]
- パラメータ:
state (
ConnectionState)channel (
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|PartialMessageable|GroupChannel)data (
Message)
- raw_mentions¶
A property that returns an array of user IDs matched with the syntax of
<@user_id>in the message content.This allows you to receive the user IDs of mentioned users even in a private message context.
- raw_channel_mentions¶
A property that returns an array of channel IDs matched with the syntax of
<#channel_id>in the message content.
- raw_role_mentions¶
A property that returns an array of role IDs matched with the syntax of
<@&role_id>in the message content.
- clean_content¶
A property that returns the content in a "cleaned up" manner. This basically means that mentions are transformed into the way the client shows it. e.g.
<#id>will transform into#name.This will also transform @everyone and @here mentions into non-mentions.
注釈
This does not affect markdown. If you want to escape or remove markdown then use
utils.escape_markdown()orutils.remove_markdown()respectively, along with this function.
- property edited_at: datetime | None¶
An aware UTC datetime object containing the edited time of the message.
- is_system()[ソース]¶
Whether the message is a system message.
A system message is a message that is constructed entirely by the Discord API in response to something.
Added in version 1.3.
- 戻り値の型:
- system_content¶
A property that returns the content that is rendered regardless of the
Message.type.In the case of
MessageType.defaultandMessageType.reply, this just returns the regularMessage.content, and forwarded messages will display the original message's content fromMessage.snapshots. Otherwise, this returns an English message denoting the contents of the system message.
- await delete(*, delay=None, reason=None)[ソース]¶
This function is a coroutine.
Deletes the message.
Your own messages could be deleted without any proper permissions. However, to delete other people's messages, you need the
manage_messagespermission.バージョン 1.1 で変更: Added the new
delaykeyword-only parameter.- パラメータ:
- 例外:
Forbidden -- You do not have proper permissions to delete the message.
NotFound -- The message was deleted already
HTTPException -- Deleting the message failed.
- 戻り値の型:
- await edit(content=..., embed=..., embeds=..., file=..., files=..., attachments=..., suppress=..., suppress_embeds=..., delete_after=None, allowed_mentions=..., view=...)[ソース]¶
This function is a coroutine.
Edits the message.
The content must be able to be transformed into a string via
str(content).バージョン 1.3 で変更: The
suppresskeyword-only parameter was added.- パラメータ:
content (
str|None) -- The new content to replace the message with. Could beNoneto remove the content.embed (
Embed|None) -- The new embed to replace the original with. Could beNoneto remove the embed.The new embeds to replace the original with. Must be a maximum of 10. To remove all embeds
[]should be passed.Added in version 2.0.
files (
list[Sequence[File]]) -- New files to add to the message.attachments (
list[Attachment]) -- A list of attachments to keep in the message. If[]is passed then all attachments are removed.suppress (
bool) --Whether to suppress embeds for the message. This removes all the embeds if set to
True. If set toFalsethis brings the embeds back if they were suppressed. Using this parameter requiresmanage_messages.バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message. This removes all the embeds if set to
True. If set toFalsethis brings the embeds back if they were suppressed. Using this parameter requiresmanage_messages.Added in version 2.8.
delete_after (
float|None) -- If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.allowed_mentions (
AllowedMentions|None) --Controls the mentions being processed in this message. If this is passed, then the object is merged with
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
view (
BaseView|None) -- The updated view to update this message with. IfNoneis passed then the view is removed.
- 例外:
NotFound -- The message was not found.
HTTPException -- Editing the message failed.
Forbidden -- Tried to suppress a message without permissions or edited a message's content or embed that isn't yours.
InvalidArgument -- You specified both
embedandembeds, specified bothfileandfiles, or either``file`` orfileswere of the wrong type.
- 戻り値の型:
- await publish()[ソース]¶
This function is a coroutine.
Publishes this message to your announcement channel.
You must have the
send_messagespermission to do this.If the message is not your own then the
manage_messagespermission is also needed.- 例外:
Forbidden -- You do not have the proper permissions to publish this message.
HTTPException -- Publishing the message failed.
- 戻り値の型:
- await pin(*, reason=None)[ソース]¶
This function is a coroutine.
Pins the message.
You must have the
pin_messagespermission to do this in a non-private channel context.- パラメータ:
The reason for pinning the message. Shows up on the audit log.
Added in version 1.4.
- 例外:
Forbidden -- You do not have permissions to pin the message.
NotFound -- The message or channel was not found or deleted.
HTTPException -- Pinning the message failed, probably due to the channel having more than 50 pinned messages.
- 戻り値の型:
- await unpin(*, reason=None)[ソース]¶
This function is a coroutine.
Unpins the message.
You must have the
pin_messagespermission to do this in a non-private channel context.- パラメータ:
The reason for unpinning the message. Shows up on the audit log.
Added in version 1.4.
- 例外:
Forbidden -- You do not have permissions to unpin the message.
NotFound -- The message or channel was not found or deleted.
HTTPException -- Unpinning the message failed.
- 戻り値の型:
- await add_reaction(emoji)[ソース]¶
This function is a coroutine.
Add a reaction to the message.
The emoji may be a unicode emoji, a custom
GuildEmoji, or anAppEmoji.You must have the
read_message_historypermission to use this. If nobody else has reacted to the message using this emoji, theadd_reactionspermission is required.- パラメータ:
emoji (
GuildEmoji|AppEmoji|PartialEmoji|str) -- The emoji to react with.- 例外:
HTTPException -- Adding the reaction failed.
Forbidden -- You do not have the proper permissions to react to the message.
NotFound -- The emoji you specified was not found.
InvalidArgument -- The emoji parameter is invalid.
- 戻り値の型:
- await remove_reaction(emoji, member)[ソース]¶
This function is a coroutine.
Remove a reaction by the member from the message.
The emoji may be a unicode emoji, a custom
GuildEmoji, or anAppEmoji.If the reaction is not your own (i.e.
memberparameter is not you) then themanage_messagespermission is needed.The
memberparameter must represent a member and meet theabc.Snowflakeabc.- パラメータ:
emoji (
GuildEmoji|AppEmoji|PartialEmoji|str|Reaction) -- The emoji to remove.member (
Snowflake) -- The member for which to remove the reaction.
- 例外:
HTTPException -- Removing the reaction failed.
Forbidden -- You do not have the proper permissions to remove the reaction.
NotFound -- The member or emoji you specified was not found.
InvalidArgument -- The emoji parameter is invalid.
- 戻り値の型:
- await clear_reaction(emoji)[ソース]¶
This function is a coroutine.
Clears a specific reaction from the message.
The emoji may be a unicode emoji, a custom
GuildEmoji, or anAppEmoji.You need the
manage_messagespermission to use this.Added in version 1.3.
- パラメータ:
emoji (
GuildEmoji|AppEmoji|PartialEmoji|str|Reaction) -- The emoji to clear.- 例外:
HTTPException -- Clearing the reaction failed.
Forbidden -- You do not have the proper permissions to clear the reaction.
NotFound -- The emoji you specified was not found.
InvalidArgument -- The emoji parameter is invalid.
- 戻り値の型:
- await clear_reactions()[ソース]¶
This function is a coroutine.
Removes all the reactions from the message.
You need the
manage_messagespermission to use this.- 例外:
HTTPException -- Removing the reactions failed.
Forbidden -- You do not have the proper permissions to remove all the reactions.
- 戻り値の型:
- await create_thread(*, name, auto_archive_duration=..., slowmode_delay=...)[ソース]¶
This function is a coroutine.
Creates a public thread from this message.
You must have
create_public_threadsin order to create a public thread from a message.The channel this message belongs in must be a
TextChannel.Added in version 2.0.
- パラメータ:
name (
str) -- The name of the thread.auto_archive_duration (
Literal[60,1440,4320,10080]) -- The duration in minutes before a thread is automatically archived for inactivity. If not provided, the channel's default auto archive duration is used.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this thread, in seconds. A value of0disables slowmode. The maximum value possible is21600.
- 戻り値:
The created thread.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to create a thread.
HTTPException -- Creating the thread failed.
InvalidArgument -- This message does not have guild info attached.
- await reply(content=None, **kwargs)[ソース]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()to reply to theMessage.Added in version 1.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, or you specified bothfileandfiles.
- パラメータ:
- await forward_to(channel, **kwargs)[ソース]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()to forward theMessageto a channel.Added in version 2.7.
- パラメータ:
channel (
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|PartialMessageable|GroupChannel) -- The channel to forward this to.- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, or you specified bothfileandfiles.
- await end_poll()[ソース]¶
This function is a coroutine.
Immediately ends the poll associated with this message. Only doable by the poll's owner.
Added in version 2.6.
- 戻り値:
The updated message.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to end this poll.
HTTPException -- Ending this poll failed.
- to_reference(*, fail_if_not_exists=True, type=None)[ソース]¶
Creates a
MessageReferencefrom the current message.Added in version 1.6.
- パラメータ:
fail_if_not_exists (
bool) --Whether replying using the message reference should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.Added in version 1.7.
type (
MessageReferenceType) --The type of message reference. Defaults to a reply.
Added in version 2.7.
- 戻り値:
The reference to this message.
- 戻り値の型:
- class discord.MessagePin(state, channel, data)[ソース]¶
Represents information about a pinned message.
Added in version 2.7.
- パラメータ:
state (
ConnectionState)channel (
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|PartialMessageable|GroupChannel)data (
MessagePin)
- class discord.MessageSnapshot(*, state, reference, data)[ソース]¶
Represents a message snapshot.
Added in version 2.7.
- message¶
The forwarded message, which includes a minimal subset of fields from the original message.
- Type:
- パラメータ:
state (
ConnectionState)reference (
MessageReference)data (
MessageSnapshot)
- class discord.ForwardedMessage(*, state, reference, data)[ソース]¶
Represents the snapshotted contents from a forwarded message. Forwarded messages are immutable; any updates to the original message will not be reflected.
Added in version 2.7.
- type¶
The type of the original message. In most cases this should not be checked, but it is helpful in cases where it might be a system message for
system_content.- Type:
- original_message¶
The original message that was forwarded, if available.
- Type:
Optional[Union[
Message,PartialMessage]]
- channel¶
The
TextChannelorThreadthat the original message was sent from.- Type:
Union[
TextChannel,Thread,DMChannel,GroupChannel,PartialMessageable]
- guild¶
The guild that the original message belonged to, if applicable.
- attachments¶
A list of attachments given to the original message.
- Type:
List[
Attachment]
- flags¶
Extra features of the original message.
- Type:
- mentions¶
A list of
Userthat were originally mentioned.注釈
This list will be empty if the message was forwarded to a different place, e.g., from a DM to a guild, or from one guild to another.
- Type:
List[
User]
- role_mentions¶
A list of
Rolethat were originally mentioned.警告
This is only available using
abc.Messageable.fetch_message().- Type:
List[
Role]
- stickers¶
A list of sticker items given to the original message.
- Type:
List[
StickerItem]
- パラメータ:
state (
ConnectionState)reference (
MessageReference)data (
ForwardedMessage)
- class discord.DeletedReferencedMessage(parent)[ソース]¶
A special sentinel type that denotes whether the resolved message referenced message had since been deleted.
The purpose of this class is to separate referenced messages that could not be fetched and those that were previously fetched but have since been deleted.
Added in version 1.6.
- パラメータ:
parent (
MessageReference)
- asyncclear
- defis_custom_emoji
- asyncremove
- defusers
- class discord.Reaction(*, message, data, emoji=None)[ソース]¶
Represents a reaction to a message.
Depending on the way this object was created, some of the attributes can have a value of
None.- x == y
Checks if two reactions are equal. This works by checking if the emoji is the same. So two messages with the same reaction will be considered "equal".
- x != y
Checks if two reactions are not equal.
- hash(x)
Returns the reaction's hash.
- str(x)
Returns the string form of the reaction's emoji.
- emoji¶
The reaction emoji. May be a custom emoji, or a unicode emoji.
- Type:
Union[
GuildEmoji,AppEmoji,PartialEmoji,str]
- パラメータ:
message (
Message)data (
Reaction)emoji (
PartialEmoji|GuildEmoji|AppEmoji|str|None)
- async for ... in users(*, limit=None, after=None, type=None)[ソース]¶
Returns an
AsyncIteratorrepresenting the users that have reacted to the message.The
afterparameter must represent a member and meet theabc.Snowflakeabc.- パラメータ:
- 列挙:
Union[
User,Member] -- The member (if retrievable) or the user that has reacted to this message. The case where it can be aMemberis in a guild message context. Sometimes it can be aUserif the member has left the guild.- 例外:
HTTPException -- Getting the users for the reaction failed.
- 戻り値の型:
ReactionIterator
サンプル
Usage
# I do not actually recommend doing this. async for user in reaction.users(): await channel.send(f'{user} has reacted with {reaction.emoji}!')
Flattening into a list:
users = await reaction.users().flatten() # users is now a list of User... winner = random.choice(users) await channel.send(f'{winner} has won the raffle.')
Getting super reactors:
users = await reaction.users(type=ReactionType.burst).flatten()
- property burst_colours: list[Colour]¶
Returns a list possible
Colourthis super reaction can be.There is an alias for this named
burst_colors.
- property burst_colors: list[Colour]¶
Returns a list possible
Colourthis super reaction can be.There is an alias for this named
burst_colours.
- property count_details¶
Returns
ReactionCountDetailsfor the individual counts of normal and super reactions made.
- await remove(user)[ソース]¶
This function is a coroutine.
Remove the reaction by the provided
Userfrom the message.If the reaction is not your own (i.e.
userparameter is not you) then themanage_messagespermission is needed.The
userparameter must represent a user or member and meet theabc.Snowflakeabc.- パラメータ:
user (
Snowflake) -- The user or member from which to remove the reaction.- 例外:
HTTPException -- Removing the reaction failed.
Forbidden -- You do not have the proper permissions to remove the reaction.
NotFound -- The user you specified, or the reaction's message was not found.
- 戻り値の型:
- await clear()[ソース]¶
This function is a coroutine.
Clears this reaction from the message.
You need the
manage_messagespermission to use this.Added in version 1.3.
- 例外:
HTTPException -- Clearing the reaction failed.
Forbidden -- You do not have the proper permissions to clear the reaction.
NotFound -- The emoji you specified was not found.
InvalidArgument -- The emoji parameter is invalid.
- 戻り値の型:
Monetization¶
- class discord.SKU(*, state, data)[ソース]¶
Represents a Discord SKU (stock-keeping unit).
Added in version 2.5.
- パラメータ:
state (
ConnectionState)data (
SKU)
- fetch_subscriptions(user, *, before=None, after=None, limit=100)[ソース]¶
Returns an
AsyncIteratorthat enables fetching the SKU's subscriptions.Added in version 2.7.
- パラメータ:
user (
Snowflake) -- The user for which to retrieve subscriptions.before (
Snowflake|datetime|None) -- Retrieves subscriptions before this date or object. 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 (
Snowflake|datetime|None) -- Retrieve subscriptions after this date or object. 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.limit (
int|None) -- The number of subscriptions to retrieve. IfNone, retrieves all subscriptions.
- 列挙:
Subscription-- A subscription that the user has for this SKU.- 例外:
HTTPException -- Getting the subscriptions failed.
- 戻り値の型:
SubscriptionIterator
サンプル
Usage
async for subscription in sku.fetch_subscriptions(discord.Object(id=123456789)): print(subscription.status)
Flattening into a list
subscriptions = await sku.fetch_subscriptions(discord.Object(id=123456789)).flatten() # subscriptions is now a list of Subscription...
All parameters except for
userare optional.
- class discord.Entitlement(*, data, state)[ソース]¶
Represents a Discord entitlement.
Added in version 2.5.
注釈
As of October 1, 2024, entitlements that have been purchased will have
ends_atset toNoneunless the parentSubscriptionhas been cancelled.- type¶
The type of entitlement.
- Type:
- starts_at¶
When the entitlement starts.
- Type:
Union[
datetime.datetime,MISSING]
- ends_at¶
When the entitlement expires.
- Type:
Union[
datetime.datetime,MISSING]
- consumed¶
Whether or not this entitlement has been consumed. This will always be
Falsefor entitlements that are not from an SKU of typeSKUType.consumable.- Type:
- パラメータ:
data (
Entitlement)state (
ConnectionState)
- await consume()[ソース]¶
This function is a coroutine.
Consumes this entitlement.
This can only be done on entitlements from an SKU of type
SKUType.consumable.- 例外:
HTTPException -- Consuming the entitlement failed.
- 戻り値の型:
- await delete()[ソース]¶
This function is a coroutine.
Deletes a test entitlement.
A test entitlement is an entitlement that was created using
Guild.create_test_entitlement()orUser.create_test_entitlement().- 例外:
HTTPException -- Deleting the entitlement failed.
- 戻り値の型:
- class discord.Subscription(*, state, data)[ソース]¶
Represents a user making recurring payments for one or more SKUs.
Successful payments grant the user access to entitlements associated with the SKU.
Added in version 2.7.
- renewal_sku_ids¶
The IDs of the SKUs that the buyer will be subscribed to at renewal.
- Type:
List[
int]
- current_period_start¶
The start of the current subscription period.
- Type:
- current_period_end¶
The end of the current subscription period.
- Type:
- status¶
The status of the subscription.
- Type:
- canceled_at¶
When the subscription was canceled.
- Type:
datetime.datetime|None
- パラメータ:
state (
ConnectionState)data (
Subscription)
Guild¶
- afk_channel
- afk_timeout
- approximate_member_count
- approximate_presence_count
- banner
- bitrate_limit
- categories
- channels
- chunked
- created_at
- default_notifications
- default_role
- description
- discovery_splash
- emoji_limit
- emojis
- explicit_content_filter
- features
- filesize_limit
- forum_channels
- icon
- id
- incidents_data
- invites_disabled
- jump_url
- large
- max_members
- max_presences
- max_video_channel_users
- me
- member_count
- members
- mfa_level
- name
- nsfw_level
- owner
- owner_id
- preferred_locale
- premium_progress_bar_enabled
- premium_subscriber_role
- premium_subscribers
- premium_subscription_count
- premium_tier
- public_updates_channel
- roles
- rules_channel
- scheduled_events
- self_role
- shard_id
- soundboard_limit
- sounds
- splash
- stage_channels
- stage_instances
- sticker_limit
- stickers
- system_channel
- system_channel_flags
- text_channels
- threads
- unavailable
- verification_level
- voice_channels
- voice_client
- asyncactive_threads
- defaudit_logs
- asyncban
- asyncbans
- asyncbulk_ban
- defby_category
- asyncchange_voice_state
- asyncchunk
- asynccreate_auto_moderation_rule
- asynccreate_category
- asynccreate_category_channel
- asynccreate_custom_emoji
- asynccreate_forum_channel
- asynccreate_integration
- asynccreate_role
- asynccreate_scheduled_event
- asynccreate_sound
- asynccreate_stage_channel
- asynccreate_sticker
- asynccreate_template
- asynccreate_test_entitlement
- asynccreate_text_channel
- asynccreate_voice_channel
- asyncdelete_auto_moderation_rule
- asyncdelete_emoji
- asyncdelete_sticker
- asyncedit
- asyncedit_onboarding
- asyncedit_role_positions
- asyncedit_welcome_screen
- asyncedit_widget
- defentitlements
- asyncestimate_pruned_members
- asyncfetch_auto_moderation_rule
- asyncfetch_auto_moderation_rules
- asyncfetch_ban
- asyncfetch_channel
- asyncfetch_channels
- asyncfetch_emoji
- asyncfetch_emojis
- asyncfetch_member
- deffetch_members
- asyncfetch_role
- asyncfetch_roles
- asyncfetch_roles_member_counts
- asyncfetch_scheduled_event
- asyncfetch_scheduled_events
- asyncfetch_sound
- asyncfetch_sounds
- asyncfetch_sticker
- asyncfetch_stickers
- defget_channel
- defget_channel_or_thread
- defget_emoji
- defget_member
- defget_member_named
- asyncget_or_fetch
- defget_role
- defget_scheduled_event
- defget_sound
- defget_stage_instance
- defget_thread
- asyncintegrations
- asyncinvites
- asynckick
- asyncleave
- asyncmodify_incident_actions
- asynconboarding
- asyncprune_members
- asyncquery_members
- asyncsearch_members
- asynctemplates
- asyncunban
- asyncvanity_invite
- asyncwebhooks
- asyncwelcome_screen
- asyncwidget
- class discord.Guild(*, data, state)[ソース]¶
Represents a Discord guild.
This is referred to as a "server" in the official Discord UI.
- x == y
Checks if two guilds are equal.
- x != y
Checks if two guilds are not equal.
- hash(x)
Returns the guild's hash.
- str(x)
Returns the guild's name.
- emojis¶
All emojis that the guild owns.
- Type:
Tuple[
GuildEmoji, ...]
- stickers¶
All stickers that the guild owns.
Added in version 2.0.
- Type:
Tuple[
GuildSticker, ...]
- afk_channel¶
The channel that denotes the AFK channel.
Noneif it doesn't exist.- Type:
Optional[
VoiceChannel]
- owner_id¶
The guild owner's ID. Use
Guild.ownerinstead.- Type:
Indicates if the guild is unavailable. If this is
Truethen the reliability of other attributes outside ofGuild.idis slim and they might all beNone. It is best to not do anything with the guild if it is unavailable.Check the
on_guild_unavailable()andon_guild_available()events.- Type:
- max_members¶
The maximum amount of members for the guild.
注釈
This attribute is only available via
Client.fetch_guild().- Type:
Optional[
int]
- max_video_channel_users¶
The maximum amount of users in a video channel.
Added in version 1.4.
- Type:
Optional[
int]
- mfa_level¶
Indicates the guild's two-factor authorisation level. If this value is 0 then the guild does not require 2FA for their administrative members. If the value is 1 then they do.
- Type:
- verification_level¶
The guild's verification level.
- Type:
- explicit_content_filter¶
The guild's explicit content filter.
- Type:
- default_notifications¶
The guild's notification settings.
- Type:
- features¶
A list of features that the guild has. The features that a guild can have are subject to arbitrary change by Discord. You can find a catalog of guild features here.
- Type:
List[
str]
The premium tier for this guild. Corresponds to "Nitro Server" in the official UI. The number goes from 0 to 3 inclusive.
- Type:
The number of "boosts" this guild currently has.
- Type:
Indicates if the guild has premium progress bar enabled.
Added in version 2.0.
- Type:
- preferred_locale¶
The preferred locale for the guild. Used when filtering Server Discovery results to a specific language.
- Type:
Optional[
str]
- approximate_member_count¶
The approximate number of members in the guild. This is
Noneunless the guild is obtained usingClient.fetch_guild()withwith_counts=True.Added in version 2.0.
- Type:
Optional[
int]
- approximate_presence_count¶
The approximate number of members currently active in the guild. This includes idle, dnd, online, and invisible members. Offline members are excluded. This is
Noneunless the guild is obtained usingClient.fetch_guild()withwith_counts=True.Added in version 2.0.
- Type:
Optional[
int]
- incidents_data¶
The incidents data for the guild.
Added in version 2.7.
- Type:
Optional[
IncidentsData]
- パラメータ:
data (
Guild)state (
ConnectionState)
- async for ... in fetch_members(*, limit=1000, after=None)[ソース]¶
Retrieves an
AsyncIteratorthat enables receiving the guild's members. In order to use this,Intents.members()must be enabled.注釈
This method is an API call. For general usage, consider
membersinstead.Added in version 1.3.
All parameters are optional.
- パラメータ:
limit (
int|None) -- The number of members to retrieve. Defaults to 1000. PassNoneto fetch all members. Note that this is potentially slow.after (
Snowflake|datetime|None) -- Retrieve members after this date or object. 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.
- 列挙:
Member-- The member with the member data parsed.- 例外:
ClientException -- The members intent is not enabled.
HTTPException -- Getting the members failed.
- 戻り値の型:
MemberIterator
サンプル
Usage
async for member in guild.fetch_members(limit=150): print(member.name)
Flattening into a list
members = await guild.fetch_members(limit=150).flatten() # members is now a list of Member...
- async for ... in audit_logs(*, limit=100, before=None, after=None, user=None, action=None)[ソース]¶
Returns an
AsyncIteratorthat enables receiving the guild's audit logs.You must have the
view_audit_logpermission to use this.See API documentation for more information about the before and after parameters.
- パラメータ:
limit (
int|None) -- The number of entries to retrieve. IfNoneretrieve all entries.before (
Snowflake|datetime|None) -- Retrieve entries before this date or entry. 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 (
Snowflake|datetime|None) -- Retrieve entries after this date or entry. 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.user (
Snowflake) -- The moderator to filter entries from.action (
AuditLogAction) -- The action to filter with.
- 列挙:
AuditLogEntry-- The audit log entry.- 例外:
Forbidden -- You are not allowed to fetch audit logs
HTTPException -- An error occurred while fetching the audit logs.
- 戻り値の型:
AuditLogIterator
サンプル
Getting the first 100 entries:
async for entry in guild.audit_logs(limit=100): print(f'{entry.user} did {entry.action} to {entry.target}')
Getting entries for a specific action:
async for entry in guild.audit_logs(action=discord.AuditLogAction.ban): print(f'{entry.user} banned {entry.target}')
Getting entries made by a specific user:
entries = await guild.audit_logs(limit=None, user=guild.me).flatten() await channel.send(f'I made {len(entries)} moderation actions.')
- await fetch_sounds()[ソース]¶
This function is a coroutine. Fetches all the soundboard sounds in the guild.
Added in version 2.7.
- 戻り値:
The sounds in the guild.
- 戻り値の型:
- await fetch_sound(sound_id)[ソース]¶
This function is a coroutine. Fetches a soundboard sound in the guild.
Added in version 2.7.
- パラメータ:
sound_id (
int) -- The ID of the sound.- 戻り値:
The sound.
- 戻り値の型:
- await create_sound(name, sound, volume=1.0, emoji=None, reason=None)[ソース]¶
This function is a coroutine. Creates a
SoundboardSoundin the guild. You must havePermissions.manage_expressionspermission to use this.Added in version 2.7.
- パラメータ:
name (
str) -- The name of the sound.sound (
bytes) -- The bytes-like object representing the sound data. Only MP3 sound files that are less than 5.2 seconds long are supported.volume (
float) -- The volume of the sound. Defaults to 1.0.emoji (
PartialEmoji|GuildEmoji|str|None) -- The emoji of the sound.reason (
str|None) -- The reason for creating this sound. Shows up on the audit log.
- 戻り値:
The created sound.
- 戻り値の型:
- 例外:
HTTPException -- Creating the sound failed.
Forbidden -- You do not have permissions to create sounds.
- property channels: list[VoiceChannel | StageChannel | TextChannel | ForumChannel | CategoryChannel]¶
A list of channels that belong to this guild.
- property threads: list[Thread]¶
A list of threads that you have permission to view.
Added in version 2.0.
- property jump_url: str¶
Returns a URL that allows the client to jump to the guild.
Added in version 2.0.
- property large: bool¶
Indicates if the guild is a 'large' guild.
A large guild is defined as having more than
large_thresholdcount members, which for this library is set to the maximum of 250.
- property voice_channels: list[VoiceChannel]¶
A list of voice channels that belong to this guild.
This is sorted by the position and are in UI order from top to bottom.
- property stage_channels: list[StageChannel]¶
A list of stage channels that belong to this guild.
Added in version 1.7.
This is sorted by the position and are in UI order from top to bottom.
- property forum_channels: list[ForumChannel]¶
A list of forum channels that belong to this guild.
Added in version 2.0.
This is sorted by the position and are in UI order from top to bottom.
- property me: Member¶
Similar to
Client.userexcept an instance ofMember. This is essentially used to get the member version of yourself.
- property voice_client: VoiceClient | None¶
Returns the
VoiceClientassociated with this guild, if any.
- property text_channels: list[TextChannel]¶
A list of text channels that belong to this guild.
This is sorted by the position and are in UI order from top to bottom.
- property categories: list[CategoryChannel]¶
A list of categories that belong to this guild.
This is sorted by the position and are in UI order from top to bottom.
- property sounds: list[SoundboardSound]¶
A list of soundboard sounds that belong to this guild.
Added in version 2.7.
This is sorted by the position and are in UI order from top to bottom.
- by_category()[ソース]¶
Returns every
CategoryChanneland their associated channels.These channels and categories are sorted in the official Discord UI order.
If the channels do not have a category, then the first element of the tuple is
None.- 戻り値:
The categories and their associated channels.
- 戻り値の型:
list[Tuple[CategoryChannel|None,List[VoiceChannel|StageChannel|TextChannel|ForumChannel|CategoryChannel]]]
- get_channel_or_thread(channel_id, /)[ソース]¶
Returns a channel or thread with the given ID.
Added in version 2.0.
- パラメータ:
channel_id (
int) -- The ID to search for.- 戻り値:
The returned channel or thread or
Noneif not found.- 戻り値の型:
Thread|VoiceChannel|StageChannel|TextChannel|ForumChannel|CategoryChannel|None
- get_channel(channel_id, /)[ソース]¶
Returns a channel with the given ID.
注釈
This does not search for threads.
- パラメータ:
channel_id (
int) -- The ID to search for.- 戻り値:
The returned channel or
Noneif not found.- 戻り値の型:
VoiceChannel|StageChannel|TextChannel|ForumChannel|CategoryChannel|None
- property system_channel: TextChannel | None¶
Returns the guild's channel used for system messages.
If no channel is set, then this returns
None.
- property system_channel_flags: SystemChannelFlags¶
Returns the guild's system channel settings.
- property rules_channel: TextChannel | None¶
Return's the guild's channel used for the rules. The guild must be a Community guild.
If no channel is set, then this returns
None.Added in version 1.3.
- property public_updates_channel: TextChannel | None¶
Return's the guild's channel where admins and moderators of the guilds receive notices from Discord. The guild must be a Community guild.
If no channel is set, then this returns
None.Added in version 1.4.
- property sticker_limit: int¶
The maximum number of sticker slots this guild has.
Added in version 2.0.
- property soundboard_limit: int¶
The maximum number of soundboard slots this guild has.
Added in version 2.7.
- property filesize_limit: int¶
The maximum number of bytes files can have when uploaded to this guild.
- await get_or_fetch(object_type, object_id, default=None)[ソース]¶
Shortcut method to get data from this guild either by returning the cached version, or if it does not exist, attempting to fetch it from the API.
- パラメータ:
object_type (
type[TypeVar(_FETCHABLE, bound= VoiceChannel | TextChannel | ForumChannel | StageChannel | CategoryChannel | Thread | Member | User | Guild | Role | GuildEmoji | AppEmoji)]) -- Type of object to fetch or get.object_id (
int|None) -- ID of the object to get. IfNone, returns default if provided, otherwiseNone.default (
TypeVar(_D)) -- The value to return instead of raising if fetching fails or if object_id isNone.self (
Guild)
- 戻り値:
The object if found, or default if provided when not found.
- 戻り値の型:
TypeVar(_FETCHABLE, bound= VoiceChannel | TextChannel | ForumChannel | StageChannel | CategoryChannel | Thread | Member | User | Guild | Role | GuildEmoji | AppEmoji) |TypeVar(_D) |None- 例外:
TypeError -- Raised when required parameters are missing or invalid types are provided.
InvalidArgument -- Raised when an unsupported or incompatible object type is used.
A list of members who have "boosted" this guild.
- property roles: list[Role]¶
Returns a
listof the guild's roles in hierarchy order.The first element of this list will be the lowest role in the hierarchy.
- await fetch_roles_member_counts()[ソース]¶
This function is a coroutine. Fetches a mapping of role IDs to their member counts for this guild.
Added in version 2.7.
- 戻り値:
A mapping of role IDs to their member counts. Can be accessed with either role IDs (
int) or Snowflake objects (e.g.,Role).- 戻り値の型:
- 例外:
HTTPException -- Fetching the role member counts failed.
サンプル
Getting member counts using role IDs:
counts = await guild.fetch_roles_member_counts() member_count = counts[123456789]
Using a role object:
counts = await guild.fetch_roles_member_counts() role = guild.get_role(123456789) member_count = counts[role]
Gets the premium subscriber role, AKA "boost" role, in this guild.
Added in version 1.6.
- property self_role: Role | None¶
Gets the role associated with this client's user, if any.
Added in version 1.6.
- property stage_instances: list[StageInstance]¶
Returns a
listof the guild's stage instances that are currently running.Added in version 2.0.
- get_stage_instance(stage_instance_id, /)[ソース]¶
Returns a stage instance with the given ID.
Added in version 2.0.
- パラメータ:
stage_instance_id (
int) -- The ID to search for.- 戻り値:
The stage instance or
Noneif not found.- 戻り値の型:
- property member_count: int¶
Returns the true member count regardless of it being loaded fully or not.
警告
Due to a Discord limitation, in order for this attribute to remain up-to-date and accurate, it requires
Intents.membersto be specified.
- property chunked: bool¶
Returns a boolean indicating if the guild is "chunked".
A chunked guild means that
member_countis equal to the number of members stored in the internalmemberscache.If this value returns
False, then you should request for offline members.
- get_member_named(name, /)[ソース]¶
Returns the first member found that matches the name provided.
The name can have an optional discriminator argument, e.g. "Jake#0001" or "Jake" will both do the lookup. However, the former will give a more precise result. Note that the discriminator must have all 4 digits for this to work.
If a nickname is passed, then it is looked up via the nickname. Note however, that a nickname + discriminator combo will not look up the nickname but rather the username + discriminator combo due to nickname + discriminator not being unique.
If no member is found,
Noneis returned.
- await create_text_channel(name, *, reason=None, category=None, position=..., topic=..., slowmode_delay=..., nsfw=..., overwrites=..., default_thread_slowmode_delay=..., default_auto_archive_duration=...)[ソース]¶
This function is a coroutine.
Creates a
TextChannelfor the guild.Note that you need the
manage_channelspermission to create the channel.The
overwritesparameter can be used to create a 'secret' channel upon creation. This parameter expects adictof overwrites with the target (either aMemberor aRole) as the key and aPermissionOverwriteas the value.注釈
Creating a channel of a specified position will not update the position of other channels to follow suit. A follow-up call to
edit()will be required to update the position of the channel in the channel list.- パラメータ:
name (
str) -- The channel's name.overwrites (
dict[Role|Member,PermissionOverwrite]) -- The overwrites to apply to the channel. Useful for creating secret channels.category (
CategoryChannel|None) -- The category to place the newly created channel under. The permissions will be automatically synced to category if no overwrites are provided.position (
int) -- The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0.topic (
str) -- The new channel's topic.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this channel, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.nsfw (
bool) -- Whether the channel is marked as NSFW.reason (
str|None) -- The reason for creating this channel. Shows up on the audit log.default_thread_slowmode_delay (
int|None) --The initial slowmode delay to set on newly created threads in this channel.
Added in version 2.7.
default_auto_archive_duration (
int) --The default auto archive duration in minutes for threads created in this channel.
Added in version 2.7.
- 戻り値:
The channel that was just created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
InvalidArgument -- The permission overwrite information is not in proper form.
サンプル
Creating a basic channel:
channel = await guild.create_text_channel('cool-channel')
Creating a "secret" channel:
overwrites = { guild.default_role: discord.PermissionOverwrite(read_messages=False), guild.me: discord.PermissionOverwrite(read_messages=True) } channel = await guild.create_text_channel('secret', overwrites=overwrites)
- await create_voice_channel(name, *, reason=None, category=None, position=..., bitrate=..., user_limit=..., rtc_region=..., video_quality_mode=..., overwrites=..., slowmode_delay=..., nsfw=...)[ソース]¶
This function is a coroutine.
This is similar to
create_text_channel()except makes aVoiceChannelinstead.- パラメータ:
name (
str) -- The channel's name.overwrites (
dict[Role|Member,PermissionOverwrite]) -- The overwrites to apply to the channel. Useful for creating secret channels.category (
CategoryChannel|None) -- The category to place the newly created channel under. The permissions will be automatically synced to category if no overwrites are provided.position (
int) -- The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0.bitrate (
int) -- The channel's preferred audio bitrate in bits per second.user_limit (
int) -- The channel's limit for number of members that can be in a voice channel.rtc_region (
VoiceRegion|None) --The region for the voice channel's voice communication. A value of
Noneindicates automatic voice region detection.Added in version 1.7.
video_quality_mode (
VideoQualityMode) --The camera video quality for the voice channel's participants.
Added in version 2.0.
reason (
str|None) -- The reason for creating this channel. Shows up on the audit log.slowmode_delay (
int) --Specifies the slowmode rate limit for user in this channel, in seconds. A value of
0disables slowmode. The maximum value possible is21600.Added in version 2.7.
nsfw (
bool) --Whether the channel is marked as NSFW.
Added in version 2.7.
- 戻り値:
The channel that was just created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
InvalidArgument -- The permission overwrite information is not in proper form.
- await create_stage_channel(name, *, topic, position=..., overwrites=..., category=None, reason=None, bitrate=..., user_limit=..., rtc_region=..., video_quality_mode=..., slowmode_delay=..., nsfw=...)[ソース]¶
This function is a coroutine.
This is similar to
create_text_channel()except makes aStageChannelinstead.Added in version 1.7.
- パラメータ:
name (
str) -- The channel's name.topic (
str) -- The new channel's topic.overwrites (
dict[Role|Member,PermissionOverwrite]) -- The overwrites to apply to the channel. Useful for creating secret channels.category (
CategoryChannel|None) -- The category to place the newly created channel under. The permissions will be automatically synced to category if no overwrites are provided.position (
int) -- The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0.reason (
str|None) -- The reason for creating this channel. Shows up on the audit log.bitrate (
int) --The channel's preferred audio bitrate in bits per second.
Added in version 2.7.
user_limit (
int) --The channel's limit for number of members that can be in a voice channel.
Added in version 2.7.
rtc_region (
VoiceRegion|None) --The region for the voice channel's voice communication. A value of
Noneindicates automatic voice region detection.Added in version 2.7.
video_quality_mode (
VideoQualityMode) --The camera video quality for the voice channel's participants.
Added in version 2.7.
slowmode_delay (
int) --Specifies the slowmode rate limit for user in this channel, in seconds. A value of
0disables slowmode. The maximum value possible is21600.Added in version 2.7.
nsfw (
bool) --Whether the channel is marked as NSFW.
Added in version 2.7.
- 戻り値:
The channel that was just created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
InvalidArgument -- The permission overwrite information is not in proper form.
- await create_forum_channel(name, *, reason=None, category=None, position=..., topic=..., slowmode_delay=..., nsfw=..., overwrites=..., default_reaction_emoji=..., available_tags=..., default_sort_order=..., default_thread_slowmode_delay=..., default_auto_archive_duration=...)[ソース]¶
This function is a coroutine.
Creates a
ForumChannelfor the guild.Note that you need the
manage_channelspermission to create the channel.The
overwritesparameter can be used to create a 'secret' channel upon creation. This parameter expects adictof overwrites with the target (either aMemberor aRole) as the key and aPermissionOverwriteas the value.注釈
Creating a channel of a specified position will not update the position of other channels to follow suit. A follow-up call to
edit()will be required to update the position of the channel in the channel list.- パラメータ:
name (
str) -- The channel's name.overwrites (
dict[Role|Member,PermissionOverwrite]) -- The overwrites to apply to the channel. Useful for creating secret channels.category (
CategoryChannel|None) -- The category to place the newly created channel under. The permissions will be automatically synced to category if no overwrites are provided.position (
int) -- The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0.topic (
str) -- The new channel's topic.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this channel, in seconds. A value of0disables slowmode. The maximum value possible is21600.nsfw (
bool) -- Whether the channel is marked as NSFW.reason (
str|None) -- The reason for creating this channel. Shows up on the audit log.default_reaction_emoji (
GuildEmoji|int|str) --The default reaction emoji. Can be a unicode emoji or a custom emoji in the forms:
GuildEmoji, snowflake ID, string representation (eg. '<a:emoji_name:emoji_id>').Added in version v2.5.
available_tags (
list[ForumTag]) --The set of tags that can be used in a forum channel.
Added in version 2.7.
default_sort_order (
SortOrder|None) --The default sort order type used to order posts in this channel.
Added in version 2.7.
default_thread_slowmode_delay (
int|None) --The initial slowmode delay to set on newly created threads in this channel.
Added in version 2.7.
default_auto_archive_duration (
int) --The default auto archive duration in minutes for threads created in this channel.
Added in version 2.7.
- 戻り値:
The channel that was just created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
InvalidArgument -- The argument is not in proper form.
サンプル
Creating a basic channel:
channel = await guild.create_forum_channel('cool-channel')
Creating a "secret" channel:
overwrites = { guild.default_role: discord.PermissionOverwrite(read_messages=False), guild.me: discord.PermissionOverwrite(read_messages=True) } channel = await guild.create_forum_channel('secret', overwrites=overwrites)
- await create_category(name, *, overwrites=..., reason=None, position=...)[ソース]¶
This function is a coroutine.
Same as
create_text_channel()except makes aCategoryChannelinstead.注釈
The
categoryparameter is not supported in this function since categories cannot have categories.- 戻り値:
The channel that was just created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
InvalidArgument -- The permission overwrite information is not in proper form.
- パラメータ:
- await create_category_channel(name, *, overwrites=..., reason=None, position=...)¶
This function is a coroutine.
Same as
create_text_channel()except makes aCategoryChannelinstead.注釈
The
categoryparameter is not supported in this function since categories cannot have categories.- 戻り値:
The channel that was just created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
InvalidArgument -- The permission overwrite information is not in proper form.
- パラメータ:
- await leave()[ソース]¶
This function is a coroutine.
Leaves the guild.
注釈
You cannot leave the guild that you own, you must delete it instead via
delete().- 例外:
HTTPException -- Leaving the guild failed.
- 戻り値の型:
- await edit(*, reason=..., name=..., description=..., icon=..., banner=..., splash=..., discovery_splash=..., community=..., afk_channel=..., afk_timeout=..., default_notifications=..., verification_level=..., explicit_content_filter=..., system_channel=..., system_channel_flags=..., preferred_locale=..., rules_channel=..., public_updates_channel=..., premium_progress_bar_enabled=..., disable_invites=..., discoverable=..., disable_raid_alerts=..., enable_activity_feed=...)[ソース]¶
This function is a coroutine.
Edits the guild.
You must have the
manage_guildpermission to edit the guild.バージョン 1.4 で変更: The rules_channel and public_updates_channel keyword-only parameters were added.
バージョン 2.0 で変更: The discovery_splash and community keyword-only parameters were added.
バージョン 2.0 で変更: The newly updated guild is returned.
- パラメータ:
name (
str) -- The new name of the guild.description (
str|None) -- The new description of the guild. Could beNonefor no description. This is only available to guilds that containPUBLICinGuild.features.icon (
bytes|None) -- A bytes-like object representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that containANIMATED_ICONinGuild.features. Could beNoneto denote removal of the icon.banner (
bytes|None) -- A bytes-like object representing the banner. Could beNoneto denote removal of the banner. This is only available to guilds that containBANNERinGuild.features.splash (
bytes|None) -- A bytes-like object representing the invite splash. Only PNG/JPEG supported. Could beNoneto denote removing the splash. This is only available to guilds that containINVITE_SPLASHinGuild.features.discovery_splash (
bytes|None) -- A bytes-like object representing the discovery splash. Only PNG/JPEG supported. Could beNoneto denote removing the splash. This is only available to guilds that containDISCOVERABLEinGuild.features.community (
bool) -- Whether the guild should be a Community guild. If set toTrue, bothrules_channelandpublic_updates_channelparameters are required.afk_channel (
VoiceChannel|None) -- The new channel that is the AFK channel. Could beNonefor no AFK channel.afk_timeout (
int) -- The number of seconds until someone is moved to the AFK channel.verification_level (
VerificationLevel) -- The new verification level for the guild.default_notifications (
NotificationLevel) -- The new default notification level for the guild.explicit_content_filter (
ContentFilter) -- The new explicit content filter for the guild.system_channel (
TextChannel|None) -- The new channel that is used for the system channel. Could beNonefor no system channel.system_channel_flags (
SystemChannelFlags) -- The new system channel settings to use with the new system channel.preferred_locale (
str) -- The new preferred locale for the guild. Used as the primary language in the guild. If set, this must be an ISO 639 code, e.g.en-USorjaorzh-CN.rules_channel (
TextChannel|None) -- The new channel that is used for rules. This is only available to guilds that containPUBLICinGuild.features. Could beNonefor no rules channel.public_updates_channel (
TextChannel|None) -- The new channel that is used for public updates from Discord. This is only available to guilds that containPUBLICinGuild.features. Could beNonefor no public updates channel.premium_progress_bar_enabled (
bool) -- Whether the guild should have premium progress bar enabled.disable_invites (
bool) -- Whether the guild should have server invites enabled or disabled.discoverable (
bool) -- Whether the guild should be discoverable in the discover tab.disable_raid_alerts (
bool) -- Whether activity alerts for the guild should be disabled.enable_activity_feed (
bool) -- Whether the guild's user activity feed should be enabled.reason (
str|None) -- The reason for editing this guild. Shows up on the audit log.
- 例外:
Forbidden -- You do not have permissions to edit the guild.
HTTPException -- Editing the guild failed.
InvalidArgument -- The image format passed in to
iconis invalid. It must be PNG or JPG.
- 戻り値:
The newly updated guild. Note that this has the same limitations as mentioned in
Client.fetch_guild()and may not have full data.- 戻り値の型:
- await fetch_channels()[ソース]¶
This function is a coroutine.
Retrieves all
abc.GuildChannelthat the guild has.注釈
This method is an API call. For general usage, consider
channelsinstead.Added in version 1.2.
- 戻り値:
All channels in the guild.
- 戻り値の型:
Sequence[VoiceChannel|StageChannel|TextChannel|ForumChannel|CategoryChannel]- 例外:
InvalidData -- An unknown channel type was received from Discord.
HTTPException -- Retrieving the channels failed.
- await active_threads()[ソース]¶
This function is a coroutine.
Returns a list of active
Threadthat the client can access.This includes both private and public threads.
Added in version 2.0.
- 戻り値:
The active threads
- 戻り値の型:
- 例外:
HTTPException -- The request to get the active threads failed.
- await search_members(query, *, limit=1000)[ソース]¶
Search for guild members whose usernames or nicknames start with the query string. Unlike
fetch_members(), this does not requireIntents.members().注釈
This method is an API call. For general usage, consider filtering
membersinstead.Added in version 2.6.
- パラメータ:
- 戻り値:
The list of members that have matched the query.
- 戻り値の型:
- 例外:
HTTPException -- Getting the members failed.
- await fetch_member(member_id, /)[ソース]¶
This function is a coroutine.
Retrieves a
Memberfrom a guild ID, and a member ID.注釈
This method is an API call. If you have
Intents.membersand member cache enabled, considerget_member()instead.- パラメータ:
member_id (
int) -- The member's ID to fetch from.- 戻り値:
The member from the member ID.
- 戻り値の型:
- 例外:
Forbidden -- You do not have access to the guild.
HTTPException -- Fetching the member failed.
- await fetch_ban(user)[ソース]¶
This function is a coroutine.
Retrieves the
BanEntryfor a user.You must have the
ban_memberspermission to get this information.- パラメータ:
user (
Snowflake) -- The user to get ban information from.- 戻り値:
The
BanEntryobject for the specified user.- 戻り値の型:
BanEntry- 例外:
Forbidden -- You do not have proper permissions to get the information.
NotFound -- This user is not banned.
HTTPException -- An error occurred while fetching the information.
- await fetch_channel(channel_id, /)[ソース]¶
This function is a coroutine.
Retrieves a
abc.GuildChannelorThreadwith the specified ID.注釈
This method is an API call. For general usage, consider
get_channel_or_thread()instead.Added in version 2.0.
- 戻り値:
The channel from the ID.
- 戻り値の型:
VoiceChannel|StageChannel|TextChannel|ForumChannel|CategoryChannel|Thread- 例外:
InvalidData -- An unknown channel type was received from Discord or the guild the channel belongs to is not the same as the one in this object points to.
HTTPException -- Retrieving the channel failed.
NotFound -- Invalid Channel ID.
Forbidden -- You do not have permission to fetch this channel.
- パラメータ:
channel_id (
int)
- bans(limit=None, before=None, after=None)[ソース]¶
This function is a coroutine.
Retrieves an
AsyncIteratorthat enables receiving the guild's bans. In order to use this, you must have theban_memberspermission. Users will always be returned in ascending order sorted by user ID. If both thebeforeandafterparameters are provided, only before is respected.バージョン 2.5 で変更: The
before. andafterparameters were changed. They are now of the typeabc.Snowflakeinstead of SnowflakeTime to comply with the discord api.バージョン 2.0 で変更: The
limit,before. andafterparameters were added. Now returns aBanIteratorinstead of a list ofBanEntryobjects.All parameters are optional.
- パラメータ:
- 列挙:
BanEntry-- The ban entry for the ban.- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- 戻り値の型:
BanIterator
サンプル
Usage
async for ban in guild.bans(limit=150): print(ban.user.name)
Flattening into a list
bans = await guild.bans(limit=150).flatten() # bans is now a list of BanEntry...
- await prune_members(*, days, compute_prune_count=True, roles=..., reason=None)[ソース]¶
This function is a coroutine.
Prunes the guild from its inactive members.
The inactive members are denoted if they have not logged on in
daysnumber of days and have no roles.You must have the
kick_memberspermission to use this.To check how many members you would prune without actually pruning, see the
estimate_pruned_members()function.To prune members that have specific roles see the
rolesparameter.バージョン 1.4 で変更: The
roleskeyword-only parameter was added.- パラメータ:
days (
int) -- The number of days before counting as inactive.reason (
str|None) -- The reason for doing this action. Shows up on the audit log.compute_prune_count (
bool) -- Whether to compute the prune count. This defaults toTruewhich makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this toFalse. If this is set toFalse, then this function will always returnNone.roles (
list[Snowflake]) -- A list ofabc.Snowflakethat represent roles to include in the pruning process. If a member has a role that is not specified, they'll be excluded.
- 例外:
Forbidden -- You do not have permissions to prune members.
HTTPException -- An error occurred while pruning members.
InvalidArgument -- An integer was not passed for
days.
- 戻り値:
The number of members pruned. If
compute_prune_countisFalsethen this returnsNone.- 戻り値の型:
- await templates()[ソース]¶
This function is a coroutine.
Gets the list of templates from this guild.
Requires
manage_guildpermissions.Added in version 1.7.
- await webhooks()[ソース]¶
This function is a coroutine.
Gets the list of webhooks from this guild.
Requires
manage_webhookspermissions.
- await estimate_pruned_members(*, days, roles=...)[ソース]¶
This function is a coroutine.
Similar to
prune_members()except instead of actually pruning members, it returns how many members it would prune from the guild had it been called.- パラメータ:
days (
int) -- The number of days before counting as inactive.A list of
abc.Snowflakethat represent roles to include in the estimate. If a member has a role that is not specified, they'll be excluded.Added in version 1.7.
- 戻り値:
The number of members estimated to be pruned.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to prune members.
HTTPException -- An error occurred while fetching the prune members estimate.
InvalidArgument -- An integer was not passed for
days.
- await invites()[ソース]¶
This function is a coroutine.
Returns a list of all active instant invites from the guild.
You must have the
manage_guildpermission to get this information.- 戻り値:
The list of invites that are currently active.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- await create_template(*, name, description=...)[ソース]¶
This function is a coroutine.
Creates a template for the guild.
You must have the
manage_guildpermission to do this.Added in version 1.7.
- await create_integration(*, type, id)[ソース]¶
This function is a coroutine.
Attaches an integration to the guild.
You must have the
manage_guildpermission to do this.Added in version 1.4.
- パラメータ:
- 例外:
Forbidden -- You do not have permission to create the integration.
HTTPException -- The account could not be found.
- 戻り値の型:
- await integrations()[ソース]¶
This function is a coroutine.
Returns a list of all integrations attached to the guild.
You must have the
manage_guildpermission to do this.Added in version 1.4.
- 戻り値:
The list of integrations that are attached to the guild.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permission to create the integration.
HTTPException -- Fetching the integrations failed.
- await fetch_stickers()[ソース]¶
This function is a coroutine.
Retrieves a list of all
Stickers for the guild.Added in version 2.0.
注釈
This method is an API call. For general usage, consider
stickersinstead.- 例外:
HTTPException -- An error occurred fetching the stickers.
- 戻り値:
The retrieved stickers.
- 戻り値の型:
- await fetch_sticker(sticker_id, /)[ソース]¶
This function is a coroutine.
Retrieves a custom
Stickerfrom the guild.Added in version 2.0.
注釈
This method is an API call. For general usage, consider iterating over
stickersinstead.- パラメータ:
sticker_id (
int) -- The sticker's ID.- 戻り値:
The retrieved sticker.
- 戻り値の型:
- 例外:
NotFound -- The sticker requested could not be found.
HTTPException -- An error occurred fetching the sticker.
- await create_sticker(*, name, description=None, emoji, file, reason=None)[ソース]¶
This function is a coroutine.
Creates a
Stickerfor the guild.You must have
manage_emojis_and_stickerspermission to do this.Added in version 2.0.
- パラメータ:
name (
str) -- The sticker name. Must be 2 to 30 characters.description (
str|None) -- The sticker's description. If used, must be 2 to 100 characters.emoji (
str) -- The name of a unicode emoji that represents the sticker's expression.file (
File) -- The file of the sticker to upload.reason (
str|None) -- The reason for creating this sticker. Shows up on the audit log.
- 戻り値:
The created sticker.
- 戻り値の型:
- 例外:
Forbidden -- You are not allowed to create stickers.
HTTPException -- An error occurred creating a sticker.
TypeError -- The parameters for the sticker are not correctly formatted.
- await delete_sticker(sticker, *, reason=None)[ソース]¶
This function is a coroutine.
Deletes the custom
Stickerfrom the guild.You must have
manage_emojis_and_stickerspermission to do this.Added in version 2.0.
- get_emoji(emoji_id, /)[ソース]¶
Returns an emoji with the given ID.
Added in version 2.7.
- パラメータ:
emoji_id (
int) -- The ID to get.- 戻り値:
The returned Emoji or
Noneif not found.- 戻り値の型:
- await fetch_emojis()[ソース]¶
This function is a coroutine.
Retrieves all custom
GuildEmojis from the guild.注釈
This method is an API call. For general usage, consider
emojisinstead.- 例外:
HTTPException -- An error occurred fetching the emojis.
- 戻り値:
The retrieved emojis.
- 戻り値の型:
- await fetch_emoji(emoji_id, /)[ソース]¶
This function is a coroutine.
Retrieves a custom
GuildEmojifrom the guild.注釈
This method is an API call. For general usage, consider iterating over
emojisinstead.- パラメータ:
emoji_id (
int) -- The emoji's ID.- 戻り値:
The retrieved emoji.
- 戻り値の型:
- 例外:
NotFound -- The emoji requested could not be found.
HTTPException -- An error occurred fetching the emoji.
- await create_custom_emoji(*, name, image, roles=..., reason=None)[ソース]¶
This function is a coroutine.
Creates a custom
GuildEmojifor the guild.There is currently a limit of 50 static and animated emojis respectively per guild, unless the guild has the
MORE_EMOJIfeature which extends the limit to 200.You must have the
manage_emojispermission to do this.- パラメータ:
name (
str) -- The emoji name. Must be at least 2 characters.image (
bytes) -- The bytes-like object representing the image data to use. Only JPG, PNG and GIF images are supported.roles (
list[Role]) -- AlistofRoles that can use this emoji. Leave empty to make it available to everyone.reason (
str|None) -- The reason for creating this emoji. Shows up on the audit log.
- 例外:
Forbidden -- You are not allowed to create emojis.
HTTPException -- An error occurred creating an emoji.
- 戻り値:
The created emoji.
- 戻り値の型:
- await delete_emoji(emoji, *, reason=None)[ソース]¶
This function is a coroutine.
Deletes the custom
GuildEmojifrom the guild.You must have
manage_emojispermission to do this.
- await fetch_roles()[ソース]¶
This function is a coroutine.
Retrieves all
Rolethat the guild has.注釈
This method is an API call. For general usage, consider
rolesinstead.Added in version 1.3.
- 戻り値:
All roles in the guild.
- 戻り値の型:
- 例外:
HTTPException -- Retrieving the roles failed.
- await fetch_role(role_id)[ソース]¶
This function is a coroutine.
Retrieves a
Rolethat the guild has.注釈
This method is an API call. For general usage, consider using
get_roleinstead.Added in version 2.7.
- 戻り値:
The role in the guild with the specified ID.
- 戻り値の型:
- 例外:
HTTPException -- Retrieving the role failed.
- パラメータ:
role_id (
int)
- await create_role(*, name=..., permissions=..., color=..., colour=..., colors=..., colours=..., holographic=..., hoist=..., mentionable=..., reason=None, icon=..., unicode_emoji=...)[ソース]¶
This function is a coroutine.
Creates a
Rolefor the guild.All fields are optional.
You must have the
manage_rolespermission to do this.バージョン 1.6 で変更: Can now pass
inttocolourkeyword-only parameter.- パラメータ:
name (
str) -- The role name. Defaults to 'new role'.permissions (
Permissions) -- The permissions to have. Defaults to no permissions.colour (
Colour|int) -- The colour for the role. Defaults toColour.default(). This is aliased tocoloras well.hoist (
bool) -- Indicates if the role should be shown separately in the member list. Defaults toFalse.mentionable (
bool) -- Indicates if the role should be mentionable by others. Defaults toFalse.reason (
str|None) -- The reason for creating this role. Shows up on the audit log.icon (
bytes|None) -- A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed,unicode_emojiis set to None. Only available to guilds that containROLE_ICONSinGuild.features.unicode_emoji (
str|None) -- The role's unicode emoji. If this argument is passed,iconis set to None. Only available to guilds that containROLE_ICONSinGuild.features.colors (
RoleColours)colours (
RoleColours)holographic (
bool)
- 戻り値:
The newly created role.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to create the role.
HTTPException -- Creating the role failed.
InvalidArgument -- An invalid keyword argument was given.
- await edit_role_positions(positions, *, reason=None)[ソース]¶
This function is a coroutine.
Bulk edits a list of
Rolein the guild.You must have the
manage_rolespermission to do this.Added in version 1.4.
Example:
positions = { bots_role: 1, # penultimate role tester_role: 2, admin_role: 6 } await guild.edit_role_positions(positions=positions)
- パラメータ:
- 戻り値:
A list of all the roles in the guild.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to move the roles.
HTTPException -- Moving the roles failed.
InvalidArgument -- An invalid keyword argument was given.
- await kick(user, *, reason=None)[ソース]¶
This function is a coroutine.
Kicks a user from the guild.
The user must meet the
abc.Snowflakeabc.You must have the
kick_memberspermission to do this.
- await ban(user, *, delete_message_seconds=None, reason=None)[ソース]¶
This function is a coroutine.
Bans a user from the guild.
The user must meet the
abc.Snowflakeabc.You must have the
ban_memberspermission to do this.- パラメータ:
- 例外:
Forbidden -- You do not have the proper permissions to ban.
HTTPException -- Banning failed.
- 戻り値の型:
- await bulk_ban(*users, delete_message_seconds=None, reason=None)[ソース]¶
This function is a coroutine.
Bulk ban users from the guild.
The users must meet the
abc.Snowflakeabc.You must have the
ban_memberspermission to do this.Example Usage:
# Ban multiple users successes, failures = await guild.bulk_ban(user1, user2, user3, ..., reason="Raid") # Ban a list of users successes, failures = await guild.bulk_ban(*users)
- パラメータ:
- 戻り値:
Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.
- 戻り値の型:
- 例外:
ValueError -- You tried to ban more than 200 users.
Forbidden -- You do not have the proper permissions to ban.
HTTPException -- No users were banned.
- await unban(user, *, reason=None)[ソース]¶
This function is a coroutine.
Unbans a user from the guild.
The user must meet the
abc.Snowflakeabc.You must have the
ban_memberspermission to do this.
- await vanity_invite()[ソース]¶
This function is a coroutine.
Returns the guild's special vanity invite.
The guild must have
VANITY_URLinfeatures.You must have the
manage_guildpermission to use this as well.- 戻り値:
The special vanity invite. If
Nonethen the guild does not have a vanity invite set.- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to get this.
HTTPException -- Retrieving the vanity invite failed.
- await widget()[ソース]¶
This function is a coroutine.
Returns the widget of the guild.
注釈
The guild must have the widget enabled to get this information.
- 戻り値:
The guild's widget.
- 戻り値の型:
- 例外:
Forbidden -- The widget for this guild is disabled.
HTTPException -- Retrieving the widget failed.
- await edit_widget(*, enabled=..., channel=...)[ソース]¶
This function is a coroutine.
Edits the widget of the guild.
You must have the
manage_guildpermission to use thisAdded in version 2.0.
- await chunk(*, cache=True)[ソース]¶
This function is a coroutine.
Requests all members that belong to this guild. In order to use this,
Intents.members()must be enabled.This is a websocket operation and can be slow.
Added in version 1.5.
- パラメータ:
cache (
bool) -- Whether to cache the members as well.- 例外:
ClientException -- The members intent is not enabled.
- 戻り値の型:
- await query_members(query=None, *, limit=5, user_ids=None, presences=False, cache=True)[ソース]¶
This function is a coroutine.
Request members that belong to this guild whose username starts with the query given.
This is a websocket operation and can be slow.
Added in version 1.3.
- パラメータ:
query (
str|None) -- The string that the username's start with.user_ids (
list[int] |None) --List of user IDs to search for. If the user ID is not in the guild then it won't be returned.
Added in version 1.4.
limit (
int|None) -- The maximum number of members to send back. If no query is passed, passingNonereturns all members. If aqueryoruser_idsis passed, must be between 1 and 100. Defaults to 5.presences (
bool) --Whether to request for presences to be provided. This defaults to
False.Added in version 1.6.
cache (
bool) -- Whether to cache the members internally. This makes operations such asget_member()work for those that matched. Defaults toTrue.
- 戻り値:
The list of members that have matched the query.
- 戻り値の型:
- 例外:
asyncio.TimeoutError -- The query timed out waiting for the members.
ValueError -- Invalid parameters were passed to the function
ClientException -- The presences intent is not enabled.
- await change_voice_state(*, channel, self_mute=False, self_deaf=False)[ソース]¶
This function is a coroutine.
Changes client's voice state in the guild.
Added in version 1.4.
- パラメータ:
channel (
VoiceChannel|StageChannel|None) -- Channel the client wants to join. UseNoneto disconnect.self_mute (
bool) -- Indicates if the client should be self-muted.self_deaf (
bool) -- Indicates if the client should be self-deafened.
- await welcome_screen()[ソース]¶
This function is a coroutine.
Returns the
WelcomeScreenof the guild.The guild must have
COMMUNITYinfeatures.You must have the
manage_guildpermission in order to get this.Added in version 2.0.
- 戻り値:
The welcome screen of guild.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to get this.
HTTPException -- Retrieving the welcome screen failed somehow.
NotFound -- The guild doesn't have a welcome screen or community feature is disabled.
- await edit_welcome_screen(**options)[ソース]¶
This function is a coroutine.
A shorthand for
WelcomeScreen.editwithout fetching the welcome screen.You must have the
manage_guildpermission in the guild to do this.The guild must have
COMMUNITYinGuild.features- パラメータ:
description (Optional[
str]) -- The new description of welcome screen.welcome_channels (Optional[List[
WelcomeScreenChannel]]) -- The welcome channels. The order of the channels would be same as the passed list order.enabled (Optional[
bool]) -- Whether the welcome screen should be displayed.reason (Optional[
str]) -- The reason that shows up on audit log.
- 戻り値:
The edited welcome screen.
- 戻り値の型:
- 例外:
HTTPException -- Editing the welcome screen failed somehow.
Forbidden -- You don't have permissions to edit the welcome screen.
NotFound -- This welcome screen does not exist.
- await fetch_scheduled_events(*, with_user_count=True)[ソース]¶
This function is a coroutine.
Returns a list of
ScheduledEventin the guild.注釈
This method is an API call. For general usage, consider
scheduled_eventsinstead.- パラメータ:
with_user_count (
bool) -- If the scheduled event should be fetched with the number of users that are interested in the events. Defaults toTrue.- 戻り値:
The fetched scheduled events.
- 戻り値の型:
- 例外:
ClientException -- The scheduled events intent is not enabled.
HTTPException -- Getting the scheduled events failed.
- await fetch_scheduled_event(event_id, /, *, with_user_count=True)[ソース]¶
This function is a coroutine.
Retrieves a
ScheduledEventfrom event ID.注釈
This method is an API call. If you have
Intents.scheduled_events, considerget_scheduled_event()instead.- パラメータ:
- 戻り値:
The scheduled event from the event ID.
- 戻り値の型:
- 例外:
HTTPException -- Fetching the event failed.
NotFound -- Event not found.
- get_scheduled_event(event_id, /)[ソース]¶
Returns a Scheduled Event with the given ID.
- パラメータ:
event_id (
int) -- The ID to search for.- 戻り値:
The scheduled event or
Noneif not found.- 戻り値の型:
- await create_scheduled_event(*, name, description=..., start_time, end_time=..., location, privacy_level=('guild_only', 2), reason=None, image=...)[ソース]¶
This function is a coroutine. Creates a scheduled event.
- パラメータ:
name (
str) -- The name of the scheduled event.description (
str) -- The description of the scheduled event.start_time (
datetime) -- A datetime object of when the scheduled event is supposed to start.end_time (
datetime) -- A datetime object of when the scheduled event is supposed to end.location (
str|int|VoiceChannel|StageChannel|ScheduledEventLocation) -- The location of where the event is happening.privacy_level (
ScheduledEventPrivacyLevel) -- The privacy level of the event. Currently, the only possible value isScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.image (
bytes) -- The cover image of the scheduled event
- 戻り値:
The created scheduled event.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the Manage Events permission.
HTTPException -- The operation failed.
- property scheduled_events: list[ScheduledEvent]¶
A list of scheduled events in this guild.
- await fetch_auto_moderation_rules()[ソース]¶
This function is a coroutine.
Retrieves a list of auto moderation rules for this guild.
- 戻り値:
The auto moderation rules for this guild.
- 戻り値の型:
- 例外:
HTTPException -- Getting the auto moderation rules failed.
Forbidden -- You do not have the Manage Guild permission.
- await fetch_auto_moderation_rule(id)[ソース]¶
This function is a coroutine.
Retrieves a
AutoModRulefrom rule ID.- 戻り値:
The requested auto moderation rule.
- 戻り値の型:
- 例外:
HTTPException -- Getting the auto moderation rule failed.
Forbidden -- You do not have the Manage Guild permission.
- パラメータ:
id (
int)
- await create_auto_moderation_rule(*, name, event_type, trigger_type, trigger_metadata, actions, enabled=False, exempt_roles=None, exempt_channels=None, reason=None)[ソース]¶
Creates an auto moderation rule.
- パラメータ:
name (
str) -- The name of the auto moderation rule.event_type (
AutoModEventType) -- The type of event that triggers the rule.trigger_type (
AutoModTriggerType) -- The rule's trigger type.trigger_metadata (
AutoModTriggerMetadata) -- The rule's trigger metadata.actions (
list[AutoModAction]) -- The actions to take when the rule is triggered.enabled (
bool) -- Whether the rule is enabled.exempt_roles (
list[Snowflake]) -- A list of roles that are exempt from the rule.exempt_channels (
list[Snowflake]) -- A list of channels that are exempt from the rule.reason (
str|None) -- The reason for creating the rule. Shows up in the audit log.
- 戻り値:
The new auto moderation rule.
- 戻り値の型:
- 例外:
HTTPException -- Creating the auto moderation rule failed.
Forbidden -- You do not have the Manage Guild permission.
- await onboarding()[ソース]¶
This function is a coroutine.
Returns the
Onboardingflow for the guild.Added in version 2.5.
- 戻り値:
The onboarding flow for the guild.
- 戻り値の型:
- 例外:
HTTPException -- Retrieving the onboarding flow failed somehow.
- await edit_onboarding(*, prompts=..., default_channels=..., enabled=..., mode=..., reason=...)[ソース]¶
This function is a coroutine.
A shorthand for
Onboarding.editwithout fetching the onboarding flow.You must have the
manage_guildandmanage_rolespermissions in the guild to do this.- パラメータ:
prompts (
list[OnboardingPrompt] |None) -- The new list of prompts for this flow.default_channels (
list[Snowflake] |None) -- The new default channels that users are opted into.enabled (
bool|None) -- Whether onboarding should be enabled. Setting this toTruerequires the guild to haveCOMMUNITYinfeaturesand at least 7default_channels.mode (
OnboardingMode|None) -- The new onboarding mode.reason (
str|None) -- The reason that shows up on Audit log.
- 戻り値:
The updated onboarding flow.
- 戻り値の型:
- 例外:
HTTPException -- Editing the onboarding flow failed somehow.
Forbidden -- You don't have permissions to edit the onboarding flow.
- await modify_incident_actions(*, invites_disabled_until=..., dms_disabled_until=..., reason=...)[ソース]¶
This function is a coroutine.
Modify the guild's incident actions, controlling when invites or DMs are re-enabled after being temporarily disabled. Requires the
manage_guildpermission.- パラメータ:
invites_disabled_until (
datetime|None) -- The ISO8601 timestamp indicating when invites will be enabled again, orNoneto enable invites immediately.dms_disabled_until (
datetime|None) -- The ISO8601 timestamp indicating when DMs will be enabled again, orNoneto enable DMs immediately.reason (
str|None) -- The reason for this action, used for the audit log.
- 戻り値:
The updated incidents data for the guild.
- 戻り値の型:
IncidentsData
- await create_test_entitlement(sku)[ソース]¶
This function is a coroutine.
Creates a test entitlement for the guild.
- パラメータ:
sku (
Snowflake) -- The SKU to create a test entitlement for.- 戻り値:
The created entitlement.
- 戻り値の型:
- entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)[ソース]¶
Returns an
AsyncIteratorthat enables fetching the guild's entitlements.This is identical to
Client.entitlements()with theguildparameter.Added in version 2.6.
- パラメータ:
skus (
list[Snowflake] |None) -- Limit the fetched entitlements to entitlements that are for these SKUs.before (
Snowflake|datetime|None) -- Retrieves guilds before this date or object. 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 (
Snowflake|datetime|None) -- Retrieve guilds after this date or object. 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.limit (
int|None) -- The number of entitlements to retrieve. IfNone, retrieves every entitlement, which may be slow. Defaults to100.exclude_ended (
bool) -- Whether to limit the fetched entitlements to those that have not ended. Defaults toFalse.
- 列挙:
Entitlement-- The application's entitlements.- 例外:
HTTPException -- Retrieving the entitlements failed.
- 戻り値の型:
EntitlementIterator
- accent_color
- accent_colour
- activities
- activity
- avatar
- avatar_decoration
- banner
- bot
- collectibles
- color
- colors
- colour
- colours
- communication_disabled_until
- created_at
- default_avatar
- desktop_status
- discriminator
- display_avatar
- display_avatar_decoration
- display_banner
- display_name
- dm_channel
- flags
- global_name
- guild
- guild_avatar
- guild_avatar_decoration
- guild_banner
- guild_permissions
- id
- is_migrated
- joined_at
- jump_url
- mention
- mobile_status
- mutual_guilds
- name
- nameplate
- nick
- pending
- premium_since
- primary_guild
- public_flags
- raw_status
- roles
- status
- system
- timed_out
- top_role
- voice
- web_status
- asyncadd_roles
- asyncban
- defcan_send
- asynccreate_dm
- asynccreate_test_entitlement
- asyncedit
- defentitlements
- asyncfetch_message
- defget_role
- defhistory
- defis_on_mobile
- asynckick
- defmentioned_in
- asyncmove_to
- defpins
- asyncremove_roles
- asyncremove_timeout
- asyncrequest_to_speak
- asyncsend
- asynctimeout
- asynctimeout_for
- asynctrigger_typing
- deftyping
- asyncunban
- class discord.Member(*, data, guild, state)[ソース]¶
Represents a Discord member to a
Guild.This implements a lot of the functionality of
User.- x == y
Checks if two members are equal. Note that this works with
Userinstances too.
- x != y
Checks if two members are not equal. Note that this works with
Userinstances too.
- hash(x)
Returns the member's hash.
- str(x)
Returns the member's name with the discriminator or global_name.
- joined_at¶
An aware datetime object that specifies the date and time in UTC that the member joined the guild. If the member left and rejoined the guild, this will be the latest date. In certain cases, this can be
None.- Type:
Optional[
datetime.datetime]
- activities¶
The activities that the user is currently doing.
注釈
Due to a Discord API limitation, a user's Spotify activity may not appear if they are listening to a song with a title longer than 128 characters.
- Type:
Tuple[Union[
BaseActivity,Spotify]]
An aware datetime object that specifies the date and time in UTC when the member used their "Nitro boost" on the guild, if available. This could be
None.- Type:
Optional[
datetime.datetime]
- communication_disabled_until¶
An aware datetime object that specifies the date and time in UTC when the member will be removed from timeout.
Added in version 2.0.
- Type:
Optional[
datetime.datetime]
- flags¶
Extra attributes of the member.
Added in version 2.6.
- Type:
- パラメータ:
data (
MemberWithUser)guild (
Guild)state (
ConnectionState)
- async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- async with typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- property discriminator¶
Equivalent to
User.discriminator
- property system¶
Equivalent to
User.system
- property created_at¶
Equivalent to
User.created_at
- property default_avatar¶
Equivalent to
User.default_avatar
- property avatar¶
Equivalent to
User.avatar
- property dm_channel¶
Equivalent to
User.dm_channel
- await create_dm() DMChannel¶
This function is a coroutine.
Creates a
DMChannelwith this user.This should be rarely called, as this is done transparently for most people.
- 戻り値:
The channel that was created.
- 戻り値の型:
- property mutual_guilds¶
Equivalent to
User.mutual_guilds
- property public_flags¶
Equivalent to
User.public_flags
- property banner¶
Equivalent to
User.banner
- property accent_color¶
Equivalent to
User.accent_color
- property accent_colour¶
Equivalent to
User.accent_colour
- property primary_guild¶
Equivalent to
User.primary_guild
- property collectibles¶
Equivalent to
User.collectibles
- property avatar_decoration¶
Equivalent to
User.avatar_decoration
- property status: Status¶
The member's overall status. If the value is unknown, then it will be a
strinstead.
- property mobile_status: Status¶
The member's status on a mobile device, if applicable.
- property desktop_status: Status¶
The member's status on the desktop client, if applicable.
- property web_status: Status¶
The member's status on the web client, if applicable.
- is_on_mobile()[ソース]¶
A helper function that determines if a member is active on a mobile device.
- 戻り値の型:
- property colour: Colour¶
A property that returns a colour denoting the rendered primary colour for the member. If the default colour is the one rendered then an instance of
Colour.default()is returned.This is an alias for
Member.colours.primary.
- property color: Colour¶
A property that returns a color denoting the primary rendered color for the member. If the default color is the one rendered then an instance of
Colour.default()is returned.This is an alias for
Member.colours.primary.
- property colours: RoleColours¶
A property that returns the rendered
RoleColoursfor the member. If the default color is the one rendered then an instance ofRoleColours.default()is returned.There is an alias for this named
colors.Added in version 2.8.
- property colors: RoleColours¶
A property that returns the rendered
RoleColoursfor the member. If the default color is the one rendered then an instance ofColour.default()is returned.This is an alias for
colours.Added in version 2.8.
- property roles: list[Role]¶
A
listofRolethat the member belongs to. Note that the first element of this list is always the default '@everyone' role.These roles are sorted by their position in the role hierarchy.
- property display_name: str¶
Returns the user's display name. This will either be their guild specific nickname, global name or username.
- property display_avatar: Asset¶
Returns the member's display avatar.
Returns the user's guild avatar. If the user does not have a guild avatar, their global avatar is returned instead.
Added in version 2.0.
- property guild_avatar: Asset | None¶
Returns an
Assetfor the guild avatar the member has. If unavailable,Noneis returned.Added in version 2.0.
- property display_avatar_decoration: Asset | None¶
Returns the member's displayed avatar decoration.
Returns the user's guild avatar decoration. If the user does not have a guild avatar decoration, their global avatar decoration is returned instead.
Added in version 2.8.
- property guild_avatar_decoration: Asset | None¶
Returns an
Assetfor the guild specific avatar decoration the member has. If unavailable,Noneis returned.Added in version 2.8.
- property display_banner: Asset | None¶
Returns the member's display banner.
Returns the user's guild banner. If the user does not have a guild banner, their global banner is returned instead.
Added in version 2.7.
- property guild_banner: Asset | None¶
Returns an
Assetfor the guild banner the member has. If unavailable,Noneis returned.Added in version 2.7.
- property activity: Activity | Game | CustomActivity | Streaming | Spotify | None¶
Returns the primary activity the user is currently doing. Could be
Noneif no activity is being done.注釈
Due to a Discord API limitation, this may be
Noneif the user is listening to a song on Spotify with a title longer than 128 characters.注釈
A user may have multiple activities, these can be accessed under
activities.
- property top_role: Role¶
Returns the member's highest role.
This is useful for figuring where a member stands in the role hierarchy chain.
- property guild_permissions: Permissions¶
Returns the member's guild permissions.
This only takes into consideration the guild permissions and not most of the implied permissions or any of the channel permission overwrites. For 100% accurate permission calculation, please use
abc.GuildChannel.permissions_for().This does take into consideration guild ownership and the administrator implication.
- property voice: VoiceState | None¶
Returns the member's current voice state.
- await ban(*, delete_message_seconds=None, reason=None)[ソース]¶
This function is a coroutine.
Bans this member. Equivalent to
Guild.ban().
- await unban(*, reason=None)[ソース]¶
This function is a coroutine.
Unbans this member. Equivalent to
Guild.unban().
- await kick(*, reason=None)[ソース]¶
This function is a coroutine.
Kicks this member. Equivalent to
Guild.kick().
- await edit(*, nick=..., mute=..., deafen=..., suppress=..., roles=..., voice_channel=..., reason=None, communication_disabled_until=..., bypass_verification=..., banner=..., avatar=..., bio=...)[ソース]¶
This function is a coroutine.
Edits the member's data.
Depending on the parameter passed, this requires different permissions listed below:
Parameter
Permission
nick
mute
deafen
roles
voice_channel
communication_disabled_until
bypass_verification
See note below
注釈
bypass_verification may be edited under three scenarios:
Client has
Permissions.manage_guildClient has
Permissions.manage_rolesClient has ALL THREE of
Permissions.moderate_members,Permissions.kick_members, andPermissions.ban_members
注釈
The following parameters are only available when editing the bot's own member:
avatarbannerbio
All parameters are optional.
バージョン 1.1 で変更: Can now pass
Nonetovoice_channelto kick a member from voice.バージョン 2.0 で変更: The newly member is now optionally returned, if applicable.
- パラメータ:
nick (
str|None) -- The member's new nickname. UseNoneto remove the nickname.mute (
bool) -- Indicates if the member should be guild muted or un-muted.deafen (
bool) -- Indicates if the member should be guild deafened or un-deafened.suppress (
bool) --Indicates if the member should be suppressed in stage channels.
Added in version 1.7.
roles (
list[Snowflake]) -- The member's new list of roles. This replaces the roles.voice_channel (
VocalGuildChannel|None) -- The voice channel to move the member to. PassNoneto kick them from voice.reason (
str|None) -- The reason for editing this member. Shows up on the audit log.communication_disabled_until (
datetime|None) --Temporarily puts the member in timeout until this time. If the value is
None, then the user is removed from timeout.Added in version 2.0.
bypass_verification (
bool|None) --Indicates if the member should bypass the guild's verification requirements.
Added in version 2.6.
A bytes-like object representing the banner. Could be
Noneto denote removal of the banner.This is only available when editing the bot's own member (i.e.
Guild.me).Added in version 2.7.
A bytes-like object representing the avatar. Could be
Noneto denote removal of the avatar.This is only available when editing the bot's own member (i.e.
Guild.me).Added in version 2.7.
The new bio for the member. Could be
Noneto denote removal of the bio.This is only available when editing the bot's own member (i.e.
Guild.me).Added in version 2.7.
- 戻り値:
The newly updated member, if applicable. This is only returned when certain fields are updated.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to the action requested.
HTTPException -- The operation failed.
InvalidArgument -- You tried to edit the avatar, banner, or bio of a member that is not the bot.
- await timeout(until, *, reason=None)[ソース]¶
This function is a coroutine.
Applies a timeout to a member in the guild until a set datetime.
You must have the
moderate_memberspermission to timeout a member.- パラメータ:
- 例外:
Forbidden -- You do not have permissions to timeout members.
HTTPException -- An error occurred doing the request.
- 戻り値の型:
- await timeout_for(duration, *, reason=None)[ソース]¶
This function is a coroutine.
Applies a timeout to a member in the guild for a set duration. A shortcut method for
timeout(), and equivalent totimeout(until=datetime.utcnow() + duration, reason=reason).You must have the
moderate_memberspermission to timeout a member.
- await remove_timeout(*, reason=None)[ソース]¶
This function is a coroutine.
Removes the timeout from a member.
You must have the
moderate_memberspermission to remove the timeout.This is equivalent to calling
timeout()and passingNoneto theuntilparameter.- パラメータ:
reason (
str|None) -- The reason for doing this action. Shows up on the audit log.- 例外:
Forbidden -- You do not have permissions to remove the timeout.
HTTPException -- An error occurred doing the request.
- 戻り値の型:
- await request_to_speak()[ソース]¶
This function is a coroutine.
Request to speak in the connected channel.
Only applies to stage channels.
注釈
Requesting members that are not the client is equivalent to
editprovidingsuppressasFalse.Added in version 1.7.
- 例外:
Forbidden -- You do not have the proper permissions to the action requested.
HTTPException -- The operation failed.
- 戻り値の型:
- await move_to(channel, *, reason=None)[ソース]¶
This function is a coroutine.
Moves a member to a new voice channel (they must be connected first).
You must have the
move_memberspermission to use this.This raises the same exceptions as
edit().バージョン 1.1 で変更: Can now pass
Noneto kick a member from voice.
- await add_roles(*roles, reason=None, atomic=True)[ソース]¶
This function is a coroutine.
Gives the member a number of
Roles.You must have the
manage_rolespermission to use this, and the addedRoles must appear lower in the list of roles than the highest role of the member.- パラメータ:
*roles (
Snowflake) -- An argument list ofabc.Snowflakerepresenting aRoleto give to the member.reason (
str|None) -- The reason for adding these roles. Shows up on the audit log.atomic (
bool) -- Whether to atomically add roles. This will ensure that multiple operations will always be applied regardless of the current state of the cache.
- 例外:
Forbidden -- You do not have permissions to add these roles.
HTTPException -- Adding roles failed.
- 戻り値の型:
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- await create_test_entitlement(sku: discord.abc.Snowflake) Entitlement¶
This function is a coroutine.
Creates a test entitlement for the user.
- パラメータ:
sku (
Snowflake) -- The SKU to create a test entitlement for.- 戻り値:
The created entitlement.
- 戻り値の型:
- entitlements(skus: list[Snowflake] | None = None, before: SnowflakeTime | None = None, after: SnowflakeTime | None = None, limit: int | None = 100, exclude_ended: bool = False) EntitlementIterator¶
Returns an
AsyncIteratorthat enables fetching the user's entitlements.This is identical to
Client.entitlements()with theuserparameter.Added in version 2.6.
- パラメータ:
skus (list[
abc.Snowflake] | None) -- Limit the fetched entitlements to entitlements that are for these SKUs.before (
abc.Snowflake|datetime.datetime| None) -- Retrieves guilds before this date or object. 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 (
abc.Snowflake|datetime.datetime| None) -- Retrieve guilds after this date or object. 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.limit (Optional[
int]) -- The number of entitlements to retrieve. IfNone, retrieves every entitlement, which may be slow. Defaults to100.exclude_ended (
bool) -- Whether to limit the fetched entitlements to those that have not ended. Defaults toFalse.
- 列挙:
Entitlement-- The application's entitlements.- 例外:
HTTPException -- Retrieving the entitlements failed.
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- property is_migrated¶
Equivalent to
User.is_migrated
- property jump_url¶
Equivalent to
User.jump_url
- property nameplate¶
Equivalent to
User.nameplate
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await remove_roles(*roles, reason=None, atomic=True)[ソース]¶
This function is a coroutine.
Removes
Roles from this member.You must have the
manage_rolespermission to use this, and the removedRoles must appear lower in the list of roles than the highest role of the member.- パラメータ:
*roles (
Snowflake) -- An argument list ofabc.Snowflakerepresenting aRoleto remove from the member.reason (
str|None) -- The reason for removing these roles. Shows up on the audit log.atomic (
bool) -- Whether to atomically remove roles. This will ensure that multiple operations will always be applied regardless of the current state of the cache.
- 例外:
Forbidden -- You do not have permissions to remove these roles.
HTTPException -- Removing the roles failed.
- 戻り値の型:
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- class discord.Template(*, state, data)[ソース]¶
Represents a Discord template.
Added in version 1.4.
- created_at¶
An aware datetime in UTC representing when the template was created.
- Type:
- updated_at¶
An aware datetime in UTC representing when the template was last updated. This is referred to as "last synced" in the official Discord client.
- Type:
- パラメータ:
state (
ConnectionState)data (
Template)
- await sync()[ソース]¶
This function is a coroutine.
Sync the template to the guild's current state.
You must have the
manage_guildpermission in the source guild to do this.Added in version 1.7.
バージョン 2.0 で変更: The template is no longer synced in-place, instead it is returned.
- 戻り値:
The newly synced template.
- 戻り値の型:
- 例外:
HTTPException -- Syncing the template failed.
Forbidden -- You don't have permissions to sync the template.
NotFound -- This template does not exist.
- await edit(*, name=..., description=...)[ソース]¶
This function is a coroutine.
Edit the template metadata.
You must have the
manage_guildpermission in the source guild to do this.Added in version 1.7.
バージョン 2.0 で変更: The template is no longer edited in-place, instead it is returned.
- パラメータ:
- 戻り値:
The newly edited template.
- 戻り値の型:
- 例外:
HTTPException -- Editing the template failed.
Forbidden -- You don't have permissions to edit the template.
NotFound -- This template does not exist.
- await delete()[ソース]¶
This function is a coroutine.
Delete the template.
You must have the
manage_guildpermission in the source guild to do this.Added in version 1.7.
- 例外:
HTTPException -- Deleting the template failed.
Forbidden -- You don't have permissions to delete the template.
NotFound -- This template does not exist.
- 戻り値の型:
AutoMod¶
- class discord.AutoModRule(*, state, data)[ソース]¶
Represents a guild's auto moderation rule.
Added in version 2.0.
- x == y
Checks if two rules are equal.
- x != y
Checks if two rules are not equal.
- hash(x)
Returns the rule's hash.
- str(x)
Returns the rule's name.
- event_type¶
Indicates in what context the rule is checked.
- Type:
- trigger_type¶
Indicates what type of information is checked to determine whether the rule is triggered.
- Type:
- trigger_metadata¶
The rule's trigger metadata.
- Type:
- actions¶
The actions to perform when the rule is triggered.
- Type:
List[
AutoModAction]
- パラメータ:
state (
ConnectionState)data (
AutoModRule)
- property exempt_roles: list[Role | Object][ソース]¶
The roles that are exempt from this rule.
If a role is not found in the guild's cache, then it will be returned as an
Object.
- property exempt_channels: list[TextChannel | ForumChannel | VoiceChannel | Object][ソース]¶
The channels that are exempt from this rule.
If a channel is not found in the guild's cache, then it will be returned as an
Object.
- await delete(reason=None)[ソース]¶
This function is a coroutine.
Deletes this rule.
- パラメータ:
reason (
str|None) -- The reason for deleting this rule. Shows up in the audit log.- 例外:
Forbidden -- You do not have the Manage Guild permission.
HTTPException -- The operation failed.
- 戻り値の型:
- await edit(*, name=..., event_type=..., trigger_metadata=..., actions=..., enabled=..., exempt_roles=..., exempt_channels=..., reason=None)[ソース]¶
This function is a coroutine.
Edits this rule.
- パラメータ:
name (
str) -- The rule's new name.event_type (
AutoModEventType) -- The new context in which the rule is checked.trigger_metadata (
AutoModTriggerMetadata) -- The new trigger metadata.actions (
list[AutoModAction]) -- The new actions to perform when the rule is triggered.enabled (
bool) -- Whether this rule is enabled.exempt_roles (
list[Snowflake]) -- The roles that will be exempt from this rule.exempt_channels (
list[Snowflake]) -- The channels that will be exempt from this rule.reason (
str|None) -- The reason for editing this rule. Shows up in the audit log.
- 戻り値:
The newly updated rule, if applicable. This is only returned when fields are updated.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the Manage Guild permission.
HTTPException -- The operation failed.
- class discord.AutoModAction(action_type, metadata)[ソース]¶
Represents an action for a guild's auto moderation rule.
Added in version 2.0.
- type¶
The action's type.
- Type:
- metadata¶
The action's metadata.
- Type:
- パラメータ:
action_type (
AutoModActionType)metadata (
AutoModActionMetadata)
- class discord.AutoModActionMetadata(channel_id=..., timeout_duration=..., custom_message=...)[ソース]¶
Represents an action's metadata.
Depending on the action's type, different attributes will be used.
Added in version 2.0.
- channel_id¶
The ID of the channel to send the message to. Only for actions of type
AutoModActionType.send_alert_message.- Type:
- timeout_duration¶
How long the member that triggered the action should be timed out for. Only for actions of type
AutoModActionType.timeout.- Type:
- custom_message¶
An additional message shown to members when their message is blocked. Maximum 150 characters. Only for actions of type
AutoModActionType.block_message.- Type:
- class discord.AutoModTriggerMetadata(keyword_filter=..., regex_patterns=..., presets=..., allow_list=..., mention_total_limit=...)[ソース]¶
Represents a rule's trigger metadata, defining additional data used to determine when a rule triggers.
Depending on the trigger type, different metadata attributes will be used:
Attribute
Trigger Types
AutoModTriggerType.keyword,AutoModTriggerType.keyword_presetEach attribute has limits that may change based on the trigger type. See here for information on attribute limits.
Added in version 2.0.
- regex_patterns¶
A list of regex patterns to filter using Rust-flavored regex, which is not fully compatible with regex syntax supported by the builtin re module.
Added in version 2.4.
- Type:
List[
str]
- presets¶
A list of preset keyword sets to filter.
- Type:
List[
AutoModKeywordPresetType]
- allow_list¶
A list of substrings to allow, overriding keyword and regex matches.
Added in version 2.4.
- Type:
List[
str]
- mention_total_limit¶
The total number of unique role and user mentions allowed.
Added in version 2.4.
- Type:
Invites¶
- class discord.PartialInviteGuild(state, data, id)[ソース]¶
Represents a "partial" invite guild.
This model will be given when the user is not part of the guild the
Inviteresolves to.- x == y
Checks if two partial guilds are the same.
- x != y
Checks if two partial guilds are not the same.
- hash(x)
Return the partial guild's hash.
- str(x)
Returns the partial guild's name.
- verification_level¶
The partial guild's verification level.
- Type:
- features¶
A list of features the guild has. See
Guild.featuresfor more information.- Type:
List[
str]
- パラメータ:
state (
ConnectionState)data (
InviteGuild)id (
int)
- class discord.PartialInviteChannel(data)[ソース]¶
Represents a "partial" invite channel.
This model will be given when the user is not part of the guild the
Inviteresolves to.- x == y
Checks if two partial channels are the same.
- x != y
Checks if two partial channels are not the same.
- hash(x)
Return the partial channel's hash.
- str(x)
Returns the partial channel's name.
- type¶
The partial channel's type.
- Type:
- パラメータ:
data (
PartialChannel)
- asyncdelete
- asyncedit_target_users
- asyncfetch_target_users_job_status
- defset_scheduled_event
- class discord.Invite(*, state, data, guild=None, channel=None)[ソース]¶
Represents a Discord
Guildorabc.GuildChannelinvite.Depending on the way this object was created, some of the attributes can have a value of
None.- x == y
Checks if two invites are equal.
- x != y
Checks if two invites are not equal.
- hash(x)
Returns the invite hash.
- str(x)
Returns the invite URL.
The following table illustrates what methods will obtain the attributes:
Attribute
Method
Client.fetch_invite()with with_counts enabledClient.fetch_invite()with with_counts enabledClient.fetch_invite()with with_expiration enabledIf it's not in the table above then it is available by all methods.
- max_age¶
How long before the invite expires in seconds. A value of
0indicates that it doesn't expire.- Type:
- guild¶
The guild the invite is for. Can be
Noneif it's from a group direct message.- Type:
Optional[Union[
Guild,Object,PartialInviteGuild]]
- created_at¶
An aware UTC datetime object denoting the time the invite was created.
- Type:
- temporary¶
Indicates that the invite grants temporary membership. If
True, members who joined via this invite will be kicked upon disconnect.- Type:
- max_uses¶
How many times the invite can be used. A value of
0indicates that it has unlimited uses.- Type:
- approximate_presence_count¶
The approximate number of members currently active in the guild. This includes idle, dnd, online, and invisible members. Offline members are excluded.
- Type:
Optional[
int]
- expires_at¶
The expiration date of the invite. If the value is
Nonewhen received through Client.fetch_invite with with_expiration enabled, the invite will never expire.Added in version 2.0.
- Type:
Optional[
datetime.datetime]
- channel¶
The channel the invite is for.
- Type:
Union[
abc.GuildChannel,Object,PartialInviteChannel]
- target_type¶
The type of target for the voice channel invite.
Added in version 2.0.
- Type:
- target_user¶
The user whose stream to display for this invite, if any.
Added in version 2.0.
- Type:
Optional[
User]
- target_application¶
The embedded application the invite targets, if any.
Added in version 2.0.
- Type:
Optional[
PartialAppInfo]
- scheduled_event¶
The scheduled event linked with the invite.
- Type:
Optional[
ScheduledEvent]
- roles¶
The roles that will be assigned to a user that joins via this invite.
When using Client.fetch_invite, these may be partial role objects and have nullish attributes.
Added in version 2.8.
- パラメータ:
state (
ConnectionState)data (
Invite|VanityInvite)guild (
PartialInviteGuild|Guild|None)channel (
PartialInviteChannel|GuildChannel|None)
- property target_users: InviteTargetUsers¶
An
InviteTargetUsersobject for managing the target users list for this invite.Added in version 2.8.
- await edit_target_users(target_users_file)[ソース]¶
This function is a coroutine.
Updates the target users list for this invite.
You must have created this invite or have the
manage_guildpermission to do this.You can use
utils.users_to_csv()to generate a virtual CSV file from a sequence of user IDs.- パラメータ:
target_users_file (
File) -- A CSV file with a single column of user IDs for all the users able to accept this invite.- 例外:
HTTPException -- Updating the target users failed.
Forbidden -- You do not have permissions to edit this invite.
NotFound -- The invite is invalid or expired.
- 戻り値の型:
- await fetch_target_users_job_status()[ソース]¶
This function is a coroutine.
Retrieves the status of the target users processing job for this invite.
You must have created this invite or have the
manage_guildorview_audit_logpermissions. permission to do this.- 戻り値:
The job status information.
- 戻り値の型:
- 例外:
HTTPException -- Fetching the job status failed.
NotFound -- The invite is invalid or expired.
Forbidden -- You do not have permission to view the target users.
- await delete(*, reason=None)[ソース]¶
This function is a coroutine.
Revokes the instant invite.
You must have the
manage_channelspermission to do this.- パラメータ:
reason (
str|None) -- The reason for deleting this invite. Shows up on the audit log.- 例外:
Forbidden -- You do not have permissions to revoke invites.
NotFound -- The invite is invalid or expired.
HTTPException -- Revoking the invite failed.
- set_scheduled_event(event)[ソース]¶
Links the given scheduled event to this invite.
注釈
Scheduled events aren't actually associated with invites on the API. Any guild channel invite can have an event attached to it. Using
abc.GuildChannel.create_invite(),Client.fetch_invite(), or this method, you can link scheduled events.Added in version 2.0.
- パラメータ:
event (
ScheduledEvent) -- The scheduled event object to link.- 戻り値の型:
- asyncas_user_ids
- asyncread
- asyncsave
- class discord.InviteTargetUsers(*, state, invite_code)[ソース]¶
Represents the target users CSV file for an invite.
Added in version 2.8.
- パラメータ:
state (
ConnectionState)invite_code (
str)
- await read()[ソース]¶
This function is a coroutine.
Retrieves this invite's target users CSV file as a
bytesobject.You must have created this invite or the
manage_guildorview_audit_logpermission to do this.- 戻り値:
The content of the CSV file.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the file failed.
NotFound -- This invite does not have any target users set.
Forbidden -- You do not have permission to view the target users.
- await save(fp, *, seek_begin=True)[ソース]¶
This function is a coroutine.
Saves this invite's target users CSV file into a file-like object.
You must have created this invite or the
manage_guildorview_audit_logpermission to do this.- パラメータ:
fp (
str|bytes|PathLike[str] |BufferedIOBase) -- The file-like object to save this file to or the filename to use. If a filename is passed then a file is created with that filename and used instead.seek_begin (
bool) -- Whether to seek to the beginning of the file after saving is successfully done.
- 戻り値:
The number of bytes written.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the file failed.
NotFound -- This invite does not have any target users set.
Forbidden -- You do not have permission to view the target users.
- await as_user_ids()[ソース]¶
This function is a coroutine.
Retrieves a list of user IDs that can accept this invite. This internally reads the invite's target users CSV file and parses the user IDs from it.
You must have created this invite or the
manage_guildorview_audit_logpermission to do this.
- class discord.InviteTargetUsersJobStatus(*, data)[ソース]¶
Represents the status of a target users processing job for an invite.
Added in version 2.8.
- created_at¶
When the job was created.
Noneif the creation time is not available.- Type:
Optional[
datetime.datetime]
- completed_at¶
When the job was completed.
Noneif the job is still processing.- Type:
Optional[
datetime.datetime]
- status¶
The current status of the job.
- パラメータ:
data (
InviteTargetUsersJobStatus)
Role¶
- asyncdelete
- asyncedit
- defis_assignable
- defis_available_for_purchase
- defis_bot_managed
- defis_default
- defis_guild_connections_role
- defis_integration
- defis_premium_subscriber
- class discord.Role(*, guild, state, data)[ソース]¶
Represents a Discord role in a
Guild.- x == y
Checks if two roles are equal.
- x != y
Checks if two roles are not equal.
- x > y
Checks if a role is higher than another in the hierarchy.
- x < y
Checks if a role is lower than another in the hierarchy.
- x >= y
Checks if a role is higher or equal to another in the hierarchy.
- x <= y
Checks if a role is lower or equal to another in the hierarchy.
- hash(x)
Return the role's hash.
- str(x)
Returns the role's name.
- position¶
The position of the role. This number is usually positive. The bottom role has a position of 0.
警告
Multiple roles can have the same position number. As a consequence of this, comparing via role position is prone to subtle bugs if checking for role hierarchy. The recommended and correct way to compare for roles in the hierarchy is using the comparison operators on the role objects themselves.
- Type:
- managed¶
Indicates if the role is managed by the guild. This is true if any of
Role.is_integration(),Role.is_premium_subscriber(),Role.is_bot_managed()orRole.is_guild_connections_role()isTrue.- Type:
- tags¶
The role tags associated with this role. Tags indicate whether the role is a special role, such as but not limited to a bot role or the booster role.
- Type:
Optional[
RoleTags]
- unicode_emoji¶
The role's unicode emoji. Only available to guilds that contain
ROLE_ICONSinGuild.features.Added in version 2.0.
- Type:
Optional[
str]
- colours¶
The role's colours.
Added in version 2.7.
- Type:
- パラメータ:
guild (
Guild)state (
ConnectionState)data (
Role)
- is_bot_managed()[ソース]¶
Whether the role is associated with a bot.
バージョン 2.8 で非推奨: Use
Role.typeinstead.Added in version 1.6.
- 戻り値の型:
Whether the role is the premium subscriber, AKA "boost", role for the guild.
バージョン 2.8 で非推奨: Use
Role.typeinstead.Added in version 1.6.
- 戻り値の型:
- is_integration()[ソース]¶
Whether the guild manages the role through some form of integrations such as Twitch or through guild subscriptions.
バージョン 2.8 で非推奨: Use
Role.typeinstead.Added in version 1.6.
- 戻り値の型:
- is_assignable()[ソース]¶
Whether the role is able to be assigned or removed by the bot. This checks whether all of the following conditions are true:
The role is not the guild's
Guild.default_roleThe role is not managed
The bot has the
manage_rolespermissionThe bot's top role is above this role
Added in version 2.0.
バージョン 2.7.1 で変更: Added check for
manage_rolespermission- 戻り値の型:
- is_available_for_purchase()[ソース]¶
Whether the role is available for purchase.
Returns
Trueif the role is available for purchase, andFalseif it is not available for purchase or if the role is not linked to a guild subscription.バージョン 2.8 で非推奨: Use
Role.typeinstead.Added in version 2.7.
- 戻り値の型:
- is_guild_connections_role()[ソース]¶
Whether the role is a guild connections role.
バージョン 2.8 で非推奨: Use
Role.typeinstead.Added in version 2.7.
- 戻り値の型:
- property permissions: Permissions¶
Returns the role's permissions.
- property colour: Colour¶
Returns the role colour. Equivalent to
colours.primary. An alias exists undercolor.バージョン 2.7 で変更.
- property color: Colour¶
Returns the role's primary color. Equivalent to
colors.primary. An alias exists undercolour.バージョン 2.7 で変更.
- property colors: RoleColours¶
Returns the role's colours. Equivalent to
colours.Added in version 2.7.
- property type: RoleType¶
The type of the role.
This is an alias for
RoleTags.type.Added in version 2.8.
- await edit(*, name=..., permissions=..., colour=..., color=..., colours=..., colors=..., holographic=..., hoist=..., mentionable=..., position=..., reason=..., icon=..., unicode_emoji=...)[ソース]¶
This function is a coroutine.
Edits the role.
You must have the
manage_rolespermission to use this.All fields are optional.
バージョン 1.4 で変更: Can now pass
inttocolourkeyword-only parameter.バージョン 2.0 で変更: Edits are no longer in-place, the newly edited role is returned instead. Added
iconandunicode_emoji.- パラメータ:
name (
str) -- The new role name to change to.permissions (
Permissions) -- The new permissions to change to.colour (
Colour|int) -- The new colour to change to. (aliased to color as well)hoist (
bool) -- Indicates if the role should be shown separately in the member list.mentionable (
bool) -- Indicates if the role should be mentionable by others.position (
int) -- The new role's position. This must be below your top role's position, or it will fail.reason (
str|None) -- The reason for editing this role. Shows up on the audit log.icon (
bytes|None) -- A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed,unicode_emojiis set to None. Only available to guilds that containROLE_ICONSinGuild.features. Could beNoneto denote removal of the icon.unicode_emoji (
str|None) -- The role's unicode emoji. If this argument is passed,iconis set to None. Only available to guilds that containROLE_ICONSinGuild.features.colours (
RoleColours)colors (
RoleColours)holographic (
bool)
- 戻り値:
The newly edited role.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to change the role.
HTTPException -- Editing the role failed.
InvalidArgument -- An invalid position was given or the default role was asked to be moved.
- await delete(*, reason=None)[ソース]¶
This function is a coroutine.
Deletes the role.
You must have the
manage_rolespermission to use this.- パラメータ:
reason (
str|None) -- The reason for deleting this role. Shows up on the audit log.- 例外:
Forbidden -- You do not have permissions to delete the role.
HTTPException -- Deleting the role failed.
- 戻り値の型:
- class discord.RoleTags(data)[ソース]¶
Represents tags on a role.
A role tag is a piece of extra information attached to a managed role that gives it context for the reason the role is managed.
Role tags are a fairly complex topic, since it's usually hard to determine which role tag combination represents which role type. In order to make your life easier, pycord provides a
RoleTags.typeattribute that attempts to determine the role type based on the role tags. Its value is not provided by Discord but is rather computed based on the role tags. If you find an issue, please report it on GitHub. Read this if you need detailed information about how role tags work.Added in version 1.6.
バージョン 2.8 で変更: The type of the role is now determined by the
RoleTags.typeattribute.- subscription_listing_id¶
The subscription SKU and listing ID of the role.
Added in version 2.7.
- Type:
Optional[
int]
- パラメータ:
data (
RoleTags)
- type¶
The type of the role.
Role tags are a fairly complex topic, since it's usually hard to determine which role tag combination represents which role type. In order to make your life easier, pycord provides a
RoleTags.typeattribute that attempts to determine the role type based on the role tags. Its value is not provided by Discord but is rather computed based on the role tags. If you find an issue, please report it on GitHub. Read this if you need detailed information about how role tags work.- Type:
- is_bot_managed()[ソース]¶
Whether the role is associated with a bot.
バージョン 2.8 で非推奨: Use
RoleTags.type == RoleType.APPLICATIONinstead.- 戻り値の型:
Whether the role is the premium subscriber, AKA "boost", role for the guild.
バージョン 2.8 で非推奨: Use
RoleTags.type == RoleType.BOOSTERinstead.- 戻り値の型:
- is_integration()[ソース]¶
Whether the guild manages the role through some form of integrations such as Twitch or through guild subscriptions.
バージョン 2.8 で非推奨: Use
RoleTags.type in (RoleType.INTEGRATION, RoleType.PREMIUM_SUBSCRIPTION_TIER, RoleType.DRAFT_PREMIUM_SUBSCRIPTION_TIER)instead.- 戻り値の型:
- is_available_for_purchase()[ソース]¶
Whether the role is available for purchase.
Returns
Trueif the role is available for purchase, andFalseif it is not available for purchase or if the role is not linked to a guild subscription.バージョン 2.8 で非推奨: Use
RoleTags.type == RoleType.PREMIUM_SUBSCRIPTION_TIERinstead.Added in version 2.7.
- 戻り値の型:
- class discord.RoleColours(primary, secondary=None, tertiary=None)[ソース]¶
Represents a role's gradient colours.
Added in version 2.7.
- tertiary¶
The tertiary colour of the role. At the moment, only 16761760 is allowed.
- Type:
Optional[
Colour]
- classmethod default()[ソース]¶
Returns a default
RoleColoursobject with no colours set.- 戻り値の型:
- classmethod holographic()[ソース]¶
Returns a
RoleColoursthat makes the role look holographic.Currently holographic roles are only supported with colours 11127295, 16759788, and 16761760.
- 戻り値の型:
- defget
- class discord.GuildRoleCounts[ソース]¶
A dictionary subclass that maps role IDs to their member counts.
This class allows accessing member counts by either role ID (
int) or by a Snowflake object (which has an.idattribute).Added in version 2.7.
Scheduled Event¶
- class discord.ScheduledEvent(*, state, guild, creator, data)[ソース]¶
Represents a Discord Guild Scheduled Event.
- x == y
Checks if two scheduled events are equal.
- x != y
Checks if two scheduled events are not equal.
- hash(x)
Returns the scheduled event's hash.
- str(x)
Returns the scheduled event's name.
Added in version 2.0.
- start_time¶
The time when the event will start
- Type:
- end_time¶
The time when the event is supposed to end.
- Type:
Optional[
datetime.datetime]
- status¶
The status of the scheduled event.
- Type:
- location¶
The location of the event. See
ScheduledEventLocationfor more information.- Type:
- subscriber_count¶
The number of users that have marked themselves as interested in the event.
- Type:
Optional[
int]
- creator_id¶
The ID of the user who created the event. It may be
Nonebecause events created before October 25th, 2021 haven't had their creators tracked.- Type:
Optional[
int]
- privacy_level¶
The privacy level of the event. Currently, the only possible value is
ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to use this attribute.
- property interested: int | None¶
An alias to
subscriber_count
- property cover: Asset | None¶
Returns the scheduled event cover image asset, if available.
バージョン 2.7 で非推奨: Use the
imageproperty instead.
- await edit(*, reason=None, name=..., description=..., status=..., location=..., start_time=..., end_time=..., cover=..., image=..., privacy_level=('guild_only', 2))[ソース]¶
This function is a coroutine.
Edits the Scheduled Event's data
All parameters are optional unless
location.typeisScheduledEventLocationType.external, thenend_timeis required.Will return a new
ScheduledEventobject if applicable.- パラメータ:
name (
str) -- The new name of the event.description (
str) -- The new description of the event.location (
str|int|VoiceChannel|StageChannel|ScheduledEventLocation) -- The location of the event.status (
int|ScheduledEventStatus) -- The status of the event. It is recommended, however, to usestart(),complete(), andcancel()to edit statuses instead.start_time (
datetime) -- The new starting time for the event.end_time (
datetime) -- The new ending time of the event.privacy_level (
ScheduledEventPrivacyLevel) -- The privacy level of the event. Currently, the only possible value isScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.image (
bytes|None) -- The cover image of the scheduled event.The cover image of the scheduled event.
バージョン 2.7 で非推奨: Use the image argument instead.
- 戻り値:
The newly updated scheduled event object. This is only returned when certain fields are updated.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the Manage Events permission.
HTTPException -- The operation failed.
- await delete()[ソース]¶
This function is a coroutine.
Deletes the scheduled event.
- 例外:
Forbidden -- You do not have the Manage Events permission.
HTTPException -- The operation failed.
- 戻り値の型:
- await start(*, reason=None)[ソース]¶
This function is a coroutine.
Starts the scheduled event. Shortcut from
edit().注釈
This method can only be used if
statusisScheduledEventStatus.scheduled.- パラメータ:
- 戻り値:
The newly updated scheduled event object.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the Manage Events permission.
HTTPException -- The operation failed.
- await complete(*, reason=None)[ソース]¶
This function is a coroutine.
Ends/completes the scheduled event. Shortcut from
edit().注釈
This method can only be used if
statusisScheduledEventStatus.active.- パラメータ:
- 戻り値:
The newly updated scheduled event object.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the Manage Events permission.
HTTPException -- The operation failed.
- await cancel(*, reason=None)[ソース]¶
This function is a coroutine.
Cancels the scheduled event. Shortcut from
edit().注釈
This method can only be used if
statusisScheduledEventStatus.scheduled.- パラメータ:
- 戻り値:
The newly updated scheduled event object.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the Manage Events permission.
HTTPException -- The operation failed.
- subscribers(*, limit=100, as_member=False, before=None, after=None)[ソース]¶
Returns an
AsyncIteratorrepresenting the users or members subscribed to the event.The
afterandbeforeparameters must represent member or user objects and meet theabc.Snowflakeabc.注釈
Even is
as_memberis set toTrue, if the user is outside the guild, it will be aUserobject.- パラメータ:
limit (
int|None) -- The maximum number of results to return.as_member (
bool) -- Whether to fetchMemberobjects instead of user objects. There may still beUserobjects if the user is outside the guild.before (
Snowflake|datetime|None) -- Retrieves users before this date or object. 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 (
Snowflake|datetime|None) -- Retrieves users after this date or object. 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.
- 列挙:
Union[
User,Member] -- The subscribedMember. Ifas_memberis set toFalseor the user is outside the guild, it will be aUserobject.- 例外:
HTTPException -- Fetching the subscribed users failed.
- 戻り値の型:
ScheduledEventSubscribersIterator
サンプル
Usage
async for user in event.subscribers(limit=100): print(user.name)
Flattening into a list:
users = await event.subscribers(limit=100).flatten() # users is now a list of User...
Getting members instead of user objects:
async for member in event.subscribers(limit=100, as_member=True): print(member.display_name)
- class discord.ScheduledEventLocation(*, state, value)[ソース]¶
Represents a scheduled event's location.
Setting the
valueto its corresponding type will set the location type automatically:Type of Input
Location Type
ScheduledEventLocationType.stage_instanceScheduledEventLocationType.voiceScheduledEventLocationType.externalAdded in version 2.0.
- value¶
The actual location of the scheduled event.
- Type:
Union[
str,StageChannel,VoiceChannel,Object]
- type¶
The type of location.
Welcome Screen¶
- asyncedit
- class discord.WelcomeScreen(data, guild)[ソース]¶
Represents the welcome screen of a guild.
Added in version 2.0.
- welcome_channels¶
A list of channels displayed on welcome screen.
- Type:
List[
WelcomeScreenChannel]
- パラメータ:
data (
WelcomeScreen)guild (
Guild)
- await edit(**options)[ソース]¶
This function is a coroutine.
Edits the welcome screen.
You must have the
manage_guildpermission in the guild to do this.- パラメータ:
description (Optional[
str]) -- The new description of welcome screen.welcome_channels (Optional[List[
WelcomeScreenChannel]]) -- The welcome channels. The order of the channels would be same as the passed list order.enabled (Optional[
bool]) -- Whether the welcome screen should be displayed.reason (Optional[
str]) -- The reason that shows up on Audit log.
- 例外:
HTTPException -- Editing the welcome screen failed somehow.
Forbidden -- You don't have permissions to edit the welcome screen.
NotFound -- This welcome screen does not exist.
サンプル
rules_channel = guild.get_channel(12345678) announcements_channel = guild.get_channel(87654321) custom_emoji = utils.get(guild.emojis, name='loudspeaker') await welcome_screen.edit( description='This is a very cool community server!', welcome_channels=[ WelcomeChannel(channel=rules_channel, description='Read the rules!', emoji='👨🏫'), WelcomeChannel(channel=announcements_channel, description='Watch out for announcements!', emoji=custom_emoji), ] )
注釈
Welcome channels can only accept custom emojis if
premium_tieris level 2 or above.
- class discord.WelcomeScreenChannel(channel, description, emoji)[ソース]¶
Represents a welcome channel displayed on
WelcomeScreenAdded in version 2.0.
- channel¶
The channel that is being referenced.
- Type:
- emoji¶
The emoji of the channel that is shown on welcome screen.
- Type:
Union[
GuildEmoji,PartialEmoji,str]
- パラメータ:
channel (
Snowflake)description (
str)emoji (
GuildEmoji|PartialEmoji|str)
Onboarding¶
- asyncadd_prompt
- asyncappend_prompt
- asyncdelete_prompt
- asyncedit
- asyncget_prompt
- class discord.Onboarding(data, guild)[ソース]¶
Represents the onboarding flow for a guild.
Added in version 2.5.
- prompts¶
A list of prompts displayed in the onboarding flow.
- Type:
List[
OnboardingPrompt]
- mode¶
The current onboarding mode.
- Type:
- パラメータ:
data (
Onboarding)guild (
Guild)
- property default_channels: list[TextChannel | ForumChannel | VoiceChannel | Object][ソース]¶
The channels that members are opted into by default.
If a channel is not found in the guild's cache, then it will be returned as an
Object.
- await edit(*, prompts=..., default_channels=..., enabled=..., mode=..., reason=...)[ソース]¶
This function is a coroutine.
Edits this onboarding flow.
You must have the
manage_guildandmanage_rolespermissions in the guild to do this.- パラメータ:
prompts (
list[OnboardingPrompt] |None) -- The new list of prompts for this flow.default_channels (
list[Snowflake] |None) -- The new default channels that users are opted into.enabled (
bool|None) -- Whether onboarding should be enabled. Setting this toTruerequires the guild to haveCOMMUNITYinfeaturesand at least 7default_channels.mode (
OnboardingMode|None) -- The new onboarding mode.reason (
str|None) -- The reason for editing this onboarding flow. Shows up on the audit log.
- 戻り値:
The updated onboarding flow.
- 戻り値の型:
- 例外:
HTTPException -- Editing the onboarding flow failed somehow.
Forbidden -- You don't have permissions to edit the onboarding flow.
- await add_prompt(type, title, options, single_select, required, in_onboarding, *, reason=None)[ソース]¶
This function is a coroutine.
Adds a new onboarding prompt.
You must have the
manage_guildandmanage_rolespermissions in the guild to do this.- パラメータ:
type (
PromptType) -- The type of onboarding prompt.title (
str) -- The prompt's title.options (
list[PromptOption]) -- The list of options available in the prompt.single_select (
bool) -- Whether the user is limited to selecting one option on this prompt.required (
bool) -- Whether the user is required to answer this prompt.in_onboarding (
bool) -- Whether this prompt is displayed in the initial onboarding flow.reason (
str|None) -- The reason for adding this prompt. Shows up on the audit log.
- 戻り値:
The updated onboarding flow.
- 戻り値の型:
- 例外:
HTTPException -- Editing the onboarding flow failed somehow.
Forbidden -- You don't have permissions to edit the onboarding flow.
- await append_prompt(prompt, *, reason=None)[ソース]¶
This function is a coroutine.
Append an onboarding prompt onto this flow.
You must have the
manage_guildandmanage_rolespermissions in the guild to do this.- パラメータ:
prompt (
OnboardingPrompt) -- The onboarding prompt to append.reason (
str|None) -- The reason for appending this prompt. Shows up on the audit log.
- 戻り値:
The updated onboarding flow.
- 戻り値の型:
- 例外:
HTTPException -- Editing the onboarding flow failed somehow.
Forbidden -- You don't have permissions to edit the onboarding flow.
- get_prompt(id)[ソース]¶
This function is a coroutine.
Get an onboarding prompt with the given ID.
- パラメータ:
id (
int) -- The ID of the prompt to get.- 戻り値:
The matching prompt, or None if it didn't exist.
- 戻り値の型:
- await delete_prompt(id, *, reason=...)[ソース]¶
This function is a coroutine.
Delete an onboarding prompt with the given ID.
You must have the
manage_guildandmanage_rolespermissions in the guild to do this.- パラメータ:
- 戻り値:
The updated onboarding flow.
- 戻り値の型:
- 例外:
ValueError -- No prompt with this ID exists.
HTTPException -- Editing the onboarding flow failed somehow.
Forbidden -- You don't have permissions to edit the onboarding flow.
- class discord.OnboardingPrompt(type, title, options, single_select, required, in_onboarding, id=None)[ソース]¶
Represents an onboarding prompt displayed in
Onboarding.Added in version 2.5.
- type¶
The type of onboarding prompt.
- Type:
- options¶
The list of options available in the prompt.
- Type:
List[
PromptOption]
- class discord.PromptOption(title, channels=None, roles=None, description=None, emoji=None, id=None)[ソース]¶
Represents an onboarding prompt option displayed in
OnboardingPrompt.Added in version 2.5.
- channels¶
The channels assigned to the user when they select this option.
- Type:
List[
Snowflake]
- roles¶
The roles assigned to the user when they select this option.
- Type:
List[
Snowflake]
- emoji¶
The emoji displayed with the option.
- Type:
Union[
GuildEmoji,PartialEmoji]
Integration¶
- class discord.Integration(*, data, guild)[ソース]¶
Represents a guild integration.
Added in version 1.4.
- account¶
The account linked to this integration.
- Type:
- パラメータ:
data (
BaseIntegration|StreamIntegration|BotIntegration)guild (
Guild)
- await delete(*, reason=None)[ソース]¶
This function is a coroutine.
Deletes the integration.
You must have the
manage_guildpermission to do this.- パラメータ:
The reason the integration was deleted. Shows up on the audit log.
Added in version 2.0.
- 例外:
Forbidden -- You do not have permission to delete the integration.
HTTPException -- Deleting the integration failed.
- 戻り値の型:
- class discord.IntegrationAccount(data)[ソース]¶
Represents an integration account.
Added in version 1.4.
- パラメータ:
data (
IntegrationAccount)
- class discord.BotIntegration(*, data, guild)[ソース]¶
Represents a bot integration on discord.
Added in version 2.0.
- account¶
The integration account information.
- Type:
- application¶
The application tied to this integration.
- Type:
- パラメータ:
data (
BaseIntegration|StreamIntegration|BotIntegration)guild (
Guild)
- class discord.IntegrationApplication(*, data, state)[ソース]¶
Represents an application for a bot integration.
Added in version 2.0.
- パラメータ:
data (
IntegrationApplication)
- class discord.StreamIntegration(*, data, guild)[ソース]¶
Represents a stream integration for Twitch or YouTube.
Added in version 2.0.
- enable_emoticons¶
Whether emoticons should be synced for this integration (currently twitch only).
- Type:
Optional[
bool]
- expire_behaviour¶
The behaviour of expiring subscribers. Aliased to
expire_behavioras well.- Type:
- account¶
The integration account information.
- Type:
- synced_at¶
An aware UTC datetime representing when the integration was last synced.
- Type:
- パラメータ:
data (
BaseIntegration|StreamIntegration|BotIntegration)guild (
Guild)
- property expire_behavior: ExpireBehaviour¶
An alias for
expire_behaviour.
- await edit(*, expire_behaviour=..., expire_grace_period=..., enable_emoticons=...)[ソース]¶
This function is a coroutine.
Edits the integration.
You must have the
manage_guildpermission to do this.- パラメータ:
expire_behaviour (
ExpireBehaviour) -- The behaviour when an integration subscription lapses. Aliased toexpire_behavioras well.expire_grace_period (
int) -- The period (in days) where the integration will ignore lapsed subscriptions.enable_emoticons (
bool) -- Where emoticons should be synced for this integration (currently twitch only).
- 例外:
Forbidden -- You do not have permission to edit the integration.
HTTPException -- Editing the guild failed.
InvalidArgument --
expire_behaviourdid not receive aExpireBehaviour.
- 戻り値の型:
- await sync()[ソース]¶
This function is a coroutine.
Syncs the integration.
You must have the
manage_guildpermission to do this.- 例外:
Forbidden -- You do not have permission to sync the integration.
HTTPException -- Syncing the integration failed.
- 戻り値の型:
Widget¶
- asyncfetch_invite
- class discord.Widget(*, state, data)[ソース]¶
Represents a
Guildwidget.- x == y
Checks if two widgets are the same.
- x != y
Checks if two widgets are not the same.
- str(x)
Returns the widget's JSON URL.
- channels¶
The accessible voice channels in the guild.
- Type:
List[
WidgetChannel]
- members¶
The online members in the server. Offline members do not appear in the widget.
注釈
Due to a Discord limitation, if this data is available the users will be "anonymized" with linear IDs and discriminator information being incorrect. Likewise, the number of members retrieved is capped.
- Type:
List[
Member]
- パラメータ:
state (
ConnectionState)data (
Widget)
- await fetch_invite(*, with_counts=True)[ソース]¶
This function is a coroutine.
Retrieves an
Invitefrom the widget's invite URL. This is the same asClient.fetch_invite(); the invite code is abstracted away.- パラメータ:
with_counts (
bool) -- Whether to include count information in the invite. This fills theInvite.approximate_member_countandInvite.approximate_presence_countfields.- 戻り値:
The invite from the widget's invite URL.
- 戻り値の型:
- class discord.WidgetChannel(id, name, position)[ソース]¶
Represents a "partial" widget channel.
- x == y
Checks if two partial channels are the same.
- x != y
Checks if two partial channels are not the same.
- hash(x)
Return the partial channel's hash.
- str(x)
Returns the partial channel's name.
- defmentioned_in
- class discord.WidgetMember(*, state, data, connected_channel=None)[ソース]¶
Represents a "partial" member of the widget's guild.
- x == y
Checks if two widget members are the same.
- x != y
Checks if two widget members are not the same.
- hash(x)
Return the widget member's hash.
- str(x)
Returns the widget member's name#discriminator.
- activity¶
The member's activity.
- Type:
Optional[Union[
BaseActivity,Spotify]]
- connected_channel¶
Which channel the member is connected to.
- Type:
Optional[
WidgetChannel]
- パラメータ:
state (
ConnectionState)data (
WidgetMember)connected_channel (
WidgetChannel|None)
- property accent_color: Colour | None¶
Returns the user's accent color, if applicable.
There is an alias for this named
accent_colour.Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property accent_colour: Colour | None¶
Returns the user's accent colour, if applicable.
There is an alias for this named
accent_color.Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property avatar_decoration: Asset | None¶
Returns the user's avatar decoration, if available.
Added in version 2.5.
- property banner: Asset | None¶
Returns the user's banner asset, if available.
Added in version 2.0.
注釈
This information is only available via
Client.fetch_user().
- property collectibles: Collectibles | None¶
Returns the user's equipped collectibles.
Added in version 2.8.
- property color: Colour¶
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.
- property colour: 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.
- property created_at: datetime¶
Returns the user's creation time in UTC.
This is when the user's Discord account was created.
- property default_avatar: Asset¶
Returns the default avatar for a given user. This is calculated by the user's ID if they're on the new username system, otherwise their discriminator.
- property display_avatar: Asset¶
Returns the user's display avatar.
Returns the user's uploaded avatar. If the user has not uploaded any avatar, their default avatar is returned instead.
Added in version 2.0.
- property jump_url: str¶
Returns a URL that allows the client to jump to the user.
Added in version 2.0.
- mentioned_in(message)¶
Checks if the user is mentioned in the specified message.
- property nameplate: Nameplate | None¶
The user's nameplate, if the user has one equipped. Alias for
User.collectibles.nameplate.Added in version 2.7.
バージョン 2.8 で変更: Now an alias for
User.collectibles.nameplate.
- property public_flags: PublicUserFlags¶
The publicly available flags the user has.
Threads¶
- applied_tags
- archive_timestamp
- archived
- auto_archive_duration
- category
- category_id
- created_at
- flags
- guild
- id
- invitable
- jump_url
- last_message
- last_message_id
- locked
- me
- member_count
- members
- mention
- message_count
- name
- owner
- owner_id
- parent
- parent_id
- slowmode_delay
- starting_message
- total_message_sent
- type
- asyncadd_user
- asyncarchive
- defcan_send
- asyncdelete
- asyncdelete_messages
- asyncedit
- asyncfetch_members
- asyncfetch_message
- defget_partial_message
- defhistory
- defis_news
- defis_nsfw
- defis_pinned
- defis_private
- asyncjoin
- asyncleave
- defpermissions_for
- defpins
- asyncpurge
- asyncremove_user
- asyncsend
- asynctrigger_typing
- deftyping
- asyncunarchive
- class discord.Thread(*, guild, state, data)[ソース]¶
Represents a Discord thread.
- x == y
Checks if two threads are equal.
- x != y
Checks if two threads are not equal.
- hash(x)
Returns the thread's hash.
- str(x)
Returns the thread's name.
Added in version 2.0.
- parent_id¶
The parent
TextChannelID this thread belongs to.- Type:
- last_message_id¶
The last message ID of the message sent to this thread. It may not point to an existing or valid message.
- Type:
Optional[
int]
- slowmode_delay¶
The number of seconds a member must wait between sending messages in this thread. A value of 0 denotes that it is disabled. Bots and users with
manage_channelsormanage_messagesbypass slowmode.- Type:
- me¶
A thread member representing yourself, if you've joined the thread. This could not be available.
- Type:
Optional[
ThreadMember]
- invitable¶
Whether non-moderators can add other non-moderators to this thread. This is always
Truefor public threads.- Type:
- auto_archive_duration¶
The duration in minutes until the thread is automatically archived due to inactivity. Usually a value of 60, 1440, 4320 and 10080.
- Type:
- archive_timestamp¶
An aware timestamp of when the thread's archived status was last updated in UTC.
- Type:
- created_at¶
An aware timestamp of when the thread was created. Only available for threads created after 2022-01-09.
- Type:
Optional[
datetime.datetime]
- flags¶
Extra features of the thread.
Added in version 2.0.
- Type:
- total_message_sent¶
Number of messages ever sent in a thread. It's similar to message_count on message creation, but will not decrement the number when a message is deleted.
Added in version 2.3.
- Type:
- パラメータ:
guild (
Guild)state (
ConnectionState)data (
Thread)
- async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- async with typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- property type: ChannelType¶
The channel's Discord type.
- property parent: TextChannel | ForumChannel | None¶
The parent channel this thread belongs to.
- property jump_url: str¶
Returns a URL that allows the client to jump to the thread.
Added in version 2.0.
- property members: list[ThreadMember]¶
A list of thread members in this thread, including the bot if it is a member of this thread.
This requires
Intents.membersto be properly filled. Most of the time however, this data is not provided by the gateway and a call tofetch_members()is needed.
- property applied_tags: list[ForumTag]¶
A list of tags applied to this thread.
This is only available for threads in forum or media channels.
- Type:
List[
ForumTag]
- property last_message: Message | None¶
Returns the last message from this thread in cache.
The message might not be valid or point to an existing message.
Reliable Fetching
For a slightly more reliable method of fetching the last message, consider using either
history()orfetch_message()with thelast_message_idattribute.- 戻り値:
The last message in this channel or
Noneif not found.- 戻り値の型:
Optional[
Message]
- property category: CategoryChannel | None¶
The category channel the parent channel belongs to, if applicable.
- 戻り値:
The parent channel's category.
- 戻り値の型:
Optional[
CategoryChannel]- 例外:
ClientException -- The parent channel was not cached and returned
None.
- property category_id: int | None¶
The category channel ID the parent channel belongs to, if applicable.
- 戻り値:
The parent channel's category ID.
- 戻り値の型:
Optional[
int]- 例外:
ClientException -- The parent channel was not cached and returned
None.
- property starting_message: Message | None¶
Returns the message that started this thread.
The message might not be valid or point to an existing message.
注釈
The ID for this message is the same as the thread ID.
- 戻り値:
The message that started this thread or
Noneif not found in the cache.- 戻り値の型:
Optional[
Message]
- is_pinned()[ソース]¶
Whether the thread is pinned to the top of its parent forum or media channel.
Added in version 2.3.
- 戻り値の型:
- is_private()[ソース]¶
Whether the thread is a private thread.
A private thread is only viewable by those that have been explicitly invited or have
manage_threads.- 戻り値の型:
- is_news()[ソース]¶
Whether the thread is a news thread.
A news thread is a thread that has a parent that is a news channel, i.e.
TextChannel.is_news()isTrue.- 戻り値の型:
- is_nsfw()[ソース]¶
Whether the thread is NSFW or not.
An NSFW thread is a thread that has a parent that is an NSFW channel, i.e.
TextChannel.is_nsfw()isTrue.- 戻り値の型:
- permissions_for(obj, /)[ソース]¶
Handles permission resolution for the
MemberorRole.Since threads do not have their own permissions, they inherit them from the parent channel. This is a convenience method for calling
permissions_for()on the parent channel.- パラメータ:
obj (
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.- 戻り値:
The resolved permissions for the member or role.
- 戻り値の型:
- 例外:
ClientException -- The parent channel was not cached and returned
None
- await delete_messages(messages, *, reason=None)[ソース]¶
This function is a coroutine.
Deletes a list of messages. This is similar to
Message.delete()except it bulk deletes multiple messages.As a special case, if the number of messages is 0, then nothing is done. If the number of messages is 1 then single message delete is done. If it's more than two, then bulk delete is used.
You cannot bulk delete more than 100 messages or messages that are older than 14 days old.
You must have the
manage_messagespermission to use this.Usable only by bot accounts.
- パラメータ:
- 例外:
ClientException -- The number of messages to delete was more than 100.
Forbidden -- You do not have proper permissions to delete the messages, or you're not using a bot account.
NotFound -- If single delete, then the message was already deleted.
HTTPException -- Deleting the messages failed.
- 戻り値の型:
- await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True, reason=None)[ソース]¶
This function is a coroutine.
Purges a list of messages that meet the criteria given by the predicate
check. If acheckis not provided then all messages are deleted without discrimination.You must have the
manage_messagespermission to delete messages even if they are your own (unless you are a user account). Theread_message_historypermission is also needed to retrieve message history.- パラメータ:
limit (
int|None) -- The number of messages to search through. This is not the number of messages that will be deleted, though it can be.check (
Callable[[Message],bool]) -- The function used to check if a message should be deleted. It must take aMessageas its sole parameter.before (
Snowflake|datetime|None) -- Same asbeforeinhistory().after (
Snowflake|datetime|None) -- Same asafterinhistory().around (
Snowflake|datetime|None) -- Same asaroundinhistory().oldest_first (
bool|None) -- Same asoldest_firstinhistory().bulk (
bool) -- IfTrue, use bulk delete. Setting this toFalseis useful for mass-deleting a bot's own messages withoutPermissions.manage_messages. WhenTrue, will fall back to single delete if messages are older than two weeks.reason (
str|None) -- The reason for deleting the messages. Shows up on the audit log.
- 戻り値:
The list of messages that were deleted.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to do the actions required.
HTTPException -- Purging the messages failed.
サンプル
Deleting bot's messages
def is_me(m): return m.author == client.user deleted = await thread.purge(limit=100, check=is_me) await thread.send(f'Deleted {len(deleted)} message(s)')
- await edit(*, name=..., archived=..., locked=..., invitable=..., slowmode_delay=..., auto_archive_duration=..., pinned=..., applied_tags=..., reason=None)[ソース]¶
This function is a coroutine.
Edits the thread.
Editing the thread requires
Permissions.manage_threads. The thread creator can also editname,archivedorauto_archive_duration. Note that if the thread is locked then only those withPermissions.manage_threadscan send messages in it or unarchive a thread.The thread must be unarchived to be edited.
- パラメータ:
name (
str) -- The new name of the thread.archived (
bool) -- Whether to archive the thread or not.locked (
bool) -- Whether to lock the thread or not.invitable (
bool) -- Whether non-moderators can add other non-moderators to this thread. Only available for private threads.auto_archive_duration (
Literal[60,1440,4320,10080] |ThreadArchiveDuration) -- The new duration in minutes before a thread is automatically archived for inactivity. Must be one of60,1440,4320, or10080.ThreadArchiveDurationcan be used alternatively.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this thread, in seconds. A value of0disables slowmode. The maximum value possible is21600.reason (
str|None) -- The reason for editing this thread. Shows up on the audit log.pinned (
bool) -- Whether to pin the thread or not. This only works if the thread is part of a forum or media channel.applied_tags (
list[ForumTag]) --The set of tags to apply to the thread. Each tag object should have an ID set.
Added in version 2.3.
- 戻り値:
The newly edited thread.
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to edit the thread.
HTTPException -- Editing the thread failed.
- await archive(locked=...)[ソース]¶
This function is a coroutine.
Archives the thread. This is a shorthand of
edit().
- await unarchive()[ソース]¶
This function is a coroutine.
Unarchives the thread. This is a shorthand of
edit().- 戻り値:
The updated thread.
- 戻り値の型:
- await join()[ソース]¶
This function is a coroutine.
Joins this thread.
You must have
send_messages_in_threadsto join a thread. If the thread is private,manage_threadsis also needed.- 例外:
Forbidden -- You do not have permissions to join the thread.
HTTPException -- Joining the thread failed.
- await leave()[ソース]¶
This function is a coroutine.
Leaves this thread.
- 例外:
HTTPException -- Leaving the thread failed.
- await add_user(user)[ソース]¶
This function is a coroutine.
Adds a user to this thread.
You must have
send_messages_in_threadsto add a user to a public thread. If the thread is private andinvitableisFalse, thenmanage_threadsis required.- パラメータ:
user (
Snowflake) -- The user to add to the thread.- 例外:
Forbidden -- You do not have permissions to add the user to the thread.
HTTPException -- Adding the user to the thread failed.
- await remove_user(user)[ソース]¶
This function is a coroutine.
Removes a user from this thread.
You must have
manage_threadsor be the creator of the thread to remove a user.- パラメータ:
user (
Snowflake) -- The user to remove from the thread.- 例外:
Forbidden -- You do not have permissions to remove the user from the thread.
HTTPException -- Removing the user from the thread failed.
- await fetch_members()[ソース]¶
This function is a coroutine.
Retrieves all
ThreadMemberthat are in this thread.This requires
Intents.membersto get information about members other than yourself.- 戻り値:
All thread members in the thread.
- 戻り値の型:
- 例外:
HTTPException -- Retrieving the members failed.
- await delete()[ソース]¶
This function is a coroutine.
Deletes this thread.
You must have
manage_threadsto delete threads.- 例外:
Forbidden -- You do not have permissions to delete this thread.
HTTPException -- Deleting the thread failed.
- get_partial_message(message_id, /)[ソース]¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
Added in version 2.0.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- class discord.ThreadMember(parent, data)[ソース]¶
Represents a Discord thread member.
- x == y
Checks if two thread members are equal.
- x != y
Checks if two thread members are not equal.
- hash(x)
Returns the thread member's hash.
- str(x)
Returns the thread member's name.
Added in version 2.0.
- joined_at¶
The time the member joined the thread in UTC.
- Type:
- パラメータ:
parent (
Thread)data (
ThreadMember)
Stages¶
- bitrate
- category
- category_id
- changed_roles
- created_at
- flags
- guild
- id
- instance
- jump_url
- last_message
- last_message_id
- listeners
- members
- mention
- moderators
- name
- nsfw
- overwrites
- permissions_synced
- position
- requesting_to_speak
- rtc_region
- slowmode_delay
- speakers
- topic
- type
- user_limit
- video_quality_mode
- voice_states
- defcan_send
- asyncclone
- asyncconnect
- asynccreate_instance
- asynccreate_invite
- asynccreate_webhook
- asyncdelete
- asyncdelete_messages
- asyncedit
- asyncfetch_instance
- asyncfetch_message
- defget_partial_message
- defhistory
- asyncinvites
- defis_nsfw
- asyncmove
- defoverwrites_for
- defpermissions_for
- defpins
- asyncpurge
- asyncsend
- asyncset_permissions
- asynctrigger_typing
- deftyping
- asyncwebhooks
- class discord.StageChannel(*, state, guild, data)[ソース]¶
Represents a Discord guild stage channel.
Added in version 1.7.
- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the channel's hash.
- str(x)
Returns the channel's name.
- position¶
The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0. Can be
Noneif the channel was received in an interaction.- Type:
Optional[
int]
- rtc_region¶
The region for the stage channel's voice communication. A value of
Noneindicates automatic voice region detection.- Type:
Optional[
VoiceRegion]
- video_quality_mode¶
The camera video quality for the stage channel's participants.
Added in version 2.0.
- Type:
- flags¶
Extra features of the channel.
Added in version 2.0.
- Type:
- last_message_id¶
The ID of the last message sent to this channel. It may not always point to an existing or valid message. .. versionadded:: 2.5
- Type:
Optional[
int]
- slowmode_delay¶
Specifies the slowmode rate limit for user in this channel, in seconds. The maximum value possible is 21600.
- Type:
- パラメータ:
state (
ConnectionState)guild (
Guild)data (
VoiceChannel|StageChannel)
- property requesting_to_speak: list[Member]¶
A list of members who are requesting to speak in the stage channel.
- property speakers: list[Member]¶
A list of members who have been permitted to speak in the stage channel.
Added in version 2.0.
- property listeners: list[Member]¶
A list of members who are listening in the stage channel.
Added in version 2.0.
- property last_message: Message | None¶
Fetches the last message from this channel in cache.
The message might not be valid or point to an existing message.
Reliable Fetching
For a slightly more reliable method of fetching the last message, consider using either
history()orfetch_message()with thelast_message_idattribute.- 戻り値:
The last message in this channel or
Noneif not found.- 戻り値の型:
Optional[
Message]
- get_partial_message(message_id, /)[ソース]¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
Added in version 1.6.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- await delete_messages(messages, *, reason=None)[ソース]¶
This function is a coroutine.
Deletes a list of messages. This is similar to
Message.delete()except it bulk deletes multiple messages.As a special case, if the number of messages is 0, then nothing is done. If the number of messages is 1 then single message delete is done. If it's more than two, then bulk delete is used.
You cannot bulk delete more than 100 messages or messages that are older than 14 days old.
You must have the
manage_messagespermission to use this.- パラメータ:
- 例外:
ClientException -- The number of messages to delete was more than 100.
Forbidden -- You do not have proper permissions to delete the messages.
NotFound -- If single delete, then the message was already deleted.
HTTPException -- Deleting the messages failed.
- 戻り値の型:
- await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True, reason=None)[ソース]¶
This function is a coroutine.
Purges a list of messages that meet the criteria given by the predicate
check. If acheckis not provided then all messages are deleted without discrimination.You must have the
manage_messagespermission to delete messages even if they are your own. Theread_message_historypermission is also needed to retrieve message history.- パラメータ:
limit (
int|None) -- The number of messages to search through. This is not the number of messages that will be deleted, though it can be.check (
Callable[[Message],bool]) -- The function used to check if a message should be deleted. It must take aMessageas its sole parameter.before (
Snowflake|datetime|None) -- Same asbeforeinhistory().after (
Snowflake|datetime|None) -- Same asafterinhistory().around (
Snowflake|datetime|None) -- Same asaroundinhistory().oldest_first (
bool|None) -- Same asoldest_firstinhistory().bulk (
bool) -- IfTrue, use bulk delete. Setting this toFalseis useful for mass-deleting a bot's own messages withoutPermissions.manage_messages. WhenTrue, will fall back to single delete if messages are older than two weeks.reason (
str|None) -- The reason for deleting the messages. Shows up on the audit log.
- 戻り値:
The list of messages that were deleted.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to do the actions required.
HTTPException -- Purging the messages failed.
サンプル
Deleting bot's messages
def is_me(m): return m.author == client.user deleted = await channel.purge(limit=100, check=is_me) await channel.send(f'Deleted {len(deleted)} message(s)')
- await webhooks()[ソース]¶
This function is a coroutine.
Gets the list of webhooks from this channel.
Requires
manage_webhookspermissions.
- await create_webhook(*, name, avatar=None, reason=None)[ソース]¶
This function is a coroutine.
Creates a webhook for this channel.
Requires
manage_webhookspermissions.バージョン 1.1 で変更: Added the
reasonkeyword-only parameter.- パラメータ:
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Creating the webhook failed.
Forbidden -- You do not have permissions to create a webhook.
- property moderators: list[Member]¶
A list of members who are moderating the stage channel.
Added in version 2.0.
- property type: ChannelType¶
The channel's Discord type.
- await clone(*, name=None, reason=None)[ソース]¶
This function is a coroutine.
Clones this channel. This creates a channel with the same properties as this channel.
You must have the
manage_channelspermission to do this.Added in version 1.1.
- パラメータ:
- 戻り値:
The channel that was created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
- property instance: StageInstance | None¶
The running stage instance of the stage channel.
Added in version 2.0.
- await create_instance(*, topic, privacy_level=..., reason=None, send_notification=False)[ソース]¶
This function is a coroutine.
Create a stage instance.
You must have the
manage_channelspermission to use this.Added in version 2.0.
- パラメータ:
topic (
str) -- The stage instance's topic.privacy_level (
StagePrivacyLevel) -- The stage instance's privacy level. Defaults toStagePrivacyLevel.guild_only.reason (
str|None) -- The reason the stage instance was created. Shows up on the audit log.send_notification (
bool|None) -- Send a notification to everyone in the server that the stage instance has started. Defaults toFalse. Requires themention_everyonepermission.
- 戻り値:
The newly created stage instance.
- 戻り値の型:
- 例外:
InvalidArgument -- If the
privacy_levelparameter is not the proper type.Forbidden -- You do not have permissions to create a stage instance.
HTTPException -- Creating a stage instance failed.
- await fetch_instance()[ソース]¶
This function is a coroutine.
Gets the running
StageInstance.Added in version 2.0.
- 戻り値:
The stage instance.
- 戻り値の型:
- 例外:
NotFound -- The stage instance or channel could not be found.
HTTPException -- Getting the stage instance failed.
- await edit(*, reason=None, **options)[ソース]¶
This function is a coroutine.
Edits the channel.
You must have the
manage_channelspermission to use this.バージョン 2.0 で変更: The
topicparameter must now be set viacreate_instance.バージョン 2.0 で変更: Edits are no longer in-place, the newly edited channel is returned instead.
- パラメータ:
name (
str) -- The new channel's name.position (
int) -- The new channel's position.sync_permissions (
bool) -- Whether to sync permissions with the channel's new or pre-existing category. Defaults toFalse.category (Optional[
CategoryChannel]) -- The new category for this channel. Can beNoneto remove the category.reason (Optional[
str]) -- The reason for editing this channel. Shows up on the audit log.overwrites (Dict[Union[
Role,Member,Snowflake],PermissionOverwrite]) -- The overwrites to apply to channel permissions. Useful for creating secret channels.rtc_region (Optional[
VoiceRegion]) -- The new region for the stage channel's voice communication. A value ofNoneindicates automatic voice region detection.video_quality_mode (
VideoQualityMode) --The camera video quality for the stage channel's participants.
Added in version 2.0.
bitrate (
int) -- The channel's preferred audio bitrate in bits per second.user_limit (
int) -- The channel's limit for number of members that can be in a voice channel.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this channel, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.
- 戻り値:
The newly edited stage channel. If the edit was only positional then
Noneis returned instead.- 戻り値の型:
Optional[
StageChannel]- 例外:
InvalidArgument -- If the permission overwrite information is not in proper form.
Forbidden -- You do not have permissions to edit the channel.
HTTPException -- Editing the channel failed.
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- property category: CategoryChannel | None¶
The category this channel belongs to.
If there is no category then this is
None.
- property changed_roles: list[Role]¶
Returns a list of roles that have been overridden from their default values in the
rolesattribute.
- await connect(*, timeout=60.0, reconnect=True, cls=...)¶
This function is a coroutine.
Connects to voice and creates a
VoiceClientto establish your connection to the voice server.This requires
Intents.voice_states.- パラメータ:
timeout (
float) -- The timeout in seconds to wait for the voice endpoint.reconnect (
bool) -- Whether the bot should automatically attempt a reconnect if a part of the handshake fails or the gateway goes down.cls (
Callable[[Client,Connectable],TypeVar(T, bound=VoiceProtocol)]) -- A type that subclassesVoiceProtocolto connect with. Defaults toVoiceClient.
- 戻り値:
A voice client that is fully connected to the voice server.
- 戻り値の型:
TypeVar(T, bound=VoiceProtocol)- 例外:
asyncio.TimeoutError -- Could not connect to the voice channel in time.
ClientException -- You are already connected to a voice channel.
OpusNotLoaded -- The opus library has not been loaded.
- await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_event=None, target_type=None, target_user=None, target_application_id=None, roles=None, target_users_file=None)¶
This function is a coroutine.
Creates an instant invite from a text or voice channel.
You must have the
create_instant_invitepermission to do this.- パラメータ:
max_age (
int) -- How long the invite should last in seconds. If it's 0 then the invite doesn't expire. Defaults to0.max_uses (
int) -- How many uses the invite could be used for. If it's 0 then there are unlimited uses. Defaults to0.temporary (
bool) -- Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults toFalse.unique (
bool) -- Indicates if a unique invite URL should be created. Defaults to True. If this is set toFalsethen it will return a previously created invite.reason (
str|None) -- The reason for creating this invite. Shows up on the audit log.target_type (
InviteTarget|None) --The type of target for the voice channel invite, if any.
Added in version 2.0.
The user whose stream to display for this invite, required if target_type is TargetType.stream. The user must be streaming in the channel.
Added in version 2.0.
target_application_id (
int|None) --The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.
Added in version 2.0.
target_event (
ScheduledEvent|None) --The scheduled event object to link to the event. Shortcut to
Invite.set_scheduled_event()See
Invite.set_scheduled_event()for more info on event invite linking.Added in version 2.0.
roles (
list[Role|Object] |None) --The roles to give a user when joining through this invite.
You must have the
manage_rolespermission to do this and roles cannot be higher than your own.Added in version 2.8.
target_users_file (
File|None) --A CSV file with a single column of user IDs for all the users able to accept this invite.
You can use
utils.users_to_csv()to generate a virtual CSV file from a sequence of user IDs.Added in version 2.8.
- 戻り値:
The invite that was created.
- 戻り値の型:
- 例外:
HTTPException -- Invite creation failed.
NotFound -- The channel that was passed is a category or an invalid channel.
- await delete(*, reason=None)¶
This function is a coroutine.
Deletes the channel.
You must have
manage_channelspermission to use this.
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- await invites()¶
This function is a coroutine.
Returns a list of all active instant invites from this channel.
You must have
manage_channelsto get this information.- 戻り値:
The list of invites that are currently active.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- await move(**kwargs)¶
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 the
manage_channelspermission to do this.注釈
Voice channels will always be sorted below text channels. This is a Discord limitation.
Added in version 1.7.
- パラメータ:
beginning (
bool) -- Whether to move the channel to the beginning of the channel list (or category if given). This is mutually exclusive withend,before, andafter.end (
bool) -- Whether to move the channel to the end of the channel list (or category if given). This is mutually exclusive withbeginning,before, andafter.before (
Snowflake) -- The channel that should be before our current channel. This is mutually exclusive withbeginning,end, andafter.after (
Snowflake) -- The channel that should be after our current channel. This is mutually exclusive withbeginning,end, andbefore.offset (
int) -- The number of channels to offset the move by. For example, an offset of2withbeginning=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 thebeginning,end,before, andafterparameters.category (Optional[
Snowflake]) -- The category to move this channel under. IfNoneis 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 (
str) -- The reason for the move.
- 例外:
InvalidArgument -- An invalid position was given or a bad mix of arguments was passed.
Forbidden -- You do not have permissions to move the channel.
HTTPException -- Moving the channel failed.
- 戻り値の型:
- property overwrites: dict[Role | Member, PermissionOverwrite]¶
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 aMemberand the value is the overwrite as aPermissionOverwrite.- 戻り値:
The channel's permission overwrites.
- 戻り値の型:
Dict[Union[
Role,Member],PermissionOverwrite]
- overwrites_for(obj)¶
Returns the channel-specific overwrites for a member or a role.
- permissions_for(obj, /)¶
Handles permission resolution for the
MemberorRole.This function takes into consideration the following cases:
Guild owner
Guild roles
Channel overrides
Member overrides
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
バージョン 2.0 で変更: The object passed in can now be a role object.
- property permissions_synced: bool¶
Whether the permissions for this channel are synced with the category it belongs to.
If there is no category then this is
False.Added in version 1.3.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- await set_permissions(target, *, overwrite=..., reason=None, **permissions)¶
This function is a coroutine.
Sets the channel specific permission overwrites for a target in the channel.
The
targetparameter should either be aMemberor aRolethat belongs to guild.The
overwriteparameter, if given, must either beNoneorPermissionOverwrite. For convenience, you can pass in keyword arguments denotingPermissionsattributes. If this is done, then you cannot mix the keyword arguments with theoverwriteparameter.If the
overwriteparameter isNone, then the permission overwrites are deleted.You must have the
manage_rolespermission to use this.注釈
This method replaces the old overwrites with the ones given.
サンプル
Setting allow and deny:
await message.channel.set_permissions(message.author, read_messages=True, send_messages=False)
Deleting overwrites
await channel.set_permissions(member, overwrite=None)
Using
PermissionOverwriteoverwrite = discord.PermissionOverwrite() overwrite.send_messages = False overwrite.read_messages = True await channel.set_permissions(member, overwrite=overwrite)
- パラメータ:
target (Union[
Member,Role]) -- The member or role to overwrite permissions for.overwrite (Optional[
PermissionOverwrite]) -- The permissions to allow and deny to the target, orNoneto 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.
- 例外:
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.
InvalidArgument -- The overwrite parameter invalid or the target type was not
RoleorMember.
- await trigger_typing()¶
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.
- 戻り値の型:
- typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- property voice_states: dict[int, VoiceState]¶
Returns a mapping of member IDs who have voice states in this channel.
Added in version 1.3.
注釈
This function is intentionally low level to replace
memberswhen the member cache is unavailable.- 戻り値:
The mapping of member ID to a voice state.
- 戻り値の型:
Mapping[
int,VoiceState]
- class discord.StageInstance(*, state, guild, data)[ソース]¶
Represents a stage instance of a stage channel in a guild.
Added in version 2.0.
- x == y
Checks if two stage instances are equal.
- x != y
Checks if two stage instances are not equal.
- hash(x)
Returns the stage instance's hash.
- privacy_level¶
The privacy level of the stage instance.
- Type:
- scheduled_event¶
The scheduled event linked with the stage instance, if any.
- Type:
Optional[
ScheduledEvent]
- パラメータ:
state (
ConnectionState)guild (
Guild)data (
StageInstance)
- channel¶
The channel that stage instance is running in.
- await edit(*, topic=..., privacy_level=..., reason=None)[ソース]¶
This function is a coroutine.
Edits the stage instance.
You must have the
manage_channelspermission to use this.- パラメータ:
- 例外:
InvalidArgument -- If the
privacy_levelparameter is not the proper type.Forbidden -- You do not have permissions to edit the stage instance.
HTTPException -- Editing a stage instance failed.
- 戻り値の型:
- await delete(*, reason=None)[ソース]¶
This function is a coroutine.
Deletes the stage instance.
You must have the
manage_channelspermission to use this.- パラメータ:
reason (
str|None) -- The reason the stage instance was deleted. Shows up on the audit log.- 例外:
Forbidden -- You do not have permissions to delete the stage instance.
HTTPException -- Deleting the stage instance failed.
- 戻り値の型:
Interactions¶
- asyncdelete_original_message
- asyncdelete_original_response
- asyncedit
- asyncedit_original_message
- asyncedit_original_response
- defis_command
- defis_component
- defis_guild_authorised
- defis_guild_authorized
- defis_user_authorised
- defis_user_authorized
- asyncoriginal_message
- asyncoriginal_response
- asyncrespond
- defto_dict
- class discord.Interaction(*, data, state)[ソース]¶
Represents a Discord interaction.
An interaction happens when a user does an action that needs to be notified. Current examples are application commands, components, and modals.
Added in version 2.0.
- type¶
The interaction type.
- Type:
- channel¶
The channel the interaction was sent from.
- Type:
Optional[Union[
abc.GuildChannel,abc.PrivateChannel,Thread,PartialMessageable]]
- user¶
The user or member that sent the interaction. Will be None in PING interactions.
- entitlements¶
Entitlements that apply to the invoking user, showing access to premium SKUs.
Added in version 2.5.
- Type:
list[
Entitlement]
- authorizing_integration_owners¶
Contains the entities (users or guilds) that authorized this interaction.
Added in version 2.6.
- context¶
The context in which this command was executed.
Added in version 2.6.
- Type:
Optional[
InteractionContextType]
- callback¶
The callback of the interaction. Contains information about the status of the interaction response. Will be None until the interaction is responded to.
Added in version 2.7.
- Type:
Optional[
InteractionCallback]
- command¶
The command that this interaction belongs to.
Added in version 2.7.
- Type:
Optional[
ApplicationCommand]
- view¶
The view that this interaction belongs to.
Added in version 2.7.
- Type:
Optional[
BaseView]
- modal¶
The modal that this interaction belongs to.
Added in version 2.7.
- Type:
Optional[
BaseModal]
- パラメータ:
data (
Interaction)state (
ConnectionState)
- property cached_channel: VoiceChannel | StageChannel | TextChannel | ForumChannel | CategoryChannel | Thread | DMChannel | GroupChannel | PartialMessageable | None¶
The cached channel from which the interaction was sent. DM channels are not resolved. These are
PartialMessageableinstead.バージョン 2.7 で非推奨.
- property permissions: Permissions¶
The resolved permissions of the member in the channel, including overwrites.
In a non-guild context where this doesn't apply, an empty permissions object is returned.
- app_permissions¶
The resolved permissions of the application in the channel, including overwrites.
- response¶
Returns an object responsible for handling responding to the interaction.
A response can only be done once. If secondary messages need to be sent, consider using
followupinstead.
- followup¶
Returns the followup webhook for followup interactions.
- is_guild_authorised()[ソース]¶
bool: Checks if the interaction is guild authorised.There is an alias for this called
is_guild_authorized().Added in version 2.7.
- 戻り値の型:
- is_user_authorised()[ソース]¶
bool: Checks if the interaction is user authorised.There is an alias for this called
is_user_authorized().Added in version 2.7.
- 戻り値の型:
- is_guild_authorized()[ソース]¶
bool: Checks if the interaction is guild authorized.There is an alias for this called
is_guild_authorised().Added in version 2.7.
- 戻り値の型:
- is_user_authorized()[ソース]¶
bool: Checks if the interaction is user authorized.There is an alias for this called
is_user_authorised().Added in version 2.7.
- 戻り値の型:
- await original_response()[ソース]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
If the interaction response was
InteractionResponse.send_message()then this would return the message that was sent using that response. Otherwise, this would return the message that triggered the interaction.Repeated calls to this will return a cached value.
- 戻り値:
The original interaction response message.
- 戻り値の型:
- 例外:
HTTPException -- Fetching the original response message failed.
ClientException -- The channel for the message could not be resolved.
- await original_message()[ソース]¶
An alias for
original_response().- 戻り値:
The original interaction response message.
- 戻り値の型:
- 例外:
HTTPException -- Fetching the original response message failed.
ClientException -- The channel for the message could not be resolved.
- await edit_original_response(*, content=..., embeds=..., embed=..., file=..., files=..., attachments=..., view=..., allowed_mentions=None, delete_after=None, suppress=None, suppress_embeds=None)[ソース]¶
This function is a coroutine.
Edits the original interaction response message.
This is a lower level interface to
InteractionMessage.edit()in case you do not want to fetch the message and save an HTTP request.This method is also the only way to edit the original message if the message sent was ephemeral.
- パラメータ:
content (
str|None) -- The content to edit the message with orNoneto clear it.embeds (
list[Embed]) -- A list of embeds to edit the message with.embed (
Embed|None) -- The embed to edit the message with.Nonesuppresses the embeds. This should not be mixed with theembedsparameter.file (
File) -- The file to upload. This cannot be mixed withfilesparameter.files (
list[File]) -- A list of files to send with the content. This cannot be mixed with thefileparameter.attachments (
list[Attachment]) -- A list of attachments to keep in the message. If[]is passed then all attachments are removed.allowed_mentions (
AllowedMentions|None) -- Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.view (
BaseView|None) -- The updated view to update this message with. IfNoneis passed then the view is removed.delete_after (
float|None) -- If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
- 戻り値:
The newly edited message.
- 戻り値の型:
- 例外:
HTTPException -- Editing the message failed.
Forbidden -- Edited a message that is not yours.
TypeError -- You specified both
embedandembedsorfileandfilesValueError -- The length of
embedswas invalid.
- await edit_original_message(**kwargs)[ソース]¶
An alias for
edit_original_response().- 戻り値:
The newly edited message.
- 戻り値の型:
- 例外:
HTTPException -- Editing the message failed.
Forbidden -- Edited a message that is not yours.
TypeError -- You specified both
embedandembedsorfileandfilesValueError -- The length of
embedswas invalid.
- await delete_original_response(*, delay=None)[ソース]¶
This function is a coroutine.
Deletes the original interaction response message.
This is a lower level interface to
InteractionMessage.delete()in case you do not want to fetch the message and save an HTTP request.- パラメータ:
delay (
float|None) -- If provided, the number of seconds to wait before deleting the message. The waiting is done in the background and deletion failures are ignored.- 例外:
HTTPException -- Deleting the message failed.
Forbidden -- Deleted a message that is not yours.
- 戻り値の型:
- await delete_original_message(**kwargs)[ソース]¶
An alias for
delete_original_response().- 例外:
HTTPException -- Deleting the message failed.
Forbidden -- Deleted a message that is not yours.
- await respond(*args, **kwargs)[ソース]¶
This function is a coroutine.
Sends either a response or a message using the followup webhook determined by whether the interaction has been responded to or not.
- パラメータ:
content (Optional[
str]) -- The content of the message to send.embeds (List[
Embed]) -- A list of embeds to send with the content. Maximum of 10. This cannot be mixed with theembedparameter.embed (
Embed) -- The rich embed for the content to send. This cannot be mixed withembedsparameter.tts (
bool) -- Indicates if the message should be sent using text-to-speech.view (
discord.ui.BaseView) -- The view to send with the message.ephemeral (
bool) -- Indicates if the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message, and it has no timeout set then the timeout is set to 15 minutes.allowed_mentions (
AllowedMentions) -- Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.delete_after (
float) -- If provided, the number of seconds to wait in the background before deleting the message we just sent.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.poll (
Poll) --The poll to send.
Added in version 2.6.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.8.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
- 戻り値:
The response, its type depending on whether it's an interaction response or a followup.
- 戻り値の型:
- await edit(*args, **kwargs)[ソース]¶
This function is a coroutine.
Either respond to the interaction with an edit_message or edits the existing response, determined by whether the interaction has been responded to or not.
- 戻り値:
The response, its type depending on whether it's an interaction response or a followup.
- 戻り値の型:
- asyncdefer
- asyncedit_message
- defis_done
- asyncpong
- asyncpremium_required
- asyncsend_autocomplete_result
- asyncsend_message
- asyncsend_modal
- class discord.InteractionResponse(parent)[ソース]¶
Represents a Discord interaction response.
This type can be accessed through
Interaction.response.Added in version 2.0.
- パラメータ:
parent (
Interaction)
- is_done()[ソース]¶
Indicates whether an interaction response has been done before.
An interaction can only be responded to once.
- 戻り値の型:
- await defer(*, ephemeral=False, invisible=True)[ソース]¶
This function is a coroutine.
Defers the interaction response.
This is typically used when the interaction is acknowledged and a secondary action will be done later.
This can only be used with the following interaction types:
注釈
The follow-up response will also be non-ephemeral if the ephemeral argument is
False, and ephemeral ifTrue.- パラメータ:
ephemeral (
bool) -- Indicates whether the deferred message will eventually be ephemeral. This only applies toInteractionType.application_commandinteractions, or ifinvisibleisFalse.invisible (
bool) -- Indicates whether the deferred type should be 'invisible' (InteractionResponseType.deferred_message_update) instead of 'thinking' (InteractionResponseType.deferred_channel_message). In the Discord UI, this is represented as the bot thinking of a response. You must eventually send a followup message viaInteraction.followupto make this thinking state go away. This parameter does not apply to interactions of typeInteractionType.application_command.
- 例外:
HTTPException -- Deferring the interaction failed.
InteractionResponded -- This interaction has already been responded to before.
- 戻り値の型:
- await pong()[ソース]¶
This function is a coroutine.
Pongs the ping interaction.
This should rarely be used.
- 例外:
HTTPException -- Ponging the interaction failed.
InteractionResponded -- This interaction has already been responded to before.
- 戻り値の型:
- await send_message(content=None, *, embed=None, embeds=None, view=None, tts=False, ephemeral=False, allowed_mentions=None, file=None, files=None, poll=None, delete_after=None, silent=False, suppress_embeds=False)[ソース]¶
This function is a coroutine.
Responds to this interaction by sending a message.
- パラメータ:
embeds (
list[Embed] |None) -- A list of embeds to send with the content. Maximum of 10. This cannot be mixed with theembedparameter.embed (
Embed|None) -- The rich embed for the content to send. This cannot be mixed withembedsparameter.tts (
bool) -- Indicates if the message should be sent using text-to-speech.view (
BaseView|None) -- The view to send with the message.ephemeral (
bool) -- Indicates if the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message, and it has no timeout set then the timeout is set to 15 minutes.allowed_mentions (
AllowedMentions|None) -- Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.delete_after (
float|None) -- If provided, the number of seconds to wait in the background before deleting the message we just sent.files (
list[File] |None) -- A list of files to upload. Must be a maximum of 10.The poll to send.
Added in version 2.6.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.8.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
- 戻り値:
The interaction object associated with the sent message.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
TypeError -- You specified both
embedandembeds, or sent content or embeds with V2 components.ValueError -- The length of
embedswas invalid.InteractionResponded -- This interaction has already been responded to before.
- await edit_message(*, content=..., embed=..., embeds=..., file=..., files=..., attachments=..., view=..., delete_after=None, suppress=..., allowed_mentions=None)[ソース]¶
This function is a coroutine.
Responds to this interaction by editing the original message of a component or modal interaction.
- パラメータ:
content (
Any|None) -- The new content to replace the message with.Noneremoves the content.embeds (
list[Embed]) -- A list of embeds to edit the message with.embed (
Embed|None) -- The embed to edit the message with.Nonesuppresses the embeds. This should not be mixed with theembedsparameter.file (
File) -- A new file to add to the message. This cannot be mixed withfilesparameter.files (
list[File]) -- A list of new files to add to the message. Must be a maximum of 10. This cannot be mixed with thefileparameter.attachments (
list[Attachment]) -- A list of attachments to keep in the message. If[]is passed then all attachments are removed.view (
BaseView|None) -- The updated view to update this message with. IfNoneis passed then the view is removed.delete_after (
float|None) -- If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.suppress (
bool|None) -- Whether to suppress embeds for the message.allowed_mentions (
AllowedMentions|None) -- Controls the mentions being processed in this message. If this is passed, then the object is merged withallowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.
- 例外:
HTTPException -- Editing the message failed.
TypeError -- You specified both
embedandembeds.InteractionResponded -- This interaction has already been responded to before.
- 戻り値の型:
- await send_autocomplete_result(*, choices)[ソース]¶
This function is a coroutine. Responds to this interaction by sending the autocomplete choices.
- パラメータ:
choices (
list[OptionChoice]) -- A list of choices.- 例外:
HTTPException -- Sending the result failed.
InteractionResponded -- This interaction has already been responded to before.
- 戻り値の型:
- await send_modal(modal)[ソース]¶
This function is a coroutine. Responds to this interaction by sending a modal dialog. This cannot be used to respond to another modal dialog submission.
- パラメータ:
modal (
BaseModal) -- The modal dialog to display to the user.- 例外:
HTTPException -- Sending the modal failed.
InteractionResponded -- This interaction has already been responded to before.
- 戻り値の型:
This function is a coroutine.
Responds to this interaction by sending a premium required message.
バージョン 2.6 で非推奨: A button with type
ButtonType.premiumshould be used instead.- 例外:
HTTPException -- Sending the message failed.
InteractionResponded -- This interaction has already been responded to before.
- 戻り値の型:
- class discord.InteractionMessage(*, state, channel, data)[ソース]¶
Represents the original interaction response message.
This allows you to edit or delete the message associated with the interaction response. To retrieve this object see
Interaction.original_response().This inherits from
discord.Messagewith changes toedit()anddelete()to work.Added in version 2.0.
- パラメータ:
state (
ConnectionState)channel (
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|PartialMessageable|GroupChannel)data (
Message)
- await edit(content=..., embeds=..., embed=..., file=..., files=..., attachments=..., view=..., allowed_mentions=None, delete_after=None, suppress=..., suppress_embeds=...)[ソース]¶
This function is a coroutine.
Edits the message.
- パラメータ:
content (
str|None) -- The content to edit the message with orNoneto clear it.embeds (
list[Embed]) -- A list of embeds to edit the message with.embed (
Embed|None) -- The embed to edit the message with.Nonesuppresses the embeds. This should not be mixed with theembedsparameter.file (
File) -- The file to upload. This cannot be mixed withfilesparameter.files (
list[File]) -- A list of files to send with the content. This cannot be mixed with thefileparameter.attachments (
list[Attachment]) -- A list of attachments to keep in the message. If[]is passed then all attachments are removed.allowed_mentions (
AllowedMentions|None) -- Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.view (
BaseView|None) -- The updated view to update this message with. IfNoneis passed then the view is removed.delete_after (
float|None) -- If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool|None) --Whether to suppress embeds for the message.
Added in version 2.8.
- 戻り値:
The newly edited message.
- 戻り値の型:
- 例外:
HTTPException -- Editing the message failed.
Forbidden -- Edited a message that is not yours.
TypeError -- You specified both
embedandembedsorfileandfilesValueError -- The length of
embedswas invalid.
- await delete(*, delay=None)[ソース]¶
This function is a coroutine.
Deletes the message.
- パラメータ:
delay (
float|None) -- If provided, the number of seconds to wait before deleting the message. The waiting is done in the background and deletion failures are ignored.- 例外:
Forbidden -- You do not have proper permissions to delete the message.
NotFound -- The message was deleted already.
HTTPException -- Deleting the message failed.
- 戻り値の型:
- class discord.MessageInteraction(*, data, state)[ソース]¶
Represents a Discord message interaction.
This is sent on the message object when the message is a response to an interaction without an existing message e.g. application command.
Added in version 2.0.
バージョン 2.6 で非推奨: See
InteractionMetadata.注釈
Responses to message components do not include this property.
- type¶
The interaction type.
- Type:
- パラメータ:
data (
MessageInteraction)state (
ConnectionState)
- class discord.InteractionMetadata(*, data, state)[ソース]¶
Represents metadata about an interaction.
This is sent on the message object when the message is related to an interaction
Added in version 2.6.
- type¶
The interaction type.
- Type:
- authorizing_integration_owners¶
The authorizing user or server for the installation(s) relevant to the interaction.
- original_response_message_id¶
The ID of the original response message. Only present on interaction follow-up messages.
- Type:
Optional[
int]
- interacted_message_id¶
The ID of the message that triggered the interaction. Only present on interactions of type
InteractionType.component.- Type:
Optional[
int]
- triggering_interaction_metadata¶
The metadata of the interaction that opened the model. Only present on interactions of type
InteractionType.modal_submit.- Type:
Optional[
InteractionMetadata]
- パラメータ:
data (
InteractionMetadata)state (
ConnectionState)
- original_response_message¶
The original response message. Returns
Noneif the message is not in cache, or iforiginal_response_message_idisNone.- Type:
Optional[
Message]
- interacted_message¶
The message that triggered the interaction. Returns
Noneif the message is not in cache, or ifinteracted_message_idisNone.- Type:
Optional[
Message]
- class discord.AuthorizingIntegrationOwners(data, state)[ソース]¶
Contains details on the authorizing user or server for the installation(s) relevant to the interaction.
Added in version 2.6.
- guild_id¶
The ID of the guild that authorized the integration. This will be
0if the integration was triggered from the user in the bot's DMs.- Type:
int| None
- defis_ephemeral
- defis_loading
UI Components¶
- class discord.Component[ソース]¶
Represents a Discord Bot UI Kit Component.
The components supported by Discord in messages are as follows:
This class is abstract and cannot be instantiated.
Added in version 2.0.
- type¶
The type of component.
- Type:
- id¶
The component's ID. If not provided by the user, it is set sequentially by Discord. The ID 0 is treated as if no ID was provided.
- Type:
- class discord.ActionRow(data)[ソース]¶
Represents a Discord Bot UI Kit Action Row.
This is a component that holds up to 5 children components in a row.
This inherits from
Component.Added in version 2.0.
- type¶
The type of component.
- Type:
- パラメータ:
data (
ActionRow|ButtonComponent|SelectMenu|InputText|TextDisplayComponent|SectionComponent|ThumbnailComponent|MediaGalleryComponent|FileComponent|SeparatorComponent|ContainerComponent|LabelComponent|FileUploadComponent|RadioGroupComponent|CheckboxGroupComponent|CheckboxComponent)
- property width¶
Returns the sum of the item's widths.
- class discord.Button(data)[ソース]¶
Represents a button from the Discord Bot UI Kit.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.Buttoninstead.Added in version 2.0.
- style¶
The style of the button.
- Type:
- custom_id¶
The ID of the button that gets received during an interaction. If this button is for a URL, it does not have a custom ID.
- Type:
Optional[
str]
- emoji¶
The emoji of the button, if available.
- Type:
Optional[
PartialEmoji]
- パラメータ:
data (
ButtonComponent)
- defis_v2
- class discord.SelectMenu(data)[ソース]¶
Represents a select menu from the Discord Bot UI Kit.
A select menu is functionally the same as a dropdown, however on mobile it renders a bit differently.
注釈
This class is not useable by end-users; see
discord.ui.Selectinstead.Added in version 2.0.
バージョン 2.3 で変更: Added support for
ComponentType.user_select,ComponentType.role_select,ComponentType.mentionable_select, andComponentType.channel_select.バージョン 2.7 で変更: Added the
requiredattribute for use in modals.- type¶
The select menu's type.
- Type:
- min_values¶
The minimum number of items that must be chosen for this select menu. Defaults to 1 and must be between 0 and 25.
- Type:
- max_values¶
The maximum number of items that must be chosen for this select menu. Defaults to 1 and must be between 1 and 25.
- Type:
- options¶
A list of options that can be selected in this menu. Will be an empty list for all component types except for
ComponentType.string_select.- Type:
List[
SelectOption]
- channel_types¶
A list of channel types that can be selected. Will be an empty list for all component types except for
ComponentType.channel_select.- Type:
List[
ChannelType]
- disabled¶
Whether the select is disabled or not. Not usable in modals. Defaults to
False.- Type:
- required¶
Whether the select is required or not. Only useable in modals. Defaults to
True.- Type:
Optional[
bool]
- パラメータ:
data (
SelectMenu)
- defget_component
- defis_v2
- class discord.Section(data, state=None)[ソース]¶
Represents a Section from Components V2.
This is a component that groups other components together with an additional component to the right as the accessory.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.Sectioninstead.Added in version 2.7.
- components¶
The components contained in this section. Currently supports
TextDisplay.- Type:
List[
Component]
- accessory¶
The accessory attached to this Section. Currently supports
ButtonandThumbnail.- Type:
Optional[
Component]
- パラメータ:
data (
SectionComponent)
- class discord.TextDisplay(data)[ソース]¶
Represents a Text Display from Components V2.
This is a component that displays text.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.TextDisplayinstead.Added in version 2.7.
- パラメータ:
data (
TextDisplayComponent)
- defis_v2
- class discord.Thumbnail(data, state=None)[ソース]¶
Represents a Thumbnail from Components V2.
This is a component that displays media, such as images and videos.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.Thumbnailinstead.Added in version 2.7.
- media¶
The component's underlying media object.
- Type:
- パラメータ:
data (
ThumbnailComponent)
- class discord.MediaGallery(data, state=None)[ソース]¶
Represents a Media Gallery from Components V2.
This is a component that displays up to 10 different
MediaGalleryItemobjects.This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.MediaGalleryinstead.Added in version 2.7.
- items¶
The media this gallery contains.
- Type:
List[
MediaGalleryItem]
- パラメータ:
data (
MediaGalleryComponent)
- class discord.FileComponent(data, state=None)[ソース]¶
Represents a File from Components V2.
This component displays a downloadable file in a message.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.Fileinstead.Added in version 2.7.
- file¶
The file's media item.
- Type:
- パラメータ:
data (
FileComponent)
- class discord.Separator(data)[ソース]¶
Represents a Separator from Components V2.
This is a component that visually separates components.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.Separatorinstead.Added in version 2.7.
- divider¶
Whether the separator will show a horizontal line in addition to vertical spacing.
- Type:
- spacing¶
The separator's spacing size.
- Type:
Optional[
SeparatorSpacingSize]
- パラメータ:
data (
SeparatorComponent)
- defget_component
- defis_v2
- class discord.Container(data, state=None)[ソース]¶
Represents a Container from Components V2.
This is a component that contains different
Componentobjects. It may only contain:This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.Containerinstead.Added in version 2.7.
- パラメータ:
data (
ContainerComponent)
- class discord.Label(data)[ソース]¶
Represents a Label used in modals as the top-level component.
This is a component that allows you to add additional text to another component.
componentmay only be:InputText
This inherits from
Component.Added in version 2.7.
- component¶
The component contained in this label. Currently supports
InputTextandSelectMenu.- Type:
- description¶
The description associated with this label's
component, up to 100 characters.- Type:
Optional[
str]
- パラメータ:
data (
LabelComponent)
- defis_v2
- class discord.FileUpload(data)[ソース]¶
Represents an File Upload component from the Discord Bot UI Kit.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.FileUploadinstead.Added in version 2.7.
- custom_id¶
The custom ID of the file upload field that gets received during an interaction.
- Type:
Optional[
str]
- パラメータ:
data (
FileUploadComponent)
- class discord.RadioGroup(data)[ソース]¶
Represents an Radio Group component from the Discord Bot UI Kit.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.RadioGroupinstead.Added in version 2.8.
- custom_id¶
The custom ID of the radio group that gets received during an interaction.
- Type:
Optional[
str]
- options¶
A list of options that can be selected in this group, between 2 and 10.
- Type:
List[
RadioGroupOption]
- required¶
Whether the radio group requires a selection or not. Defaults to
True.- Type:
Optional[
bool]
- パラメータ:
data (
RadioGroupComponent)
- defis_v2
- class discord.CheckboxGroup(data)[ソース]¶
Represents an Checkbox Group component from the Discord Bot UI Kit.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.CheckboxGroupinstead.Added in version 2.8.
- custom_id¶
The custom ID of the checkbox group that gets received during an interaction.
- Type:
Optional[
str]
- options¶
A list of options that can be selected in this group.
- Type:
List[
CheckboxGroupOption]
- min_values¶
The minimum number of options that must be selected. Defaults to 1 and must be between 0 and 25. If set to 0,
requiredmust beFalse.- Type:
Optional[
int]
- max_values¶
The maximum number of options that can be selected. Must be between 1 and 10.
- Type:
Optional[
int]
- required¶
Whether the checkbox group requires a selection or not. Defaults to
True.- Type:
Optional[
bool]
- パラメータ:
data (
CheckboxGroupComponent)
- class discord.Checkbox(data)[ソース]¶
Represents an Checkbox component from the Discord Bot UI Kit.
This inherits from
Component.注釈
This class is not useable by end-users; see
discord.ui.Checkboxinstead.Added in version 2.8.
- custom_id¶
The custom ID of the checkbox group that gets received during an interaction.
- Type:
Optional[
str]
- パラメータ:
data (
CheckboxComponent)
Emoji¶
- class discord.GuildEmoji(*, guild, state, data)[ソース]¶
Represents a custom emoji in a guild.
Depending on the way this object was created, some attributes can have a value of
None.- x == y
Checks if two emoji are the same.
- x != y
Checks if two emoji are not the same.
- hash(x)
Return the emoji's hash.
- iter(x)
Returns an iterator of
(field, value)pairs. This allows this class to be used as an iterable in list/dict/etc constructions.
- str(x)
Returns the emoji rendered for discord.
- require_colons¶
If colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
- Type:
- user¶
The user that created the emoji. This can only be retrieved using
Guild.fetch_emoji()and having themanage_emojispermission.- Type:
Optional[
User]
- パラメータ:
guild (
Guild)state (
ConnectionState)data (
Emoji)
- property roles: list[Role]¶
A
listof roles that is allowed to use this emoji.If roles is empty, the emoji is unrestricted.
- await delete(*, reason=None)[ソース]¶
This function is a coroutine.
Deletes the custom emoji.
You must have
manage_emojispermission to do this.- パラメータ:
reason (
str|None) -- The reason for deleting this emoji. Shows up on the audit log.- 例外:
Forbidden -- You are not allowed to delete emojis.
HTTPException -- An error occurred deleting the emoji.
- 戻り値の型:
- await edit(*, name=..., roles=..., reason=None)[ソース]¶
This function is a coroutine.
Edits the custom emoji.
You must have
manage_emojispermission to do this.バージョン 2.0 で変更: The newly updated emoji is returned.
- パラメータ:
- 例外:
Forbidden -- You are not allowed to edit emojis.
HTTPException -- An error occurred editing the emoji.
- 戻り値:
The newly updated emoji.
- 戻り値の型:
- property extension: Literal['webp', 'png']¶
Return the file extension of the emoji.
Added in version 2.7.1.
- await read()¶
This function is a coroutine.
Retrieves the content of this asset as a
bytesobject.- 戻り値:
The content of the asset.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
- await save(fp, *, seek_begin=True)¶
This function is a coroutine.
Saves this asset into a file-like object.
- パラメータ:
fp (
str|bytes|PathLike|BufferedIOBase) -- The file-like object to save this attachment to or the filename to use. If a filename is passed then a file is created with that filename and used instead.seek_begin (
bool) -- Whether to seek to the beginning of the file after saving is successfully done.
- 戻り値:
The number of bytes written.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
- class discord.AppEmoji(*, application_id, state, data)[ソース]¶
Represents a custom emoji from an application.
Depending on the way this object was created, some attributes can have a value of
None.Added in version 2.7.
- x == y
Checks if two emoji are the same.
- x != y
Checks if two emoji are not the same.
- hash(x)
Return the emoji's hash.
- iter(x)
Returns an iterator of
(field, value)pairs. This allows this class to be used as an iterable in list/dict/etc constructions.
- str(x)
Returns the emoji rendered for discord.
- require_colons¶
If colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
- Type:
- パラメータ:
application_id (
int)state (
ConnectionState)data (
Emoji)
- property roles: list[Role]¶
A
listof roles that is allowed to use this emoji. This is always empty forAppEmoji.
- await delete()[ソース]¶
This function is a coroutine.
Deletes the application emoji.
You must own the emoji to do this.
- 例外:
Forbidden -- You are not allowed to delete the emoji.
HTTPException -- An error occurred deleting the emoji.
- 戻り値の型:
- await edit(*, name=...)[ソース]¶
This function is a coroutine.
Edits the application emoji.
You must own the emoji to do this.
- パラメータ:
name (
str) -- The new emoji name.- 例外:
Forbidden -- You are not allowed to edit the emoji.
HTTPException -- An error occurred editing the emoji.
- 戻り値:
The newly updated emoji.
- 戻り値の型:
- property extension: Literal['webp', 'png']¶
Return the file extension of the emoji.
Added in version 2.7.1.
- await read()¶
This function is a coroutine.
Retrieves the content of this asset as a
bytesobject.- 戻り値:
The content of the asset.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
- await save(fp, *, seek_begin=True)¶
This function is a coroutine.
Saves this asset into a file-like object.
- パラメータ:
fp (
str|bytes|PathLike|BufferedIOBase) -- The file-like object to save this attachment to or the filename to use. If a filename is passed then a file is created with that filename and used instead.seek_begin (
bool) -- Whether to seek to the beginning of the file after saving is successfully done.
- 戻り値:
The number of bytes written.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
- clsPartialEmoji.from_str
- defis_custom_emoji
- defis_unicode_emoji
- asyncread
- asyncsave
- class discord.PartialEmoji(*, name, animated=False, id=None)[ソース]¶
Represents a "partial" emoji.
This model will be given in two scenarios:
"Raw" data events such as
on_raw_reaction_add()Custom emoji that the bot cannot see from e.g.
Message.reactions
- x == y
Checks if two emoji are the same.
- x != y
Checks if two emoji are not the same.
- hash(x)
Return the emoji's hash.
- str(x)
Returns the emoji rendered for discord.
- name¶
The custom emoji name, if applicable, or the unicode codepoint of the non-custom emoji. This can be
Noneif the emoji got deleted (e.g. removing a reaction with a deleted emoji).- Type:
Optional[
str]
- classmethod from_str(value)[ソース]¶
Converts a Discord string representation of an emoji to a
PartialEmoji.The formats accepted are:
a:name:id<a:name:id>name:id<:name:id>
If the format does not match then it is assumed to be a Unicode emoji block, either as Unicode characters or as a Discord alias (
:smile:).Added in version 2.0.
- property created_at: datetime | None¶
Returns the emoji's creation time in UTC, or None if Unicode emoji.
Added in version 1.6.
- property url: str¶
Returns the URL of the emoji, if it is custom.
If this isn't a custom emoji then an empty string is returned
- property extension: Literal['webp', 'png']¶
Return the file extension of the emoji.
Added in version 2.7.1.
- await read()[ソース]¶
This function is a coroutine.
Retrieves the content of this asset as a
bytesobject.- 戻り値:
The content of the asset.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
- await save(fp, *, seek_begin=True)¶
This function is a coroutine.
Saves this asset into a file-like object.
- パラメータ:
fp (
str|bytes|PathLike|BufferedIOBase) -- The file-like object to save this attachment to or the filename to use. If a filename is passed then a file is created with that filename and used instead.seek_begin (
bool) -- Whether to seek to the beginning of the file after saving is successfully done.
- 戻り値:
The number of bytes written.
- 戻り値の型:
- 例外:
DiscordException -- There was no internal connection state.
HTTPException -- Downloading the asset failed.
NotFound -- The asset was deleted.
Channels¶
- defarchived_threads
- defcan_send
- asyncclone
- asynccreate_invite
- asynccreate_thread
- asynccreate_webhook
- asyncdelete
- asyncdelete_messages
- asyncedit
- asyncfetch_message
- asyncfollow
- defget_partial_message
- defget_thread
- defhistory
- asyncinvites
- defis_news
- defis_nsfw
- asyncmove
- defoverwrites_for
- defpermissions_for
- defpins
- asyncpurge
- asyncsend
- asyncset_permissions
- asynctrigger_typing
- deftyping
- asyncwebhooks
- class discord.TextChannel(*, state, guild, data)[ソース]¶
Represents a Discord text channel.
- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the channel's hash.
- str(x)
Returns the channel's name.
- position¶
The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0. Can be
Noneif the channel was received in an interaction.- Type:
Optional[
int]
- last_message_id¶
The last message ID of the message sent to this channel. It may not point to an existing or valid message.
- Type:
Optional[
int]
- slowmode_delay¶
The number of seconds a member must wait between sending messages in this channel. A value of 0 denotes that it is disabled. Bots and users with
manage_channelsormanage_messagesbypass slowmode.- Type:
- nsfw¶
If the channel is marked as "not safe for work".
注釈
To check if the channel or the guild of that channel are marked as NSFW, consider
is_nsfw()instead.- Type:
- default_auto_archive_duration¶
The default auto archive duration in minutes for threads created in this channel.
Added in version 2.0.
- Type:
- flags¶
Extra features of the channel.
Added in version 2.0.
- Type:
- default_thread_slowmode_delay¶
The initial slowmode delay to set on newly created threads in this channel.
Added in version 2.3.
- Type:
Optional[
int]
- パラメータ:
state (
ConnectionState)guild (
Guild)data (
TextChannel)
- async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- async with typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- await edit(*, reason=None, **options)[ソース]¶
This function is a coroutine.
Edits the channel.
You must have the
manage_channelspermission to use this.バージョン 1.3 で変更: The
overwriteskeyword-only parameter was added.バージョン 1.4 で変更: The
typekeyword-only parameter was added.バージョン 2.0 で変更: Edits are no longer in-place, the newly edited channel is returned instead.
- パラメータ:
name (
str) -- The new channel name.topic (
str) -- The new channel's topic.position (
int) -- The new channel's position.nsfw (
bool) -- Whether the channel is marked as NSFW.sync_permissions (
bool) -- Whether to sync permissions with the channel's new or pre-existing category. Defaults toFalse.category (Optional[
CategoryChannel]) -- The new category for this channel. Can beNoneto remove the category.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this channel, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.type (
ChannelType) -- Change the type of this text channel. Currently, only conversion betweenChannelType.textandChannelType.newsis supported. This is only available to guilds that containNEWSinGuild.features.reason (Optional[
str]) -- The reason for editing this channel. Shows up on the audit log.overwrites (Dict[Union[
Role,Member,Snowflake],PermissionOverwrite]) -- The overwrites to apply to channel permissions. Useful for creating secret channels.default_auto_archive_duration (
int) -- The new default auto archive duration in minutes for threads created in this channel. Must be one of60,1440,4320, or10080.default_thread_slowmode_delay (
int) --The new default slowmode delay in seconds for threads created in this channel.
Added in version 2.3.
- 戻り値:
The newly edited text channel. If the edit was only positional then
Noneis returned instead.- 戻り値の型:
Optional[
TextChannel]- 例外:
InvalidArgument -- If position is less than 0 or greater than the number of channels, or if the permission overwrite information is not in proper form.
Forbidden -- You do not have permissions to edit the channel.
HTTPException -- Editing the channel failed.
- await create_thread(*, name, message=None, auto_archive_duration=..., type=None, slowmode_delay=None, invitable=None, reason=None)[ソース]¶
This function is a coroutine.
Creates a thread in this text channel.
To create a public thread, you must have
create_public_threads. For a private thread,create_private_threadsis needed instead.Added in version 2.0.
- パラメータ:
name (
str) -- The name of the thread.message (
Snowflake|None) -- A snowflake representing the message to create the thread with. IfNoneis passed then a private thread is created. Defaults toNone.auto_archive_duration (
Literal[60,1440,4320,10080]) -- The duration in minutes before a thread is automatically archived for inactivity. If not provided, the channel's default auto archive duration is used.type (
ChannelType|None) -- The type of thread to create. If amessageis passed then this parameter is ignored, as a thread created with a message is always a public thread. By default, this creates a private thread if this isNone.slowmode_delay (
int|None) -- Specifies the slowmode rate limit for users in this thread, in seconds. A value of0disables slowmode. The maximum value possible is21600.invitable (
bool|None) -- Whether non-moderators can add other non-moderators to this thread. Only available for private threads, where it defaults to True.reason (
str|None) -- The reason for creating a new thread. Shows up on the audit log.
- 戻り値:
The created thread
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to create a thread.
HTTPException -- Starting the thread failed.
- archived_threads(*, private=False, joined=False, limit=50, before=None)¶
Returns an
AsyncIteratorthat iterates over all archived threads in the guild.You must have
read_message_historyto use this. If iterating over private threads thenmanage_threadsis also required.Added in version 2.0.
- パラメータ:
limit (
int|None) -- The number of threads to retrieve. IfNone, retrieves every archived thread in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- Retrieve archived channels before the given date or ID.private (
bool) -- Whether to retrieve private archived threads.joined (
bool) -- Whether to retrieve private archived threads that you've joined. You cannot setjoinedtoTrueandprivatetoFalse.
- 列挙:
Thread-- The archived threads.- 例外:
Forbidden -- You do not have permissions to get archived threads.
HTTPException -- The request to get the archived threads failed.
- 戻り値の型:
ArchivedThreadIterator
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- property category: CategoryChannel | None¶
The category this channel belongs to.
If there is no category then this is
None.
- property changed_roles: list[Role]¶
Returns a list of roles that have been overridden from their default values in the
rolesattribute.
- await clone(*, name=None, reason=None)¶
This function is a coroutine.
Clones this channel. This creates a channel with the same properties as this channel.
You must have the
manage_channelspermission to do this.Added in version 1.1.
- パラメータ:
- 戻り値:
The channel that was created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
- await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_event=None, target_type=None, target_user=None, target_application_id=None, roles=None, target_users_file=None)¶
This function is a coroutine.
Creates an instant invite from a text or voice channel.
You must have the
create_instant_invitepermission to do this.- パラメータ:
max_age (
int) -- How long the invite should last in seconds. If it's 0 then the invite doesn't expire. Defaults to0.max_uses (
int) -- How many uses the invite could be used for. If it's 0 then there are unlimited uses. Defaults to0.temporary (
bool) -- Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults toFalse.unique (
bool) -- Indicates if a unique invite URL should be created. Defaults to True. If this is set toFalsethen it will return a previously created invite.reason (
str|None) -- The reason for creating this invite. Shows up on the audit log.target_type (
InviteTarget|None) --The type of target for the voice channel invite, if any.
Added in version 2.0.
The user whose stream to display for this invite, required if target_type is TargetType.stream. The user must be streaming in the channel.
Added in version 2.0.
target_application_id (
int|None) --The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.
Added in version 2.0.
target_event (
ScheduledEvent|None) --The scheduled event object to link to the event. Shortcut to
Invite.set_scheduled_event()See
Invite.set_scheduled_event()for more info on event invite linking.Added in version 2.0.
roles (
list[Role|Object] |None) --The roles to give a user when joining through this invite.
You must have the
manage_rolespermission to do this and roles cannot be higher than your own.Added in version 2.8.
target_users_file (
File|None) --A CSV file with a single column of user IDs for all the users able to accept this invite.
You can use
utils.users_to_csv()to generate a virtual CSV file from a sequence of user IDs.Added in version 2.8.
- 戻り値:
The invite that was created.
- 戻り値の型:
- 例外:
HTTPException -- Invite creation failed.
NotFound -- The channel that was passed is a category or an invalid channel.
- await create_webhook(*, name, avatar=None, reason=None)¶
This function is a coroutine.
Creates a webhook for this channel.
Requires
manage_webhookspermissions.バージョン 1.1 で変更: Added the
reasonkeyword-only parameter.- パラメータ:
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Creating the webhook failed.
Forbidden -- You do not have permissions to create a webhook.
- await delete(*, reason=None)¶
This function is a coroutine.
Deletes the channel.
You must have
manage_channelspermission to use this.
- await delete_messages(messages, *, reason=None)¶
This function is a coroutine.
Deletes a list of messages. This is similar to
Message.delete()except it bulk deletes multiple messages.As a special case, if the number of messages is 0, then nothing is done. If the number of messages is 1 then single message delete is done. If it's more than two, then bulk delete is used.
You cannot bulk delete more than 100 messages or messages that are older than 14 days old.
You must have the
manage_messagespermission to use this.- パラメータ:
- 例外:
ClientException -- The number of messages to delete was more than 100.
Forbidden -- You do not have proper permissions to delete the messages.
NotFound -- If single delete, then the message was already deleted.
HTTPException -- Deleting the messages failed.
- 戻り値の型:
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- await follow(*, destination, reason=None)¶
Follows a channel using a webhook.
Only news channels can be followed.
注釈
The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.
Added in version 1.3.
- パラメータ:
destination (
TextChannel) -- The channel you would like to follow from.The reason for following the channel. Shows up on the destination guild's audit log.
Added in version 1.4.
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Following the channel failed.
Forbidden -- You do not have the permissions to create a webhook.
- get_partial_message(message_id, /)¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
Added in version 1.6.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- get_thread(thread_id, /)¶
Returns a thread with the given ID.
Added in version 2.0.
- await invites()¶
This function is a coroutine.
Returns a list of all active instant invites from this channel.
You must have
manage_channelsto get this information.- 戻り値:
The list of invites that are currently active.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- property last_message: Message | None¶
Fetches the last message from this channel in cache.
The message might not be valid or point to an existing message.
Reliable Fetching
For a slightly more reliable method of fetching the last message, consider using either
history()orfetch_message()with thelast_message_idattribute.- 戻り値:
The last message in this channel or
Noneif not found.- 戻り値の型:
Optional[
Message]
- await move(**kwargs)¶
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 the
manage_channelspermission to do this.注釈
Voice channels will always be sorted below text channels. This is a Discord limitation.
Added in version 1.7.
- パラメータ:
beginning (
bool) -- Whether to move the channel to the beginning of the channel list (or category if given). This is mutually exclusive withend,before, andafter.end (
bool) -- Whether to move the channel to the end of the channel list (or category if given). This is mutually exclusive withbeginning,before, andafter.before (
Snowflake) -- The channel that should be before our current channel. This is mutually exclusive withbeginning,end, andafter.after (
Snowflake) -- The channel that should be after our current channel. This is mutually exclusive withbeginning,end, andbefore.offset (
int) -- The number of channels to offset the move by. For example, an offset of2withbeginning=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 thebeginning,end,before, andafterparameters.category (Optional[
Snowflake]) -- The category to move this channel under. IfNoneis 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 (
str) -- The reason for the move.
- 例外:
InvalidArgument -- An invalid position was given or a bad mix of arguments was passed.
Forbidden -- You do not have permissions to move the channel.
HTTPException -- Moving the channel failed.
- 戻り値の型:
- property overwrites: dict[Role | Member, PermissionOverwrite]¶
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 aMemberand the value is the overwrite as aPermissionOverwrite.- 戻り値:
The channel's permission overwrites.
- 戻り値の型:
Dict[Union[
Role,Member],PermissionOverwrite]
- overwrites_for(obj)¶
Returns the channel-specific overwrites for a member or a role.
- permissions_for(obj, /)¶
Handles permission resolution for the
MemberorRole.This function takes into consideration the following cases:
Guild owner
Guild roles
Channel overrides
Member overrides
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
バージョン 2.0 で変更: The object passed in can now be a role object.
- property permissions_synced: bool¶
Whether the permissions for this channel are synced with the category it belongs to.
If there is no category then this is
False.Added in version 1.3.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True, reason=None)¶
This function is a coroutine.
Purges a list of messages that meet the criteria given by the predicate
check. If acheckis not provided then all messages are deleted without discrimination.You must have the
manage_messagespermission to delete messages even if they are your own. Theread_message_historypermission is also needed to retrieve message history.- パラメータ:
limit (
int|None) -- The number of messages to search through. This is not the number of messages that will be deleted, though it can be.check (
Callable[[Message],bool]) -- The function used to check if a message should be deleted. It must take aMessageas its sole parameter.before (
Snowflake|datetime|None) -- Same asbeforeinhistory().after (
Snowflake|datetime|None) -- Same asafterinhistory().around (
Snowflake|datetime|None) -- Same asaroundinhistory().oldest_first (
bool|None) -- Same asoldest_firstinhistory().bulk (
bool) -- IfTrue, use bulk delete. Setting this toFalseis useful for mass-deleting a bot's own messages withoutPermissions.manage_messages. WhenTrue, will fall back to single delete if messages are older than two weeks.reason (
str|None) -- The reason for deleting the messages. Shows up on the audit log.
- 戻り値:
The list of messages that were deleted.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to do the actions required.
HTTPException -- Purging the messages failed.
サンプル
Deleting bot's messages
def is_me(m): return m.author == client.user deleted = await channel.purge(limit=100, check=is_me) await channel.send(f'Deleted {len(deleted)} message(s)')
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- await set_permissions(target, *, overwrite=..., reason=None, **permissions)¶
This function is a coroutine.
Sets the channel specific permission overwrites for a target in the channel.
The
targetparameter should either be aMemberor aRolethat belongs to guild.The
overwriteparameter, if given, must either beNoneorPermissionOverwrite. For convenience, you can pass in keyword arguments denotingPermissionsattributes. If this is done, then you cannot mix the keyword arguments with theoverwriteparameter.If the
overwriteparameter isNone, then the permission overwrites are deleted.You must have the
manage_rolespermission to use this.注釈
This method replaces the old overwrites with the ones given.
サンプル
Setting allow and deny:
await message.channel.set_permissions(message.author, read_messages=True, send_messages=False)
Deleting overwrites
await channel.set_permissions(member, overwrite=None)
Using
PermissionOverwriteoverwrite = discord.PermissionOverwrite() overwrite.send_messages = False overwrite.read_messages = True await channel.set_permissions(member, overwrite=overwrite)
- パラメータ:
target (Union[
Member,Role]) -- The member or role to overwrite permissions for.overwrite (Optional[
PermissionOverwrite]) -- The permissions to allow and deny to the target, orNoneto 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.
- 例外:
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.
InvalidArgument -- The overwrite parameter invalid or the target type was not
RoleorMember.
- await trigger_typing()¶
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.
- 戻り値の型:
- property type: ChannelType¶
The channel's Discord type.
- available_tags
- category
- category_id
- changed_roles
- created_at
- default_auto_archive_duration
- default_reaction_emoji
- default_sort_order
- default_thread_slowmode_delay
- flags
- guidelines
- guild
- id
- jump_url
- last_message
- last_message_id
- members
- mention
- name
- nsfw
- overwrites
- permissions_synced
- position
- requires_tag
- slowmode_delay
- threads
- topic
- type
- defarchived_threads
- asyncclone
- asynccreate_invite
- asynccreate_thread
- asynccreate_webhook
- asyncdelete
- asyncdelete_messages
- asyncedit
- asyncfollow
- defget_partial_message
- defget_tag
- defget_thread
- asyncinvites
- defis_nsfw
- asyncmove
- defoverwrites_for
- defpermissions_for
- asyncpurge
- asyncset_permissions
- asyncwebhooks
- class discord.ForumChannel(*, state, guild, data)[ソース]¶
Represents a Discord forum channel.
- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the channel's hash.
- str(x)
Returns the channel's name.
- topic¶
The channel's topic.
Noneif it doesn't exist.注釈
guidelinesexists as an alternative to this attribute.- Type:
Optional[
str]
- position¶
The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0. Can be
Noneif the channel was received in an interaction.- Type:
Optional[
int]
- last_message_id¶
The last message ID of the message sent to this channel. It may not point to an existing or valid message.
- Type:
Optional[
int]
- slowmode_delay¶
The number of seconds a member must wait between sending messages in this channel. A value of 0 denotes that it is disabled. Bots and users with
manage_channelsormanage_messagesbypass slowmode.- Type:
- nsfw¶
If the channel is marked as "not safe for work".
注釈
To check if the channel or the guild of that channel are marked as NSFW, consider
is_nsfw()instead.- Type:
- default_auto_archive_duration¶
The default auto archive duration in minutes for threads created in this channel.
Added in version 2.0.
- Type:
- flags¶
Extra features of the channel.
Added in version 2.0.
- Type:
- available_tags¶
The set of tags that can be used in a forum channel.
Added in version 2.3.
- Type:
List[
ForumTag]
- default_sort_order¶
The default sort order type used to order posts in this channel.
Added in version 2.3.
- Type:
Optional[
SortOrder]
- default_thread_slowmode_delay¶
The initial slowmode delay to set on newly created threads in this channel.
Added in version 2.3.
- Type:
Optional[
int]
- default_reaction_emoji¶
The default forum reaction emoji.
Added in version 2.5.
- Type:
Optional[
str|discord.GuildEmoji]
- パラメータ:
state (
ConnectionState)guild (
Guild)data (
ForumChannel)
- property requires_tag: bool¶
Whether a tag is required to be specified when creating a thread in this forum or media channel.
Tags are specified in
applied_tags.Added in version 2.3.
- get_tag(id, /)[ソース]¶
Returns the
ForumTagfrom this forum channel with the given ID, if any.Added in version 2.3.
- await edit(*, reason=None, **options)[ソース]¶
This function is a coroutine.
Edits the channel.
You must have the
manage_channelspermission to use this.- パラメータ:
name (
str) -- The new channel name.topic (
str) -- The new channel's topic.position (
int) -- The new channel's position.nsfw (
bool) -- Whether the channel is marked as NSFW.sync_permissions (
bool) -- Whether to sync permissions with the channel's new or pre-existing category. Defaults toFalse.category (Optional[
CategoryChannel]) -- The new category for this channel. Can beNoneto remove the category.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this channel, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.reason (Optional[
str]) -- The reason for editing this channel. Shows up on the audit log.overwrites (Dict[Union[
Role,Member,Snowflake],PermissionOverwrite]) -- The overwrites to apply to channel permissions. Useful for creating secret channels.default_auto_archive_duration (
int) -- The new default auto archive duration in minutes for threads created in this channel. Must be one of60,1440,4320, or10080.ThreadArchiveDurationcan be used alternatively.default_thread_slowmode_delay (
int) --The new default slowmode delay in seconds for threads created in this channel.
Added in version 2.3.
default_sort_order (Optional[
SortOrder]) --The default sort order type to use to order posts in this channel.
Added in version 2.3.
default_reaction_emoji (Optional[
discord.GuildEmoji|int|str]) --The default reaction emoji. Can be a unicode emoji or a custom emoji in the forms:
GuildEmoji, snowflake ID, string representation (eg. '<a:emoji_name:emoji_id>').Added in version 2.5.
available_tags (List[
ForumTag]) --The set of tags that can be used in this channel. Must be less than 20.
Added in version 2.3.
require_tag (
bool) --Whether a tag should be required to be specified when creating a thread in this channel.
Added in version 2.3.
- 戻り値:
The newly edited forum channel. If the edit was only positional then
Noneis returned instead.- 戻り値の型:
Optional[
ForumChannel]- 例外:
InvalidArgument -- If position is less than 0 or greater than the number of channels, or if the permission overwrite information is not in proper form.
Forbidden -- You do not have permissions to edit the channel.
HTTPException -- Editing the channel failed.
- await create_thread(name, content=None, *, embed=None, embeds=None, file=None, files=None, stickers=None, delete_message_after=None, nonce=None, allowed_mentions=None, view=None, applied_tags=None, suppress=False, silent=False, auto_archive_duration=..., slowmode_delay=..., reason=None)[ソース]¶
This function is a coroutine.
Creates a thread in this forum channel.
To create a public thread, you must have
create_public_threads. For a private thread,create_private_threadsis needed instead.Added in version 2.0.
- パラメータ:
name (
str) -- The name of the thread.embeds (
list[Embed] |None) -- A list of embeds to upload. Must be a maximum of 10.files (
list[File] |None) -- A list of files to upload. Must be a maximum of 10.stickers (
Sequence[GuildSticker|StickerItem] |None) -- A list of stickers to upload. Must be a maximum of 3.delete_message_after (
float|None) -- The time to wait before deleting the thread.nonce (
int|str|None) -- The nonce to use for sending this message. If the message was successfully sent, then the message will have a nonce with this value.allowed_mentions (
AllowedMentions|None) -- Controls the mentions being processed in this message. If this is passed, then the object is merged withallowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.view (
BaseView|None) -- A Discord UI View to add to the message.applied_tags (
list[ForumTag] |None) -- A list of tags to apply to the new thread.auto_archive_duration (
Literal[60,1440,4320,10080]) -- The duration in minutes before a thread is automatically archived for inactivity. If not provided, the channel's default auto archive duration is used.slowmode_delay (
int) -- The number of seconds a member must wait between sending messages in the new thread. A value of 0 denotes that it is disabled. Bots and users withmanage_channelsormanage_messagesbypass slowmode. If not provided, the forum channel's default slowmode is used.reason (
str|None) -- The reason for creating a new thread. Shows up on the audit log.suppress (
bool)silent (
bool)
- 戻り値:
The created thread
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to create a thread.
HTTPException -- Starting the thread failed.
- archived_threads(*, private=False, joined=False, limit=50, before=None)¶
Returns an
AsyncIteratorthat iterates over all archived threads in the guild.You must have
read_message_historyto use this. If iterating over private threads thenmanage_threadsis also required.Added in version 2.0.
- パラメータ:
limit (
int|None) -- The number of threads to retrieve. IfNone, retrieves every archived thread in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- Retrieve archived channels before the given date or ID.private (
bool) -- Whether to retrieve private archived threads.joined (
bool) -- Whether to retrieve private archived threads that you've joined. You cannot setjoinedtoTrueandprivatetoFalse.
- 列挙:
Thread-- The archived threads.- 例外:
Forbidden -- You do not have permissions to get archived threads.
HTTPException -- The request to get the archived threads failed.
- 戻り値の型:
ArchivedThreadIterator
- property category: CategoryChannel | None¶
The category this channel belongs to.
If there is no category then this is
None.
- property changed_roles: list[Role]¶
Returns a list of roles that have been overridden from their default values in the
rolesattribute.
- await clone(*, name=None, reason=None)¶
This function is a coroutine.
Clones this channel. This creates a channel with the same properties as this channel.
You must have the
manage_channelspermission to do this.Added in version 1.1.
- パラメータ:
- 戻り値:
The channel that was created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
- await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_event=None, target_type=None, target_user=None, target_application_id=None, roles=None, target_users_file=None)¶
This function is a coroutine.
Creates an instant invite from a text or voice channel.
You must have the
create_instant_invitepermission to do this.- パラメータ:
max_age (
int) -- How long the invite should last in seconds. If it's 0 then the invite doesn't expire. Defaults to0.max_uses (
int) -- How many uses the invite could be used for. If it's 0 then there are unlimited uses. Defaults to0.temporary (
bool) -- Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults toFalse.unique (
bool) -- Indicates if a unique invite URL should be created. Defaults to True. If this is set toFalsethen it will return a previously created invite.reason (
str|None) -- The reason for creating this invite. Shows up on the audit log.target_type (
InviteTarget|None) --The type of target for the voice channel invite, if any.
Added in version 2.0.
The user whose stream to display for this invite, required if target_type is TargetType.stream. The user must be streaming in the channel.
Added in version 2.0.
target_application_id (
int|None) --The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.
Added in version 2.0.
target_event (
ScheduledEvent|None) --The scheduled event object to link to the event. Shortcut to
Invite.set_scheduled_event()See
Invite.set_scheduled_event()for more info on event invite linking.Added in version 2.0.
roles (
list[Role|Object] |None) --The roles to give a user when joining through this invite.
You must have the
manage_rolespermission to do this and roles cannot be higher than your own.Added in version 2.8.
target_users_file (
File|None) --A CSV file with a single column of user IDs for all the users able to accept this invite.
You can use
utils.users_to_csv()to generate a virtual CSV file from a sequence of user IDs.Added in version 2.8.
- 戻り値:
The invite that was created.
- 戻り値の型:
- 例外:
HTTPException -- Invite creation failed.
NotFound -- The channel that was passed is a category or an invalid channel.
- await create_webhook(*, name, avatar=None, reason=None)¶
This function is a coroutine.
Creates a webhook for this channel.
Requires
manage_webhookspermissions.バージョン 1.1 で変更: Added the
reasonkeyword-only parameter.- パラメータ:
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Creating the webhook failed.
Forbidden -- You do not have permissions to create a webhook.
- await delete(*, reason=None)¶
This function is a coroutine.
Deletes the channel.
You must have
manage_channelspermission to use this.
- await delete_messages(messages, *, reason=None)¶
This function is a coroutine.
Deletes a list of messages. This is similar to
Message.delete()except it bulk deletes multiple messages.As a special case, if the number of messages is 0, then nothing is done. If the number of messages is 1 then single message delete is done. If it's more than two, then bulk delete is used.
You cannot bulk delete more than 100 messages or messages that are older than 14 days old.
You must have the
manage_messagespermission to use this.- パラメータ:
- 例外:
ClientException -- The number of messages to delete was more than 100.
Forbidden -- You do not have proper permissions to delete the messages.
NotFound -- If single delete, then the message was already deleted.
HTTPException -- Deleting the messages failed.
- 戻り値の型:
- await follow(*, destination, reason=None)¶
Follows a channel using a webhook.
Only news channels can be followed.
注釈
The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.
Added in version 1.3.
- パラメータ:
destination (
TextChannel) -- The channel you would like to follow from.The reason for following the channel. Shows up on the destination guild's audit log.
Added in version 1.4.
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Following the channel failed.
Forbidden -- You do not have the permissions to create a webhook.
- get_partial_message(message_id, /)¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
Added in version 1.6.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- get_thread(thread_id, /)¶
Returns a thread with the given ID.
Added in version 2.0.
- await invites()¶
This function is a coroutine.
Returns a list of all active instant invites from this channel.
You must have
manage_channelsto get this information.- 戻り値:
The list of invites that are currently active.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- property last_message: Message | None¶
Fetches the last message from this channel in cache.
The message might not be valid or point to an existing message.
Reliable Fetching
For a slightly more reliable method of fetching the last message, consider using either
history()orfetch_message()with thelast_message_idattribute.- 戻り値:
The last message in this channel or
Noneif not found.- 戻り値の型:
Optional[
Message]
- await move(**kwargs)¶
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 the
manage_channelspermission to do this.注釈
Voice channels will always be sorted below text channels. This is a Discord limitation.
Added in version 1.7.
- パラメータ:
beginning (
bool) -- Whether to move the channel to the beginning of the channel list (or category if given). This is mutually exclusive withend,before, andafter.end (
bool) -- Whether to move the channel to the end of the channel list (or category if given). This is mutually exclusive withbeginning,before, andafter.before (
Snowflake) -- The channel that should be before our current channel. This is mutually exclusive withbeginning,end, andafter.after (
Snowflake) -- The channel that should be after our current channel. This is mutually exclusive withbeginning,end, andbefore.offset (
int) -- The number of channels to offset the move by. For example, an offset of2withbeginning=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 thebeginning,end,before, andafterparameters.category (Optional[
Snowflake]) -- The category to move this channel under. IfNoneis 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 (
str) -- The reason for the move.
- 例外:
InvalidArgument -- An invalid position was given or a bad mix of arguments was passed.
Forbidden -- You do not have permissions to move the channel.
HTTPException -- Moving the channel failed.
- 戻り値の型:
- property overwrites: dict[Role | Member, PermissionOverwrite]¶
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 aMemberand the value is the overwrite as aPermissionOverwrite.- 戻り値:
The channel's permission overwrites.
- 戻り値の型:
Dict[Union[
Role,Member],PermissionOverwrite]
- overwrites_for(obj)¶
Returns the channel-specific overwrites for a member or a role.
- permissions_for(obj, /)¶
Handles permission resolution for the
MemberorRole.This function takes into consideration the following cases:
Guild owner
Guild roles
Channel overrides
Member overrides
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
バージョン 2.0 で変更: The object passed in can now be a role object.
- property permissions_synced: bool¶
Whether the permissions for this channel are synced with the category it belongs to.
If there is no category then this is
False.Added in version 1.3.
- await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True, reason=None)¶
This function is a coroutine.
Purges a list of messages that meet the criteria given by the predicate
check. If acheckis not provided then all messages are deleted without discrimination.You must have the
manage_messagespermission to delete messages even if they are your own. Theread_message_historypermission is also needed to retrieve message history.- パラメータ:
limit (
int|None) -- The number of messages to search through. This is not the number of messages that will be deleted, though it can be.check (
Callable[[Message],bool]) -- The function used to check if a message should be deleted. It must take aMessageas its sole parameter.before (
Snowflake|datetime|None) -- Same asbeforeinhistory().after (
Snowflake|datetime|None) -- Same asafterinhistory().around (
Snowflake|datetime|None) -- Same asaroundinhistory().oldest_first (
bool|None) -- Same asoldest_firstinhistory().bulk (
bool) -- IfTrue, use bulk delete. Setting this toFalseis useful for mass-deleting a bot's own messages withoutPermissions.manage_messages. WhenTrue, will fall back to single delete if messages are older than two weeks.reason (
str|None) -- The reason for deleting the messages. Shows up on the audit log.
- 戻り値:
The list of messages that were deleted.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to do the actions required.
HTTPException -- Purging the messages failed.
サンプル
Deleting bot's messages
def is_me(m): return m.author == client.user deleted = await channel.purge(limit=100, check=is_me) await channel.send(f'Deleted {len(deleted)} message(s)')
- await set_permissions(target, *, overwrite=..., reason=None, **permissions)¶
This function is a coroutine.
Sets the channel specific permission overwrites for a target in the channel.
The
targetparameter should either be aMemberor aRolethat belongs to guild.The
overwriteparameter, if given, must either beNoneorPermissionOverwrite. For convenience, you can pass in keyword arguments denotingPermissionsattributes. If this is done, then you cannot mix the keyword arguments with theoverwriteparameter.If the
overwriteparameter isNone, then the permission overwrites are deleted.You must have the
manage_rolespermission to use this.注釈
This method replaces the old overwrites with the ones given.
サンプル
Setting allow and deny:
await message.channel.set_permissions(message.author, read_messages=True, send_messages=False)
Deleting overwrites
await channel.set_permissions(member, overwrite=None)
Using
PermissionOverwriteoverwrite = discord.PermissionOverwrite() overwrite.send_messages = False overwrite.read_messages = True await channel.set_permissions(member, overwrite=overwrite)
- パラメータ:
target (Union[
Member,Role]) -- The member or role to overwrite permissions for.overwrite (Optional[
PermissionOverwrite]) -- The permissions to allow and deny to the target, orNoneto 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.
- 例外:
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.
InvalidArgument -- The overwrite parameter invalid or the target type was not
RoleorMember.
- property type: ChannelType¶
The channel's Discord type.
- available_tags
- category
- category_id
- changed_roles
- created_at
- default_auto_archive_duration
- default_reaction_emoji
- default_sort_order
- default_thread_slowmode_delay
- flags
- guidelines
- guild
- id
- jump_url
- last_message
- last_message_id
- media_download_options_hidden
- members
- mention
- name
- nsfw
- overwrites
- permissions_synced
- position
- requires_tag
- slowmode_delay
- threads
- topic
- type
- defarchived_threads
- asyncclone
- asynccreate_invite
- asynccreate_thread
- asynccreate_webhook
- asyncdelete
- asyncdelete_messages
- asyncedit
- asyncfollow
- defget_partial_message
- defget_tag
- defget_thread
- asyncinvites
- defis_nsfw
- asyncmove
- defoverwrites_for
- defpermissions_for
- asyncpurge
- asyncset_permissions
- asyncwebhooks
- class discord.MediaChannel(*, state, guild, data)[ソース]¶
Represents a Discord media channel. Subclass of
ForumChannel.- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the channel's hash.
- str(x)
Returns the channel's name.
Added in version 2.7.
- topic¶
The channel's topic.
Noneif it doesn't exist.注釈
guidelinesexists as an alternative to this attribute.- Type:
Optional[
str]
- position¶
The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0. Can be
Noneif the channel was received in an interaction.- Type:
Optional[
int]
- last_message_id¶
The last message ID of the message sent to this channel. It may not point to an existing or valid message.
- Type:
Optional[
int]
- slowmode_delay¶
The number of seconds a member must wait between sending messages in this channel. A value of 0 denotes that it is disabled. Bots and users with
manage_channelsormanage_messagesbypass slowmode.- Type:
- nsfw¶
If the channel is marked as "not safe for work".
注釈
To check if the channel or the guild of that channel are marked as NSFW, consider
is_nsfw()instead.- Type:
- default_auto_archive_duration¶
The default auto archive duration in minutes for threads created in this channel.
- Type:
- flags¶
Extra features of the channel.
- Type:
- available_tags¶
The set of tags that can be used in a forum channel.
- Type:
List[
ForumTag]
- default_sort_order¶
The default sort order type used to order posts in this channel.
- Type:
Optional[
SortOrder]
- default_thread_slowmode_delay¶
The initial slowmode delay to set on newly created threads in this channel.
- Type:
Optional[
int]
- default_reaction_emoji¶
The default forum reaction emoji.
- Type:
Optional[
str|discord.GuildEmoji]
- パラメータ:
state (
ConnectionState)guild (
Guild)data (
ForumChannel)
Whether media download options are hidden in this media channel.
Added in version 2.7.
- await edit(*, reason=None, **options)[ソース]¶
This function is a coroutine.
Edits the channel.
You must have the
manage_channelspermission to use this.- パラメータ:
name (
str) -- The new channel name.topic (
str) -- The new channel's topic.position (
int) -- The new channel's position.nsfw (
bool) -- Whether the channel is marked as NSFW.sync_permissions (
bool) -- Whether to sync permissions with the channel's new or pre-existing category. Defaults toFalse.category (Optional[
CategoryChannel]) -- The new category for this channel. Can beNoneto remove the category.slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this channel, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.reason (Optional[
str]) -- The reason for editing this channel. Shows up on the audit log.overwrites (Dict[Union[
Role,Member,Snowflake],PermissionOverwrite]) -- The overwrites to apply to channel permissions. Useful for creating secret channels.default_auto_archive_duration (
int) -- The new default auto archive duration in minutes for threads created in this channel. Must be one of60,1440,4320, or10080.default_thread_slowmode_delay (
int) -- The new default slowmode delay in seconds for threads created in this channel.default_sort_order (Optional[
SortOrder]) -- The default sort order type to use to order posts in this channel.default_reaction_emoji (Optional[
discord.GuildEmoji|int|str]) -- The default reaction emoji. Can be a unicode emoji or a custom emoji in the forms:GuildEmoji, snowflake ID, string representation (e.g., '<a:emoji_name:emoji_id>').available_tags (List[
ForumTag]) -- The set of tags that can be used in this channel. Must be less than 20.require_tag (
bool) -- Whether a tag should be required to be specified when creating a thread in this channel.hide_media_download_options (
bool) -- Whether media download options should be hidden in this media channel.
- 戻り値:
The newly edited media channel. If the edit was only positional then
Noneis returned instead.- 戻り値の型:
Optional[
MediaChannel]- 例外:
InvalidArgument -- If position is less than 0 or greater than the number of channels, or if the permission overwrite information is not in proper form.
Forbidden -- You do not have permissions to edit the channel.
HTTPException -- Editing the channel failed.
- archived_threads(*, private=False, joined=False, limit=50, before=None)¶
Returns an
AsyncIteratorthat iterates over all archived threads in the guild.You must have
read_message_historyto use this. If iterating over private threads thenmanage_threadsis also required.Added in version 2.0.
- パラメータ:
limit (
int|None) -- The number of threads to retrieve. IfNone, retrieves every archived thread in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- Retrieve archived channels before the given date or ID.private (
bool) -- Whether to retrieve private archived threads.joined (
bool) -- Whether to retrieve private archived threads that you've joined. You cannot setjoinedtoTrueandprivatetoFalse.
- 列挙:
Thread-- The archived threads.- 例外:
Forbidden -- You do not have permissions to get archived threads.
HTTPException -- The request to get the archived threads failed.
- 戻り値の型:
ArchivedThreadIterator
- property category: CategoryChannel | None¶
The category this channel belongs to.
If there is no category then this is
None.
- property changed_roles: list[Role]¶
Returns a list of roles that have been overridden from their default values in the
rolesattribute.
- await clone(*, name=None, reason=None)¶
This function is a coroutine.
Clones this channel. This creates a channel with the same properties as this channel.
You must have the
manage_channelspermission to do this.Added in version 1.1.
- パラメータ:
- 戻り値:
The channel that was created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
- await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_event=None, target_type=None, target_user=None, target_application_id=None, roles=None, target_users_file=None)¶
This function is a coroutine.
Creates an instant invite from a text or voice channel.
You must have the
create_instant_invitepermission to do this.- パラメータ:
max_age (
int) -- How long the invite should last in seconds. If it's 0 then the invite doesn't expire. Defaults to0.max_uses (
int) -- How many uses the invite could be used for. If it's 0 then there are unlimited uses. Defaults to0.temporary (
bool) -- Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults toFalse.unique (
bool) -- Indicates if a unique invite URL should be created. Defaults to True. If this is set toFalsethen it will return a previously created invite.reason (
str|None) -- The reason for creating this invite. Shows up on the audit log.target_type (
InviteTarget|None) --The type of target for the voice channel invite, if any.
Added in version 2.0.
The user whose stream to display for this invite, required if target_type is TargetType.stream. The user must be streaming in the channel.
Added in version 2.0.
target_application_id (
int|None) --The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.
Added in version 2.0.
target_event (
ScheduledEvent|None) --The scheduled event object to link to the event. Shortcut to
Invite.set_scheduled_event()See
Invite.set_scheduled_event()for more info on event invite linking.Added in version 2.0.
roles (
list[Role|Object] |None) --The roles to give a user when joining through this invite.
You must have the
manage_rolespermission to do this and roles cannot be higher than your own.Added in version 2.8.
target_users_file (
File|None) --A CSV file with a single column of user IDs for all the users able to accept this invite.
You can use
utils.users_to_csv()to generate a virtual CSV file from a sequence of user IDs.Added in version 2.8.
- 戻り値:
The invite that was created.
- 戻り値の型:
- 例外:
HTTPException -- Invite creation failed.
NotFound -- The channel that was passed is a category or an invalid channel.
- await create_thread(name, content=None, *, embed=None, embeds=None, file=None, files=None, stickers=None, delete_message_after=None, nonce=None, allowed_mentions=None, view=None, applied_tags=None, suppress=False, silent=False, auto_archive_duration=..., slowmode_delay=..., reason=None)¶
This function is a coroutine.
Creates a thread in this forum channel.
To create a public thread, you must have
create_public_threads. For a private thread,create_private_threadsis needed instead.Added in version 2.0.
- パラメータ:
name (
str) -- The name of the thread.embeds (
list[Embed] |None) -- A list of embeds to upload. Must be a maximum of 10.files (
list[File] |None) -- A list of files to upload. Must be a maximum of 10.stickers (
Sequence[GuildSticker|StickerItem] |None) -- A list of stickers to upload. Must be a maximum of 3.delete_message_after (
float|None) -- The time to wait before deleting the thread.nonce (
int|str|None) -- The nonce to use for sending this message. If the message was successfully sent, then the message will have a nonce with this value.allowed_mentions (
AllowedMentions|None) -- Controls the mentions being processed in this message. If this is passed, then the object is merged withallowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.view (
BaseView|None) -- A Discord UI View to add to the message.applied_tags (
list[ForumTag] |None) -- A list of tags to apply to the new thread.auto_archive_duration (
Literal[60,1440,4320,10080]) -- The duration in minutes before a thread is automatically archived for inactivity. If not provided, the channel's default auto archive duration is used.slowmode_delay (
int) -- The number of seconds a member must wait between sending messages in the new thread. A value of 0 denotes that it is disabled. Bots and users withmanage_channelsormanage_messagesbypass slowmode. If not provided, the forum channel's default slowmode is used.reason (
str|None) -- The reason for creating a new thread. Shows up on the audit log.suppress (
bool)silent (
bool)
- 戻り値:
The created thread
- 戻り値の型:
- 例外:
Forbidden -- You do not have permissions to create a thread.
HTTPException -- Starting the thread failed.
- await create_webhook(*, name, avatar=None, reason=None)¶
This function is a coroutine.
Creates a webhook for this channel.
Requires
manage_webhookspermissions.バージョン 1.1 で変更: Added the
reasonkeyword-only parameter.- パラメータ:
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Creating the webhook failed.
Forbidden -- You do not have permissions to create a webhook.
- await delete(*, reason=None)¶
This function is a coroutine.
Deletes the channel.
You must have
manage_channelspermission to use this.
- await delete_messages(messages, *, reason=None)¶
This function is a coroutine.
Deletes a list of messages. This is similar to
Message.delete()except it bulk deletes multiple messages.As a special case, if the number of messages is 0, then nothing is done. If the number of messages is 1 then single message delete is done. If it's more than two, then bulk delete is used.
You cannot bulk delete more than 100 messages or messages that are older than 14 days old.
You must have the
manage_messagespermission to use this.- パラメータ:
- 例外:
ClientException -- The number of messages to delete was more than 100.
Forbidden -- You do not have proper permissions to delete the messages.
NotFound -- If single delete, then the message was already deleted.
HTTPException -- Deleting the messages failed.
- 戻り値の型:
- await follow(*, destination, reason=None)¶
Follows a channel using a webhook.
Only news channels can be followed.
注釈
The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.
Added in version 1.3.
- パラメータ:
destination (
TextChannel) -- The channel you would like to follow from.The reason for following the channel. Shows up on the destination guild's audit log.
Added in version 1.4.
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Following the channel failed.
Forbidden -- You do not have the permissions to create a webhook.
- get_partial_message(message_id, /)¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
Added in version 1.6.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- get_tag(id, /)¶
Returns the
ForumTagfrom this forum channel with the given ID, if any.Added in version 2.3.
- get_thread(thread_id, /)¶
Returns a thread with the given ID.
Added in version 2.0.
- await invites()¶
This function is a coroutine.
Returns a list of all active instant invites from this channel.
You must have
manage_channelsto get this information.- 戻り値:
The list of invites that are currently active.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- property last_message: Message | None¶
Fetches the last message from this channel in cache.
The message might not be valid or point to an existing message.
Reliable Fetching
For a slightly more reliable method of fetching the last message, consider using either
history()orfetch_message()with thelast_message_idattribute.- 戻り値:
The last message in this channel or
Noneif not found.- 戻り値の型:
Optional[
Message]
- await move(**kwargs)¶
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 the
manage_channelspermission to do this.注釈
Voice channels will always be sorted below text channels. This is a Discord limitation.
Added in version 1.7.
- パラメータ:
beginning (
bool) -- Whether to move the channel to the beginning of the channel list (or category if given). This is mutually exclusive withend,before, andafter.end (
bool) -- Whether to move the channel to the end of the channel list (or category if given). This is mutually exclusive withbeginning,before, andafter.before (
Snowflake) -- The channel that should be before our current channel. This is mutually exclusive withbeginning,end, andafter.after (
Snowflake) -- The channel that should be after our current channel. This is mutually exclusive withbeginning,end, andbefore.offset (
int) -- The number of channels to offset the move by. For example, an offset of2withbeginning=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 thebeginning,end,before, andafterparameters.category (Optional[
Snowflake]) -- The category to move this channel under. IfNoneis 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 (
str) -- The reason for the move.
- 例外:
InvalidArgument -- An invalid position was given or a bad mix of arguments was passed.
Forbidden -- You do not have permissions to move the channel.
HTTPException -- Moving the channel failed.
- 戻り値の型:
- property overwrites: dict[Role | Member, PermissionOverwrite]¶
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 aMemberand the value is the overwrite as aPermissionOverwrite.- 戻り値:
The channel's permission overwrites.
- 戻り値の型:
Dict[Union[
Role,Member],PermissionOverwrite]
- overwrites_for(obj)¶
Returns the channel-specific overwrites for a member or a role.
- permissions_for(obj, /)¶
Handles permission resolution for the
MemberorRole.This function takes into consideration the following cases:
Guild owner
Guild roles
Channel overrides
Member overrides
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
バージョン 2.0 で変更: The object passed in can now be a role object.
- property permissions_synced: bool¶
Whether the permissions for this channel are synced with the category it belongs to.
If there is no category then this is
False.Added in version 1.3.
- await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True, reason=None)¶
This function is a coroutine.
Purges a list of messages that meet the criteria given by the predicate
check. If acheckis not provided then all messages are deleted without discrimination.You must have the
manage_messagespermission to delete messages even if they are your own. Theread_message_historypermission is also needed to retrieve message history.- パラメータ:
limit (
int|None) -- The number of messages to search through. This is not the number of messages that will be deleted, though it can be.check (
Callable[[Message],bool]) -- The function used to check if a message should be deleted. It must take aMessageas its sole parameter.before (
Snowflake|datetime|None) -- Same asbeforeinhistory().after (
Snowflake|datetime|None) -- Same asafterinhistory().around (
Snowflake|datetime|None) -- Same asaroundinhistory().oldest_first (
bool|None) -- Same asoldest_firstinhistory().bulk (
bool) -- IfTrue, use bulk delete. Setting this toFalseis useful for mass-deleting a bot's own messages withoutPermissions.manage_messages. WhenTrue, will fall back to single delete if messages are older than two weeks.reason (
str|None) -- The reason for deleting the messages. Shows up on the audit log.
- 戻り値:
The list of messages that were deleted.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to do the actions required.
HTTPException -- Purging the messages failed.
サンプル
Deleting bot's messages
def is_me(m): return m.author == client.user deleted = await channel.purge(limit=100, check=is_me) await channel.send(f'Deleted {len(deleted)} message(s)')
- property requires_tag: bool¶
Whether a tag is required to be specified when creating a thread in this forum or media channel.
Tags are specified in
applied_tags.Added in version 2.3.
- await set_permissions(target, *, overwrite=..., reason=None, **permissions)¶
This function is a coroutine.
Sets the channel specific permission overwrites for a target in the channel.
The
targetparameter should either be aMemberor aRolethat belongs to guild.The
overwriteparameter, if given, must either beNoneorPermissionOverwrite. For convenience, you can pass in keyword arguments denotingPermissionsattributes. If this is done, then you cannot mix the keyword arguments with theoverwriteparameter.If the
overwriteparameter isNone, then the permission overwrites are deleted.You must have the
manage_rolespermission to use this.注釈
This method replaces the old overwrites with the ones given.
サンプル
Setting allow and deny:
await message.channel.set_permissions(message.author, read_messages=True, send_messages=False)
Deleting overwrites
await channel.set_permissions(member, overwrite=None)
Using
PermissionOverwriteoverwrite = discord.PermissionOverwrite() overwrite.send_messages = False overwrite.read_messages = True await channel.set_permissions(member, overwrite=overwrite)
- パラメータ:
target (Union[
Member,Role]) -- The member or role to overwrite permissions for.overwrite (Optional[
PermissionOverwrite]) -- The permissions to allow and deny to the target, orNoneto 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.
- 例外:
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.
InvalidArgument -- The overwrite parameter invalid or the target type was not
RoleorMember.
- property type: ChannelType¶
The channel's Discord type.
- defcan_send
- asyncclone
- asyncconnect
- asynccreate_activity_invite
- asynccreate_invite
- asynccreate_webhook
- asyncdelete
- asyncdelete_messages
- asyncedit
- asyncfetch_message
- defget_partial_message
- defhistory
- asyncinvites
- defis_nsfw
- asyncmove
- defoverwrites_for
- defpermissions_for
- defpins
- asyncpurge
- asyncsend
- asyncsend_soundboard_sound
- asyncset_permissions
- asyncset_status
- asynctrigger_typing
- deftyping
- asyncwebhooks
- class discord.VoiceChannel(*, state, guild, data)[ソース]¶
Represents a Discord guild voice channel.
- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the channel's hash.
- str(x)
Returns the channel's name.
- position¶
The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0. Can be
Noneif the channel was received in an interaction.- Type:
Optional[
int]
- rtc_region¶
The region for the voice channel's voice communication. A value of
Noneindicates automatic voice region detection.Added in version 1.7.
- Type:
Optional[
VoiceRegion]
- video_quality_mode¶
The camera video quality for the voice channel's participants.
Added in version 2.0.
- Type:
- last_message_id¶
The ID of the last message sent to this channel. It may not always point to an existing or valid message.
Added in version 2.0.
- Type:
Optional[
int]
- slowmode_delay¶
The number of seconds a member must wait between sending messages in this channel. A value of 0 denotes that it is disabled. Bots and users with
manage_channelsormanage_messagesbypass slowmode.Added in version 2.5.
- Type:
- flags¶
Extra features of the channel.
Added in version 2.0.
- Type:
- パラメータ:
state (
ConnectionState)guild (
Guild)data (
VoiceChannel)
- property last_message: Message | None¶
Fetches the last message from this channel in cache.
The message might not be valid or point to an existing message.
Reliable Fetching
For a slightly more reliable method of fetching the last message, consider using either
history()orfetch_message()with thelast_message_idattribute.- 戻り値:
The last message in this channel or
Noneif not found.- 戻り値の型:
Optional[
Message]
- get_partial_message(message_id, /)[ソース]¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
Added in version 1.6.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- await delete_messages(messages, *, reason=None)[ソース]¶
This function is a coroutine.
Deletes a list of messages. This is similar to
Message.delete()except it bulk deletes multiple messages.As a special case, if the number of messages is 0, then nothing is done. If the number of messages is 1 then single message delete is done. If it's more than two, then bulk delete is used.
You cannot bulk delete more than 100 messages or messages that are older than 14 days old.
You must have the
manage_messagespermission to use this.- パラメータ:
- 例外:
ClientException -- The number of messages to delete was more than 100.
Forbidden -- You do not have proper permissions to delete the messages.
NotFound -- If single delete, then the message was already deleted.
HTTPException -- Deleting the messages failed.
- 戻り値の型:
- await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True, reason=None)[ソース]¶
This function is a coroutine.
Purges a list of messages that meet the criteria given by the predicate
check. If acheckis not provided then all messages are deleted without discrimination.You must have the
manage_messagespermission to delete messages even if they are your own. Theread_message_historypermission is also needed to retrieve message history.- パラメータ:
limit (
int|None) -- The number of messages to search through. This is not the number of messages that will be deleted, though it can be.check (
Callable[[Message],bool]) -- The function used to check if a message should be deleted. It must take aMessageas its sole parameter.before (
Snowflake|datetime|None) -- Same asbeforeinhistory().after (
Snowflake|datetime|None) -- Same asafterinhistory().around (
Snowflake|datetime|None) -- Same asaroundinhistory().oldest_first (
bool|None) -- Same asoldest_firstinhistory().bulk (
bool) -- IfTrue, use bulk delete. Setting this toFalseis useful for mass-deleting a bot's own messages withoutPermissions.manage_messages. WhenTrue, will fall back to single delete if messages are older than two weeks.reason (
str|None) -- The reason for deleting the messages. Shows up on the audit log.
- 戻り値:
The list of messages that were deleted.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to do the actions required.
HTTPException -- Purging the messages failed.
サンプル
Deleting bot's messages
def is_me(m): return m.author == client.user deleted = await channel.purge(limit=100, check=is_me) await channel.send(f'Deleted {len(deleted)} message(s)')
- await webhooks()[ソース]¶
This function is a coroutine.
Gets the list of webhooks from this channel.
Requires
manage_webhookspermissions.
- await create_webhook(*, name, avatar=None, reason=None)[ソース]¶
This function is a coroutine.
Creates a webhook for this channel.
Requires
manage_webhookspermissions.バージョン 1.1 で変更: Added the
reasonkeyword-only parameter.- パラメータ:
- 戻り値:
The created webhook.
- 戻り値の型:
- 例外:
HTTPException -- Creating the webhook failed.
Forbidden -- You do not have permissions to create a webhook.
- property type: ChannelType¶
The channel's Discord type.
- await clone(*, name=None, reason=None)[ソース]¶
This function is a coroutine.
Clones this channel. This creates a channel with the same properties as this channel.
You must have the
manage_channelspermission to do this.Added in version 1.1.
- パラメータ:
- 戻り値:
The channel that was created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
- await edit(*, reason=None, **options)[ソース]¶
This function is a coroutine.
Edits the channel.
You must have the
manage_channelspermission to use this.バージョン 1.3 で変更: The
overwriteskeyword-only parameter was added.バージョン 2.0 で変更: Edits are no longer in-place, the newly edited channel is returned instead.
- パラメータ:
name (
str) -- The new channel's name.bitrate (
int) -- The new channel's bitrate.user_limit (
int) -- The new channel's user limit.position (
int) -- The new channel's position.sync_permissions (
bool) -- Whether to sync permissions with the channel's new or pre-existing category. Defaults toFalse.category (Optional[
CategoryChannel]) -- The new category for this channel. Can beNoneto remove the category.reason (Optional[
str]) -- The reason for editing this channel. Shows up on the audit log.overwrites (Dict[Union[
Role,Member,Snowflake],PermissionOverwrite]) -- The overwrites to apply to channel permissions. Useful for creating secret channels.rtc_region (Optional[
VoiceRegion]) --The new region for the voice channel's voice communication. A value of
Noneindicates automatic voice region detection.Added in version 1.7.
video_quality_mode (
VideoQualityMode) --The camera video quality for the voice channel's participants.
Added in version 2.0.
slowmode_delay (
int) -- Specifies the slowmode rate limit for user in this channel, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.nsfw (
bool) --Whether the channel is marked as NSFW.
Added in version 2.7.
- 戻り値:
The newly edited voice channel. If the edit was only positional then
Noneis returned instead.- 戻り値の型:
Optional[
VoiceChannel]- 例外:
InvalidArgument -- If the permission overwrite information is not in proper form.
Forbidden -- You do not have permissions to edit the channel.
HTTPException -- Editing the channel failed.
- await create_activity_invite(activity, **kwargs)[ソース]¶
This function is a coroutine.
A shortcut method that creates an instant activity invite.
You must have the
start_embedded_activitiespermission to do this.- パラメータ:
activity (
EmbeddedActivity|int) -- The activity to create an invite for which can be an application id as well.max_age (
int) -- How long the invite should last in seconds. If it's 0 then the invite doesn't expire. Defaults to0.max_uses (
int) -- How many uses the invite could be used for. If it's 0 then there are unlimited uses. Defaults to0.temporary (
bool) -- Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults toFalse.unique (
bool) -- Indicates if a unique invite URL should be created. Defaults to True. If this is set toFalsethen it will return a previously created invite.reason (Optional[
str]) -- The reason for creating this invite. Shows up on the audit log.
- 戻り値:
The invite that was created.
- 戻り値の型:
- 例外:
TypeError -- If the activity is not a valid activity or application id.
HTTPException -- Invite creation failed.
- await set_status(status, *, reason=None)[ソース]¶
This function is a coroutine.
Sets the status of the voice channel.
You must have the
set_voice_channel_statuspermission to use this.
- await send_soundboard_sound(sound)[ソース]¶
This function is a coroutine.
Sends a soundboard sound to the voice channel.
- パラメータ:
sound (
PartialSoundboardSound) -- The soundboard sound to send.- 例外:
Forbidden -- You do not have proper permissions to send the soundboard sound.
HTTPException -- Sending the soundboard sound failed.
- 戻り値の型:
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- property category: CategoryChannel | None¶
The category this channel belongs to.
If there is no category then this is
None.
- property changed_roles: list[Role]¶
Returns a list of roles that have been overridden from their default values in the
rolesattribute.
- await connect(*, timeout=60.0, reconnect=True, cls=...)¶
This function is a coroutine.
Connects to voice and creates a
VoiceClientto establish your connection to the voice server.This requires
Intents.voice_states.- パラメータ:
timeout (
float) -- The timeout in seconds to wait for the voice endpoint.reconnect (
bool) -- Whether the bot should automatically attempt a reconnect if a part of the handshake fails or the gateway goes down.cls (
Callable[[Client,Connectable],TypeVar(T, bound=VoiceProtocol)]) -- A type that subclassesVoiceProtocolto connect with. Defaults toVoiceClient.
- 戻り値:
A voice client that is fully connected to the voice server.
- 戻り値の型:
TypeVar(T, bound=VoiceProtocol)- 例外:
asyncio.TimeoutError -- Could not connect to the voice channel in time.
ClientException -- You are already connected to a voice channel.
OpusNotLoaded -- The opus library has not been loaded.
- await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_event=None, target_type=None, target_user=None, target_application_id=None, roles=None, target_users_file=None)¶
This function is a coroutine.
Creates an instant invite from a text or voice channel.
You must have the
create_instant_invitepermission to do this.- パラメータ:
max_age (
int) -- How long the invite should last in seconds. If it's 0 then the invite doesn't expire. Defaults to0.max_uses (
int) -- How many uses the invite could be used for. If it's 0 then there are unlimited uses. Defaults to0.temporary (
bool) -- Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults toFalse.unique (
bool) -- Indicates if a unique invite URL should be created. Defaults to True. If this is set toFalsethen it will return a previously created invite.reason (
str|None) -- The reason for creating this invite. Shows up on the audit log.target_type (
InviteTarget|None) --The type of target for the voice channel invite, if any.
Added in version 2.0.
The user whose stream to display for this invite, required if target_type is TargetType.stream. The user must be streaming in the channel.
Added in version 2.0.
target_application_id (
int|None) --The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.
Added in version 2.0.
target_event (
ScheduledEvent|None) --The scheduled event object to link to the event. Shortcut to
Invite.set_scheduled_event()See
Invite.set_scheduled_event()for more info on event invite linking.Added in version 2.0.
roles (
list[Role|Object] |None) --The roles to give a user when joining through this invite.
You must have the
manage_rolespermission to do this and roles cannot be higher than your own.Added in version 2.8.
target_users_file (
File|None) --A CSV file with a single column of user IDs for all the users able to accept this invite.
You can use
utils.users_to_csv()to generate a virtual CSV file from a sequence of user IDs.Added in version 2.8.
- 戻り値:
The invite that was created.
- 戻り値の型:
- 例外:
HTTPException -- Invite creation failed.
NotFound -- The channel that was passed is a category or an invalid channel.
- await delete(*, reason=None)¶
This function is a coroutine.
Deletes the channel.
You must have
manage_channelspermission to use this.
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- await invites()¶
This function is a coroutine.
Returns a list of all active instant invites from this channel.
You must have
manage_channelsto get this information.- 戻り値:
The list of invites that are currently active.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- await move(**kwargs)¶
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 the
manage_channelspermission to do this.注釈
Voice channels will always be sorted below text channels. This is a Discord limitation.
Added in version 1.7.
- パラメータ:
beginning (
bool) -- Whether to move the channel to the beginning of the channel list (or category if given). This is mutually exclusive withend,before, andafter.end (
bool) -- Whether to move the channel to the end of the channel list (or category if given). This is mutually exclusive withbeginning,before, andafter.before (
Snowflake) -- The channel that should be before our current channel. This is mutually exclusive withbeginning,end, andafter.after (
Snowflake) -- The channel that should be after our current channel. This is mutually exclusive withbeginning,end, andbefore.offset (
int) -- The number of channels to offset the move by. For example, an offset of2withbeginning=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 thebeginning,end,before, andafterparameters.category (Optional[
Snowflake]) -- The category to move this channel under. IfNoneis 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 (
str) -- The reason for the move.
- 例外:
InvalidArgument -- An invalid position was given or a bad mix of arguments was passed.
Forbidden -- You do not have permissions to move the channel.
HTTPException -- Moving the channel failed.
- 戻り値の型:
- property overwrites: dict[Role | Member, PermissionOverwrite]¶
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 aMemberand the value is the overwrite as aPermissionOverwrite.- 戻り値:
The channel's permission overwrites.
- 戻り値の型:
Dict[Union[
Role,Member],PermissionOverwrite]
- overwrites_for(obj)¶
Returns the channel-specific overwrites for a member or a role.
- permissions_for(obj, /)¶
Handles permission resolution for the
MemberorRole.This function takes into consideration the following cases:
Guild owner
Guild roles
Channel overrides
Member overrides
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
バージョン 2.0 で変更: The object passed in can now be a role object.
- property permissions_synced: bool¶
Whether the permissions for this channel are synced with the category it belongs to.
If there is no category then this is
False.Added in version 1.3.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- await set_permissions(target, *, overwrite=..., reason=None, **permissions)¶
This function is a coroutine.
Sets the channel specific permission overwrites for a target in the channel.
The
targetparameter should either be aMemberor aRolethat belongs to guild.The
overwriteparameter, if given, must either beNoneorPermissionOverwrite. For convenience, you can pass in keyword arguments denotingPermissionsattributes. If this is done, then you cannot mix the keyword arguments with theoverwriteparameter.If the
overwriteparameter isNone, then the permission overwrites are deleted.You must have the
manage_rolespermission to use this.注釈
This method replaces the old overwrites with the ones given.
サンプル
Setting allow and deny:
await message.channel.set_permissions(message.author, read_messages=True, send_messages=False)
Deleting overwrites
await channel.set_permissions(member, overwrite=None)
Using
PermissionOverwriteoverwrite = discord.PermissionOverwrite() overwrite.send_messages = False overwrite.read_messages = True await channel.set_permissions(member, overwrite=overwrite)
- パラメータ:
target (Union[
Member,Role]) -- The member or role to overwrite permissions for.overwrite (Optional[
PermissionOverwrite]) -- The permissions to allow and deny to the target, orNoneto 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.
- 例外:
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.
InvalidArgument -- The overwrite parameter invalid or the target type was not
RoleorMember.
- await trigger_typing()¶
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.
- 戻り値の型:
- typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- property voice_states: dict[int, VoiceState]¶
Returns a mapping of member IDs who have voice states in this channel.
Added in version 1.3.
注釈
This function is intentionally low level to replace
memberswhen the member cache is unavailable.- 戻り値:
The mapping of member ID to a voice state.
- 戻り値の型:
Mapping[
int,VoiceState]
- asyncclone
- asynccreate_forum_channel
- asynccreate_invite
- asynccreate_stage_channel
- asynccreate_text_channel
- asynccreate_voice_channel
- asyncdelete
- asyncedit
- asyncinvites
- asyncmove
- defoverwrites_for
- defpermissions_for
- asyncset_permissions
- class discord.CategoryChannel(*, state, guild, data)[ソース]¶
Represents a Discord channel category.
These are useful to group channels to logical compartments.
- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the category's hash.
- str(x)
Returns the category's name.
- position¶
The position in the category list. This is a number that starts at 0. e.g. the top category is position 0. Can be
Noneif the channel was received in an interaction.- Type:
Optional[
int]
- flags¶
Extra features of the channel.
Added in version 2.0.
- Type:
- パラメータ:
state (
ConnectionState)guild (
Guild)data (
CategoryChannel)
- property type: ChannelType¶
The channel's Discord type.
- await clone(*, name=None, reason=None)[ソース]¶
This function is a coroutine.
Clones this channel. This creates a channel with the same properties as this channel.
You must have the
manage_channelspermission to do this.Added in version 1.1.
- パラメータ:
- 戻り値:
The channel that was created.
- 戻り値の型:
- 例外:
Forbidden -- You do not have the proper permissions to create this channel.
HTTPException -- Creating the channel failed.
- await edit(*, reason=None, **options)[ソース]¶
This function is a coroutine.
Edits the channel.
You must have the
manage_channelspermission to use this.バージョン 1.3 で変更: The
overwriteskeyword-only parameter was added.バージョン 2.0 で変更: Edits are no longer in-place, the newly edited channel is returned instead.
- パラメータ:
name (
str) -- The new category's name.position (
int) -- The new category's position.reason (Optional[
str]) -- The reason for editing this category. Shows up on the audit log.overwrites (Dict[Union[
Role,Member,Snowflake],PermissionOverwrite]) -- The overwrites to apply to channel permissions. Useful for creating secret channels.
- 戻り値:
The newly edited category channel. If the edit was only positional then
Noneis returned instead.- 戻り値の型:
Optional[
CategoryChannel]- 例外:
InvalidArgument -- If position is less than 0 or greater than the number of categories.
Forbidden -- You do not have permissions to edit the category.
HTTPException -- Editing the category failed.
- await move(**kwargs) None[ソース]¶
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 the
manage_channelspermission to do this.注釈
Voice channels will always be sorted below text channels. This is a Discord limitation.
Added in version 1.7.
- パラメータ:
beginning (
bool) -- Whether to move the channel to the beginning of the channel list (or category if given). This is mutually exclusive withend,before, andafter.end (
bool) -- Whether to move the channel to the end of the channel list (or category if given). This is mutually exclusive withbeginning,before, andafter.before (
Snowflake) -- The channel that should be before our current channel. This is mutually exclusive withbeginning,end, andafter.after (
Snowflake) -- The channel that should be after our current channel. This is mutually exclusive withbeginning,end, andbefore.offset (
int) -- The number of channels to offset the move by. For example, an offset of2withbeginning=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 thebeginning,end,before, andafterparameters.category (Optional[
Snowflake]) -- The category to move this channel under. IfNoneis 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 (
str) -- The reason for the move.
- 例外:
InvalidArgument -- An invalid position was given or a bad mix of arguments was passed.
Forbidden -- You do not have permissions to move the channel.
HTTPException -- Moving the channel failed.
- property channels: list[VoiceChannel | StageChannel | TextChannel | ForumChannel | CategoryChannel]¶
Returns the channels that are under this category.
These are sorted by the official Discord UI, which places voice channels below the text channels.
- property text_channels: list[TextChannel]¶
Returns the text channels that are under this category.
- property voice_channels: list[VoiceChannel]¶
Returns the voice channels that are under this category.
- property stage_channels: list[StageChannel]¶
Returns the stage channels that are under this category.
Added in version 1.7.
- property forum_channels: list[ForumChannel]¶
Returns the forum channels that are under this category.
Added in version 2.0.
- await create_text_channel(name, **options)[ソース]¶
This function is a coroutine.
A shortcut method to
Guild.create_text_channel()to create aTextChannelin the category.- 戻り値:
The channel that was just created.
- 戻り値の型:
- パラメータ:
- await create_voice_channel(name, **options)[ソース]¶
This function is a coroutine.
A shortcut method to
Guild.create_voice_channel()to create aVoiceChannelin the category.- 戻り値:
The channel that was just created.
- 戻り値の型:
- パラメータ:
- await create_stage_channel(name, **options)[ソース]¶
This function is a coroutine.
A shortcut method to
Guild.create_stage_channel()to create aStageChannelin the category.Added in version 1.7.
- 戻り値:
The channel that was just created.
- 戻り値の型:
- パラメータ:
- await create_forum_channel(name, **options)[ソース]¶
This function is a coroutine.
A shortcut method to
Guild.create_forum_channel()to create aForumChannelin the category.Added in version 2.0.
- 戻り値:
The channel that was just created.
- 戻り値の型:
- パラメータ:
- property category: CategoryChannel | None¶
The category this channel belongs to.
If there is no category then this is
None.
- property changed_roles: list[Role]¶
Returns a list of roles that have been overridden from their default values in the
rolesattribute.
- await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_event=None, target_type=None, target_user=None, target_application_id=None, roles=None, target_users_file=None)¶
This function is a coroutine.
Creates an instant invite from a text or voice channel.
You must have the
create_instant_invitepermission to do this.- パラメータ:
max_age (
int) -- How long the invite should last in seconds. If it's 0 then the invite doesn't expire. Defaults to0.max_uses (
int) -- How many uses the invite could be used for. If it's 0 then there are unlimited uses. Defaults to0.temporary (
bool) -- Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults toFalse.unique (
bool) -- Indicates if a unique invite URL should be created. Defaults to True. If this is set toFalsethen it will return a previously created invite.reason (
str|None) -- The reason for creating this invite. Shows up on the audit log.target_type (
InviteTarget|None) --The type of target for the voice channel invite, if any.
Added in version 2.0.
The user whose stream to display for this invite, required if target_type is TargetType.stream. The user must be streaming in the channel.
Added in version 2.0.
target_application_id (
int|None) --The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.
Added in version 2.0.
target_event (
ScheduledEvent|None) --The scheduled event object to link to the event. Shortcut to
Invite.set_scheduled_event()See
Invite.set_scheduled_event()for more info on event invite linking.Added in version 2.0.
roles (
list[Role|Object] |None) --The roles to give a user when joining through this invite.
You must have the
manage_rolespermission to do this and roles cannot be higher than your own.Added in version 2.8.
target_users_file (
File|None) --A CSV file with a single column of user IDs for all the users able to accept this invite.
You can use
utils.users_to_csv()to generate a virtual CSV file from a sequence of user IDs.Added in version 2.8.
- 戻り値:
The invite that was created.
- 戻り値の型:
- 例外:
HTTPException -- Invite creation failed.
NotFound -- The channel that was passed is a category or an invalid channel.
- await delete(*, reason=None)¶
This function is a coroutine.
Deletes the channel.
You must have
manage_channelspermission to use this.
- await invites()¶
This function is a coroutine.
Returns a list of all active instant invites from this channel.
You must have
manage_channelsto get this information.- 戻り値:
The list of invites that are currently active.
- 戻り値の型:
- 例外:
Forbidden -- You do not have proper permissions to get the information.
HTTPException -- An error occurred while fetching the information.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- property overwrites: dict[Role | Member, PermissionOverwrite]¶
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 aMemberand the value is the overwrite as aPermissionOverwrite.- 戻り値:
The channel's permission overwrites.
- 戻り値の型:
Dict[Union[
Role,Member],PermissionOverwrite]
- overwrites_for(obj)¶
Returns the channel-specific overwrites for a member or a role.
- permissions_for(obj, /)¶
Handles permission resolution for the
MemberorRole.This function takes into consideration the following cases:
Guild owner
Guild roles
Channel overrides
Member overrides
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
バージョン 2.0 で変更: The object passed in can now be a role object.
- property permissions_synced: bool¶
Whether the permissions for this channel are synced with the category it belongs to.
If there is no category then this is
False.Added in version 1.3.
- await set_permissions(target, *, overwrite=..., reason=None, **permissions)¶
This function is a coroutine.
Sets the channel specific permission overwrites for a target in the channel.
The
targetparameter should either be aMemberor aRolethat belongs to guild.The
overwriteparameter, if given, must either beNoneorPermissionOverwrite. For convenience, you can pass in keyword arguments denotingPermissionsattributes. If this is done, then you cannot mix the keyword arguments with theoverwriteparameter.If the
overwriteparameter isNone, then the permission overwrites are deleted.You must have the
manage_rolespermission to use this.注釈
This method replaces the old overwrites with the ones given.
サンプル
Setting allow and deny:
await message.channel.set_permissions(message.author, read_messages=True, send_messages=False)
Deleting overwrites
await channel.set_permissions(member, overwrite=None)
Using
PermissionOverwriteoverwrite = discord.PermissionOverwrite() overwrite.send_messages = False overwrite.read_messages = True await channel.set_permissions(member, overwrite=overwrite)
- パラメータ:
target (Union[
Member,Role]) -- The member or role to overwrite permissions for.overwrite (Optional[
PermissionOverwrite]) -- The permissions to allow and deny to the target, orNoneto 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.
- 例外:
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.
InvalidArgument -- The overwrite parameter invalid or the target type was not
RoleorMember.
- defcan_send
- asyncfetch_message
- defget_partial_message
- defhistory
- defpermissions_for
- defpins
- asyncsend
- asynctrigger_typing
- deftyping
- class discord.DMChannel(*, me, state, data)[ソース]¶
Represents a Discord direct message channel.
- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the channel's hash.
- str(x)
Returns a string representation of the channel
- recipient¶
The user you are participating with in the direct message channel. If this channel is received through the gateway, the recipient information may not be always available.
- Type:
Optional[
User]
- me¶
The user presenting yourself.
- Type:
- パラメータ:
me (
ClientUser)state (
ConnectionState)data (
DMChannel)
- async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- async with typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- property type: ChannelType¶
The channel's Discord type.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- permissions_for(obj=None, /)[ソース]¶
Handles permission resolution for a
User.This function is there for compatibility with other channel types.
Actual direct messages do not really have the concept of permissions.
This returns all the Text related permissions set to
Trueexcept:send_tts_messages: You cannot send TTS messages in a DM.manage_messages: You cannot delete others messages in a DM.
- パラメータ:
obj (
Any) -- The user to check permissions for. This parameter is ignored but kept for compatibility with otherpermissions_formethods.- 戻り値:
The resolved permissions.
- 戻り値の型:
- get_partial_message(message_id, /)[ソース]¶
Creates a
PartialMessagefrom the message ID.This is useful if you want to work with a message and only have its ID without doing an unnecessary API call.
Added in version 1.6.
- パラメータ:
message_id (
int) -- The message ID to create a partial message for.- 戻り値:
The partial message.
- 戻り値の型:
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
- defcan_send
- asyncfetch_message
- defhistory
- asyncleave
- defpermissions_for
- defpins
- asyncsend
- asynctrigger_typing
- deftyping
- class discord.GroupChannel(*, me, state, data)[ソース]¶
Represents a Discord group channel.
- x == y
Checks if two channels are equal.
- x != y
Checks if two channels are not equal.
- hash(x)
Returns the channel's hash.
- str(x)
Returns a string representation of the channel
- me¶
The user presenting yourself.
- Type:
- パラメータ:
me (
ClientUser)state (
ConnectionState)data (
GroupDMChannel)
- async for ... in history(*, limit=100, before=None, after=None, around=None, oldest_first=None)¶
Returns an
AsyncIteratorthat enables receiving the destination's message history.You must have
read_message_historypermissions to use this.- パラメータ:
limit (
int|None) -- The number of messages to retrieve. IfNone, retrieves every message in the channel. Note, however, that this would make it a slow operation.before (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
Snowflake|datetime|None) -- 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 (
bool|None) -- If set toTrue, return messages in oldest->newest order. Defaults toTrueifafteris specified, otherwiseFalse.
- 列挙:
Message-- The message with the message data parsed.- 例外:
Forbidden -- You do not have permissions to get channel message history.
HTTPException -- The request to get message history failed.
- 戻り値の型:
HistoryIterator
サンプル
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.
- async with typing()¶
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.
注釈
This is both a regular context manager and an async context manager. This means that both
withandasync withwork with this.Example Usage:
async with channel.typing(): # simulate something heavy await asyncio.sleep(10) await channel.send('done!')
- 戻り値の型:
Typing
- property type: ChannelType¶
The channel's Discord type.
- property jump_url: str¶
Returns a URL that allows the client to jump to the channel.
Added in version 2.0.
- permissions_for(obj, /)[ソース]¶
Handles permission resolution for a
User.This function is there for compatibility with other channel types.
Actual direct messages do not really have the concept of permissions.
This returns all the Text related permissions set to
Trueexcept:send_tts_messages: You cannot send TTS messages in a DM.manage_messages: You cannot delete others messages in a DM.
This also checks the kick_members permission if the user is the owner.
- パラメータ:
obj (
Snowflake) -- The user to check permissions for.- 戻り値:
The resolved permissions for the user.
- 戻り値の型:
- await leave()[ソース]¶
This function is a coroutine.
Leave the group.
If you are the only one in the group, this deletes it as well.
- 例外:
HTTPException -- Leaving the group failed.
- 戻り値の型:
- can_send(*objects)¶
Returns a
boolindicating whether you have the permissions to send the object(s).
- await fetch_message(id, /)¶
This function is a coroutine.
Retrieves a single
Messagefrom the destination.- パラメータ:
id (
int) -- The message ID to look for.- 戻り値:
The message asked 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.
- pins(*, limit=50, before=None)¶
Returns a
MessagePinIteratorthat enables receiving the destination's pinned messages.You must have
read_message_historypermissions to use this.警告
Starting from version 3.0, await channel.pins() will no longer return a list of
Message. See examples below for new usage instead.- パラメータ:
limit (
int|None) -- The number of pinned messages to retrieve. IfNone, retrieves every pinned message in the channel.before (
Snowflake|datetime|None) -- Retrieve messages pinned before this datetime. 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.
- 列挙:
MessagePin-- The pinned message.- 例外:
Forbidden -- You do not have permissions to get pinned messages.
HTTPException -- The request to get pinned messages failed.
- 戻り値の型:
MessagePinIterator
サンプル
Usage
counter = 0 async for pin in channel.pins(limit=250): if pin.message.author == client.user: counter += 1
Flattening into a list:
pins = await channel.pins(limit=None).flatten() # pins is now a list of MessagePin...
All parameters are optional.
- await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, enforce_nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None, poll=None, suppress=None, suppress_embeds=None, silent=None)¶
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). If the content is set toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.To upload a single embed, the
embedparameter should be used with a singleEmbedobject. To upload multiple embeds, theembedsparameter should be used with alistofEmbedobjects. Specifying both parameters will lead to an exception.- パラメータ:
content (Optional[
str]) -- The content of the message to send.tts (
bool) -- Indicates if the message should be sent using text-to-speech.embed (
Embed) -- The rich embed for the content.file (
File) -- The file to upload.files (List[
File]) -- A list of files to upload. Must be a maximum of 10.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.enforce_nonce (Optional[
bool]) --Whether
nonceis enforced to be validated.Added in version 2.5.
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
allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare used instead.Added in version 1.4.
reference (Union[
Message,MessageReference,PartialMessage]) --A reference to the
Messagebeing replied to or forwarded. This can be created usingto_reference(). When replying, you can control whether this mentions the author of the referenced message using thereplied_userattribute ofallowed_mentionsor by settingmention_author.Added in version 1.6.
mention_author (Optional[
bool]) --If set, overrides the
replied_userattribute ofallowed_mentions.Added in version 1.6.
view (
discord.ui.BaseView) -- A Discord UI View to add to the message.embeds (List[
Embed]) --A list of embeds to upload. Must be a maximum of 10.
Added in version 2.0.
stickers (Sequence[Union[
GuildSticker,StickerItem]]) --A list of stickers to upload. Must be a maximum of 3.
Added in version 2.0.
suppress (
bool) --Whether to suppress embeds for the message.
バージョン 2.8 で非推奨.
suppress_embeds (
bool) --Whether to suppress embeds for the message.
Added in version 2.8.
silent (
bool) --Whether to suppress push and desktop notifications for the message.
Added in version 2.4.
poll (
Poll) --The poll to send.
Added in version 2.6.
- 戻り値:
The message that was sent.
- 戻り値の型:
- 例外:
HTTPException -- Sending the message failed.
Forbidden -- You do not have the proper permissions to send the message.
InvalidArgument -- The
fileslist is not of the appropriate size, you specified bothfileandfiles, or you specified bothembedandembeds, or thereferenceobject is not aMessage,MessageReferenceorPartialMessage.
Stickers¶
- class discord.Sticker(*, state, data)[ソース]¶
Represents a sticker.
Added in version 1.6.
- str(x)
Returns the name of the sticker.
- x == y
Checks if the sticker is equal to another sticker.
- x != y
Checks if the sticker is not equal to another sticker.
- format¶
The format for the sticker's image.
- Type:
- パラメータ:
state (
ConnectionState)data (
BaseSticker|StandardSticker|GuildSticker)
- class discord.StickerPack(*, state, data)[ソース]¶
Represents a sticker pack.
Added in version 2.0.
- str(x)
Returns the name of the sticker pack.
- x == y
Checks if the sticker pack is equal to another sticker pack.
- x != y
Checks if the sticker pack is not equal to another sticker pack.
- stickers¶
The stickers of this sticker pack.
- Type:
List[
StandardSticker]
- cover_sticker¶
The sticker used for the cover of the sticker pack.
- Type:
- パラメータ:
state (
ConnectionState)data (
StickerPack)
- class discord.StickerItem(*, state, data)[ソース]¶
Represents a sticker item.
Added in version 2.0.
- str(x)
Returns the name of the sticker item.
- x == y
Checks if the sticker item is equal to another sticker item.
- x != y
Checks if the sticker item is not equal to another sticker item.
- format¶
The format for the sticker's image.
- Type:
- パラメータ:
state (
ConnectionState)data (
StickerItem)
- await fetch()[ソース]¶
This function is a coroutine.
Attempts to retrieve the full sticker data of the sticker item.
- 戻り値:
The retrieved sticker.
- 戻り値の型:
- 例外:
HTTPException -- Retrieving the sticker failed.
- asyncpack
- class discord.StandardSticker(*, state, data)[ソース]¶
Represents a sticker that is found in a standard sticker pack.
Added in version 2.0.
- str(x)
Returns the name of the sticker.
- x == y
Checks if the sticker is equal to another sticker.
- x != y
Checks if the sticker is not equal to another sticker.
- format¶
The format for the sticker's image.
- Type:
- パラメータ:
state (
ConnectionState)data (
BaseSticker|StandardSticker|GuildSticker)
- await pack()[ソース]¶
This function is a coroutine.
Retrieves the sticker pack that this sticker belongs to.
- 戻り値:
The retrieved sticker pack.
- 戻り値の型:
- 例外:
InvalidData -- The corresponding sticker pack was not found.
HTTPException -- Retrieving the sticker pack failed.
- class discord.GuildSticker(*, state, data)[ソース]¶
Represents a sticker that belongs to a guild.
Added in version 2.0.
- str(x)
Returns the name of the sticker.
- x == y
Checks if the sticker is equal to another sticker.
- x != y
Checks if the sticker is not equal to another sticker.
- format¶
The format for the sticker's image.
- Type:
- user¶
The user that created this sticker. This can only be retrieved using
Guild.fetch_sticker()and having themanage_emojis_and_stickerspermission.- Type:
Optional[
User]
- パラメータ:
state (
ConnectionState)data (
BaseSticker|StandardSticker|GuildSticker)
- guild¶
The guild that this sticker is from. Could be
Noneif the bot is not in the guild.Added in version 2.0.
- await edit(*, name=..., description=..., emoji=..., reason=None)[ソース]¶
This function is a coroutine.
Edits a
GuildStickerfor the guild.- パラメータ:
name (
str) -- The sticker's new name. Must be at least 2 characters.description (
str) -- The sticker's new description. Can beNone.emoji (
str) -- The name of a unicode emoji that represents the sticker's expression.reason (
str|None) -- The reason for editing this sticker. Shows up on the audit log.
- 戻り値:
The newly modified sticker.
- 戻り値の型:
- 例外:
Forbidden -- You are not allowed to edit stickers.
HTTPException -- An error occurred editing the sticker.
- await delete(*, reason=None)[ソース]¶
This function is a coroutine.
Deletes the custom
Stickerfrom the guild.You must have
manage_emojis_and_stickerspermission to do this.- パラメータ:
reason (
str|None) -- The reason for deleting this sticker. Shows up on the audit log.- 例外:
Forbidden -- You are not allowed to delete stickers.
HTTPException -- An error occurred deleting the sticker.
- 戻り値の型:
Soundboard¶
- class discord.PartialSoundboardSound(data, state, http)[ソース]¶
A partial soundboard sound.
Added in version 2.7.
- emoji¶
The sound's emoji. Could be
Noneif the sound has no emoji.- Type:
PartialEmoji|None
- パラメータ:
data (
SoundboardSound|VoiceChannelEffectSendEvent)state (
ConnectionState)http (
HTTPClient)
- class discord.SoundboardSound(*, state, http, data)[ソース]¶
Represents a soundboard sound.
Added in version 2.7.
- emoji¶
The sound's emoji. Could be
Noneif the sound has no emoji.- Type:
PartialEmoji|None
- available¶
Whether the sound is available. Could be
Falseif the sound is not available. This is the case, for example, when the guild loses the boost level required to use the sound.- Type:
- guild_id¶
The ID of the guild to which the sound belongs. Could be
Noneif the sound is a default sound.- Type:
int|None
- パラメータ:
state (
ConnectionState)http (
HTTPClient)data (
SoundboardSound)
- edit(*, name=None, volume=None, emoji=None, reason=None)[ソース]¶
Edits the sound.
Added in version 2.7.
- パラメータ:
- 戻り値:
The edited sound.
- 戻り値の型:
- 例外:
ValueError -- Editing a default sound is not allowed.
Events¶
- class discord.AutoModActionExecutionEvent(state, data)[ソース]¶
Represents the payload for an
on_auto_moderation_action_execution()Added in version 2.0.
- action¶
The action that was executed.
- Type:
- rule_trigger_type¶
The category of trigger the rule belongs to.
Added in version 2.4.
- Type:
- channel¶
The channel in which the member's content was posted, if cached.
- Type:
Optional[Union[
TextChannel,Thread,VoiceChannel,StageChannel]]
- message_id¶
The ID of the message that triggered the action. This is only available if the message was not blocked.
- Type:
Optional[
int]
- alert_system_message_id¶
The ID of the system auto moderation message that was posted as a result of the action.
- Type:
Optional[
int]
- alert_system_message¶
The system auto moderation message that was posted as a result of the action, if cached.
- Type:
Optional[
Message]
- パラメータ:
state (
ConnectionState)data (
AutoModActionExecutionEvent)
- class discord.RawTypingEvent(data)[ソース]¶
Represents the payload for a
on_raw_typing()event.Added in version 2.0.
- when¶
When the typing started as an aware datetime in UTC.
- Type:
- member¶
The member who started typing. Only available if the member started typing in a guild.
- Type:
Optional[
Member]
- パラメータ:
data (
TypingEvent)
- class discord.RawMessageDeleteEvent(data)[ソース]¶
Represents the event payload for a
on_raw_message_delete()event.- パラメータ:
data (
MessageDeleteEvent)
- class discord.RawBulkMessageDeleteEvent(data)[ソース]¶
Represents the event payload for a
on_raw_bulk_message_delete()event.- パラメータ:
data (
BulkMessageDeleteEvent)
- class discord.RawMessageUpdateEvent(data, new_message)[ソース]¶
Represents the payload for a
on_raw_message_edit()event.- guild_id¶
The guild ID where the message got updated, if applicable.
Added in version 1.7.
- Type:
Optional[
int]
- cached_message¶
The cached message, if found in the internal message cache. Represents the message before it is modified by the data in
RawMessageUpdateEvent.data.- Type:
Optional[
Message]
- new_message¶
The new message object. Represents the message after it is modified by the data in
RawMessageUpdateEvent.data.Added in version 2.7.
- Type:
- パラメータ:
data (
MessageUpdateEvent)new_message (
Message)
- class discord.RawReactionActionEvent(data, emoji, event_type)[ソース]¶
Represents the payload for a
on_raw_reaction_add()oron_raw_reaction_remove()event.- emoji¶
The custom or unicode emoji being used.
- Type:
- member¶
The member who added the reaction. Only available if the reaction occurs within a guild.
Added in version 1.3.
- Type:
Optional[
Member]
- event_type¶
The event type that triggered this action. Can be
REACTION_ADDfor reaction addition orREACTION_REMOVEfor reaction removal.Added in version 1.3.
- Type:
- burst_colours¶
A list of hex codes this reaction can be. Only available if event_type is REACTION_ADD and this emoji has super reactions available.
- Type:
Optional[
list]
- burst_colors¶
Alias for
burst_colours.- Type:
Optional[
list]
- type¶
The type of reaction added.
- Type:
- パラメータ:
data (
ReactionActionEvent)emoji (
PartialEmoji)event_type (
str)
- class discord.RawReactionClearEvent(data)[ソース]¶
Represents the payload for a
on_raw_reaction_clear()event.- パラメータ:
data (
ReactionClearEvent)
- class discord.RawReactionClearEmojiEvent(data, emoji)[ソース]¶
Represents the payload for a
on_raw_reaction_clear_emoji()event.Added in version 1.3.
- emoji¶
The custom or unicode emoji being removed.
- Type:
- burst_colors¶
Alias for
burst_colours.- Type:
Optional[
list]
- type¶
The type of reaction removed.
- Type:
- パラメータ:
data (
ReactionClearEmojiEvent)emoji (
PartialEmoji)
- class discord.RawIntegrationDeleteEvent(data)[ソース]¶
Represents the payload for a
on_raw_integration_delete()event.Added in version 2.0.
- application_id¶
The ID of the bot/OAuth2 application for this deleted integration.
- Type:
Optional[
int]
- パラメータ:
data (
IntegrationDeleteEvent)
- class discord.RawThreadDeleteEvent(data)[ソース]¶
Represents the payload for
on_raw_thread_delete()event.Added in version 2.0.
- thread_type¶
The channel type of the deleted thread.
- Type:
- thread¶
The thread that was deleted. This may be
Noneif deleted thread is not found in internal cache.- Type:
Optional[
discord.Thread]
- パラメータ:
data (
ThreadDeleteEvent)
- class discord.RawScheduledEventSubscription(data, event_type)[ソース]¶
Represents the payload for a
raw_scheduled_event_user_add()orraw_scheduled_event_user_remove()event.Added in version 2.0.
- パラメータ:
data (
ScheduledEventSubscription)event_type (
str)
- class discord.RawMemberRemoveEvent(data, user)[ソース]¶
Represents the payload for an
on_raw_member_remove()event.Added in version 2.4.
- user¶
The user that left the guild.
- Type:
- パラメータ:
data (
MemberRemoveEvent)user (
User)
- class discord.RawThreadUpdateEvent(data)[ソース]¶
Represents the payload for an
on_raw_thread_update()event.Added in version 2.4.
- thread_type¶
The channel type of the updated thread.
- Type:
- thread¶
The thread, if it could be found in the internal cache.
- Type:
discord.Thread| None
- パラメータ:
data (
Thread)
- class discord.RawThreadMembersUpdateEvent(data)[ソース]¶
Represents the payload for an
on_raw_thread_member_remove()event.Added in version 2.4.
- パラメータ:
data (
ThreadMembersUpdateEvent)
- class discord.RawAuditLogEntryEvent(data)[ソース]¶
Represents the payload for an
on_raw_audit_log_entry()event.Added in version 2.5.
- action_type¶
The action that was done.
- Type:
- extra¶
Extra information that this entry has that might be useful. For most actions, this is
None. However, in some cases it contains extra information. SeeAuditLogActionfor which actions have this field filled out.- Type:
Any
- パラメータ:
data (
AuditLogEntryEvent)
- class discord.RawVoiceChannelStatusUpdateEvent(data)[ソース]¶
Represents the payload for an
on_raw_voice_channel_status_update()event.Added in version 2.5.
- パラメータ:
data (
VoiceChannelStatusUpdateEvent)
- class discord.VoiceChannelEffectSendEvent(data, state, sound=None)[ソース]¶
Represents the payload for an
on_voice_channel_effect_send().Added in version 2.7.
- sound¶
The sound that is being sent, could be
Noneif the effect is not a sound effect.- Type:
Optional[
SoundboardSound]
- channel¶
The voice channel in which the sound is being sent.
- Type:
- パラメータ:
data (
VoiceChannelEffectSendEvent)state (
ConnectionState)sound (
SoundboardSound|PartialSoundboardSound|None)
Webhooks¶
Collectibles¶
- class discord.Collectibles(data, state)[ソース]¶
Represents a user or member's equipped collectibles.
Added in version 2.8.
- x == y
Checks if two sets of collectibles are equal.
- x != y
Checks if two sets of collectibles are not equal.
- パラメータ:
data (
Collectibles)state (
ConnectionState)