Event Reference

This section outlines the different types of events in Pycord. Events are class-based objects that inherit from Event and are dispatched by the Discord gateway when certain actions occur.

See also

For information about the Gears system and modular event handling, see Gears.

Listening to Events

There are two main ways to listen to events in Pycord:

  1. Using Client.listen() decorator - This allows you to register typed event listeners directly on the client.

  2. Using Gears - A modular event handling system that allows you to organize event listeners into reusable components.

Using the listen() Decorator

The modern way to register event listeners is by using the listen() decorator with typed event classes:

import discord
from discord.events import MessageCreate, Ready

client = discord.Client(intents=discord.Intents.default())

@client.listen()
async def on_message(event: MessageCreate) -> None:
    if event.author == client.user:
        return
    if event.content.startswith('$hello'):
        await event.channel.send('Hello World!')

@client.listen(once=True)
async def on_ready(event: Ready) -> None:
    print("Client is ready!")

client.run("TOKEN")

Note that:

  • Event listeners use type annotations to specify which event they handle

  • Event objects may inherit from domain models (e.g., MessageCreate inherits from Message)

  • The once=True parameter creates a one-time listener that is automatically removed after being called once

  • All event listeners must be coroutines (async def functions)

Using Gears

For more organized code, especially in larger bots, you can use the Gears system:

from discord.gears import Gear
from discord.events import Ready, MessageCreate

class MyGear(Gear):
    @Gear.listen()
    async def on_ready(self, event: Ready) -> None:
        print("Bot is ready!")

    @Gear.listen()
    async def on_message(self, event: MessageCreate) -> None:
        print(f"Message: {event.content}")

bot = discord.Bot()
bot.attach_gear(MyGear())
bot.run("TOKEN")

See Gears for more information on using Gears.

Warning

All event listeners must be coroutine. If they aren’t, then you might get unexpected errors. In order to turn a function into a coroutine they must be async def functions.

Event Classes

All events inherit from the base Event class. Events are typed objects that contain data related to the specific Discord gateway event that occurred.

Some event classes inherit from domain models, meaning they have all the attributes and methods of that model. For example:

Events that don’t inherit from a domain model will have specific attributes for accessing event data.

Many events also include a raw attribute that contains the raw event payload data from Discord, which can be useful for accessing data that may not be in the cache.

Available Events

Below is a comprehensive list of all events available in Pycord, organized by category.

Audit Logs

class discord.events.GuildAuditLogEntryCreate[source]

Called when an audit log entry is created.

The bot must have view_audit_log to receive this, and Intents.moderation must be enabled.

This event inherits from AuditLogEntry.

raw

The raw event payload data.

Type:

RawAuditLogEntryEvent

property after: AuditLogDiff

The target’s subsequent state.

property before: AuditLogDiff

The target’s prior state.

property category: AuditLogActionCategory

The category of the action, if applicable.

await changes()

The list of changes this entry has.

Return type:

AuditLogChanges

property created_at: datetime

Returns the entry’s creation time in UTC.

AutoMod

class discord.events.AutoModRuleCreate[source]

Called when an auto moderation rule is created.

The bot must have manage_guild to receive this, and Intents.auto_moderation_configuration must be enabled.

rule

The newly created rule.

Type:

AutoModRule

class discord.events.AutoModRuleUpdate[source]

Called when an auto moderation rule is updated.

The bot must have manage_guild to receive this, and Intents.auto_moderation_configuration must be enabled.

rule

The updated rule.

Type:

AutoModRule

class discord.events.AutoModRuleDelete[source]

Called when an auto moderation rule is deleted.

The bot must have manage_guild to receive this, and Intents.auto_moderation_configuration must be enabled.

rule

The deleted rule.

Type:

AutoModRule

class discord.events.AutoModActionExecution[source]

Called when an auto moderation action is executed.

The bot must have manage_guild to receive this, and Intents.auto_moderation_execution must be enabled.

This event inherits from AutoModActionExecutionEvent.

Channels

class discord.events.ChannelCreate[source]

Called when a guild channel is created.

This requires Intents.guilds to be enabled.

This event inherits from the actual channel type that was created (e.g., TextChannel, VoiceChannel, ForumChannel, etc.). You can access all channel attributes directly on the event object.

Note

While this class shows GuildChannel in the signature, at runtime the event will be an instance of the specific channel type that was 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 roles attribute.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • 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)

This function is a coroutine.

Creates an instant invite from a text or voice channel.

You must have the create_instant_invite permission to do this.

Parameters:
  • max_age (int) – How long the invite should last in seconds. If it’s 0 then the invite doesn’t expire. Defaults to 0.

  • max_uses (int) – How many uses the invite could be used for. If it’s 0 then there are unlimited uses. Defaults to 0.

  • temporary (bool) – Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults to False.

  • unique (bool) – Indicates if a unique invite URL should be created. Defaults to True. If this is set to False then it will return a previously created invite.

  • reason (Optional[str]) – The reason for creating this invite. Shows up on the audit log.

  • target_type (Optional[InviteTarget]) –

    The type of target for the voice channel invite, if any.

    Added in version 2.0.

  • target_user (Optional[User]) –

    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 (Optional[int]) –

    The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.

    Added in version 2.0.

  • target_event (Optional[ScheduledEvent]) –

    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.

Returns:

The invite that was created.

Return type:

Invite

Raises:
  • HTTPException – Invite creation failed.

  • NotFound – The channel that was passed is a category or an invalid channel.

property created_at: datetime

The channel’s creation time in UTC.

await delete(*, reason=None)

This function is a coroutine.

Deletes the channel.

You must have manage_channels permission to use this.

Parameters:

reason (Optional[str]) – The reason for deleting this channel. Shows up on the audit log.

Raises:
  • Forbidden – You do not have proper permissions to delete the channel.

  • NotFound – The channel was not found or was already deleted.

  • HTTPException – Deleting the channel failed.

Return type:

None

await get_overwrites()

Returns all of the channel’s overwrites.

This is returned as a dictionary where the key contains the target which can be either a Role or a Member and the value is the overwrite as a PermissionOverwrite.

Returns:

The channel’s permission overwrites.

Return type:

Dict[Union[Role, Member, Object], PermissionOverwrite]

await invites()

This function is a coroutine.

Returns a list of all active instant invites from this channel.

You must have manage_channels to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • 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 members: Collection[Member]

Returns all members that can view this channel.

This is calculated based on the channel’s permission overwrites and the members’ roles.

Returns:

All members who have permission to view this channel.

Return type:

Collection[Member]

property mention: str

The string that allows you to mention the channel.

overwrites_for(obj)

Returns the channel-specific overwrites for a member or a role.

Parameters:

obj (Union[Role, User]) – The role or user denoting whose overwrite to get.

Returns:

The permission overwrites for this object.

Return type:

PermissionOverwrite

await permissions_are_synced()

Whether the permissions for this channel are synced with the category it belongs to.

If there is no category then this is False. :rtype: bool

Added in version 3.0.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

This function takes into consideration the following cases:

  • Guild owner

  • Guild roles

  • Channel overrides

  • Member overrides

If a Role is 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

Changed in version 2.0: The object passed in can now be a role object.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

await set_permissions(target, *, overwrite=Undefined.MISSING, reason=None, **permissions)

This function is a coroutine.

Sets the channel specific permission overwrites for a target in the channel.

The target parameter should either be a Member or a Role that belongs to guild.

The overwrite parameter, if given, must either be None or PermissionOverwrite. For convenience, you can pass in keyword arguments denoting Permissions attributes. If this is done, then you cannot mix the keyword arguments with the overwrite parameter.

If the overwrite parameter is None, then the permission overwrites are deleted.

You must have the manage_roles permission to use this.

Note

This method replaces the old overwrites with the ones given.

Examples

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 PermissionOverwrite

overwrite = discord.PermissionOverwrite()
overwrite.send_messages = False
overwrite.read_messages = True
await channel.set_permissions(member, overwrite=overwrite)
Parameters:
  • target (Union[Member, Role]) – The member or role to overwrite permissions for.

  • overwrite (Optional[PermissionOverwrite]) – The permissions to allow and deny to the target, or None to delete the overwrite.

  • **permissions (bool) – 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.

Raises:
  • 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 Role or Member.

Return type:

None

property type: ChannelType

The channel’s Discord channel type.

class discord.events.ChannelDelete[source]

Called when a guild channel is deleted.

This requires Intents.guilds to be enabled.

This event inherits from the actual channel type that was deleted (e.g., TextChannel, VoiceChannel, ForumChannel, etc.). You can access all channel attributes directly on the event object.

Note

While this class shows GuildChannel in the signature, at runtime the event will be an instance of the specific channel type that was deleted.

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 roles attribute.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • 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)

This function is a coroutine.

Creates an instant invite from a text or voice channel.

You must have the create_instant_invite permission to do this.

Parameters:
  • max_age (int) – How long the invite should last in seconds. If it’s 0 then the invite doesn’t expire. Defaults to 0.

  • max_uses (int) – How many uses the invite could be used for. If it’s 0 then there are unlimited uses. Defaults to 0.

  • temporary (bool) – Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults to False.

  • unique (bool) – Indicates if a unique invite URL should be created. Defaults to True. If this is set to False then it will return a previously created invite.

  • reason (Optional[str]) – The reason for creating this invite. Shows up on the audit log.

  • target_type (Optional[InviteTarget]) –

    The type of target for the voice channel invite, if any.

    Added in version 2.0.

  • target_user (Optional[User]) –

    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 (Optional[int]) –

    The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.

    Added in version 2.0.

  • target_event (Optional[ScheduledEvent]) –

    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.

Returns:

The invite that was created.

Return type:

Invite

Raises:
  • HTTPException – Invite creation failed.

  • NotFound – The channel that was passed is a category or an invalid channel.

property created_at: datetime

The channel’s creation time in UTC.

await delete(*, reason=None)

This function is a coroutine.

Deletes the channel.

You must have manage_channels permission to use this.

Parameters:

reason (Optional[str]) – The reason for deleting this channel. Shows up on the audit log.

Raises:
  • Forbidden – You do not have proper permissions to delete the channel.

  • NotFound – The channel was not found or was already deleted.

  • HTTPException – Deleting the channel failed.

Return type:

None

await get_overwrites()

Returns all of the channel’s overwrites.

This is returned as a dictionary where the key contains the target which can be either a Role or a Member and the value is the overwrite as a PermissionOverwrite.

Returns:

The channel’s permission overwrites.

Return type:

Dict[Union[Role, Member, Object], PermissionOverwrite]

await invites()

This function is a coroutine.

Returns a list of all active instant invites from this channel.

You must have manage_channels to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • 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 members: Collection[Member]

Returns all members that can view this channel.

This is calculated based on the channel’s permission overwrites and the members’ roles.

Returns:

All members who have permission to view this channel.

Return type:

Collection[Member]

property mention: str

The string that allows you to mention the channel.

overwrites_for(obj)

Returns the channel-specific overwrites for a member or a role.

Parameters:

obj (Union[Role, User]) – The role or user denoting whose overwrite to get.

Returns:

The permission overwrites for this object.

Return type:

PermissionOverwrite

await permissions_are_synced()

Whether the permissions for this channel are synced with the category it belongs to.

If there is no category then this is False. :rtype: bool

Added in version 3.0.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

This function takes into consideration the following cases:

  • Guild owner

  • Guild roles

  • Channel overrides

  • Member overrides

If a Role is 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

Changed in version 2.0: The object passed in can now be a role object.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

await set_permissions(target, *, overwrite=Undefined.MISSING, reason=None, **permissions)

This function is a coroutine.

Sets the channel specific permission overwrites for a target in the channel.

The target parameter should either be a Member or a Role that belongs to guild.

The overwrite parameter, if given, must either be None or PermissionOverwrite. For convenience, you can pass in keyword arguments denoting Permissions attributes. If this is done, then you cannot mix the keyword arguments with the overwrite parameter.

If the overwrite parameter is None, then the permission overwrites are deleted.

You must have the manage_roles permission to use this.

Note

This method replaces the old overwrites with the ones given.

Examples

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 PermissionOverwrite

overwrite = discord.PermissionOverwrite()
overwrite.send_messages = False
overwrite.read_messages = True
await channel.set_permissions(member, overwrite=overwrite)
Parameters:
  • target (Union[Member, Role]) – The member or role to overwrite permissions for.

  • overwrite (Optional[PermissionOverwrite]) – The permissions to allow and deny to the target, or None to delete the overwrite.

  • **permissions (bool) – 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.

Raises:
  • 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 Role or Member.

Return type:

None

property type: ChannelType

The channel’s Discord channel type.

class discord.events.ChannelUpdate[source]

Internal event that dispatches to either PrivateChannelUpdate or GuildChannelUpdate.

This event is not directly received by user code. It automatically routes to the appropriate specific channel update event based on the channel type.

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 roles attribute.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • 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)

This function is a coroutine.

Creates an instant invite from a text or voice channel.

You must have the create_instant_invite permission to do this.

Parameters:
  • max_age (int) – How long the invite should last in seconds. If it’s 0 then the invite doesn’t expire. Defaults to 0.

  • max_uses (int) – How many uses the invite could be used for. If it’s 0 then there are unlimited uses. Defaults to 0.

  • temporary (bool) – Denotes that the invite grants temporary membership (i.e. they get kicked after they disconnect). Defaults to False.

  • unique (bool) – Indicates if a unique invite URL should be created. Defaults to True. If this is set to False then it will return a previously created invite.

  • reason (Optional[str]) – The reason for creating this invite. Shows up on the audit log.

  • target_type (Optional[InviteTarget]) –

    The type of target for the voice channel invite, if any.

    Added in version 2.0.

  • target_user (Optional[User]) –

    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 (Optional[int]) –

    The id of the embedded application for the invite, required if target_type is TargetType.embedded_application.

    Added in version 2.0.

  • target_event (Optional[ScheduledEvent]) –

    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.

Returns:

The invite that was created.

Return type:

Invite

Raises:
  • HTTPException – Invite creation failed.

  • NotFound – The channel that was passed is a category or an invalid channel.

property created_at: datetime

The channel’s creation time in UTC.

await delete(*, reason=None)

This function is a coroutine.

Deletes the channel.

You must have manage_channels permission to use this.

Parameters:

reason (Optional[str]) – The reason for deleting this channel. Shows up on the audit log.

Raises:
  • Forbidden – You do not have proper permissions to delete the channel.

  • NotFound – The channel was not found or was already deleted.

  • HTTPException – Deleting the channel failed.

Return type:

None

await get_overwrites()

Returns all of the channel’s overwrites.

This is returned as a dictionary where the key contains the target which can be either a Role or a Member and the value is the overwrite as a PermissionOverwrite.

Returns:

The channel’s permission overwrites.

Return type:

Dict[Union[Role, Member, Object], PermissionOverwrite]

await invites()

This function is a coroutine.

Returns a list of all active instant invites from this channel.

You must have manage_channels to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • 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 members: Collection[Member]

Returns all members that can view this channel.

This is calculated based on the channel’s permission overwrites and the members’ roles.

Returns:

All members who have permission to view this channel.

Return type:

Collection[Member]

property mention: str

The string that allows you to mention the channel.

overwrites_for(obj)

Returns the channel-specific overwrites for a member or a role.

Parameters:

obj (Union[Role, User]) – The role or user denoting whose overwrite to get.

Returns:

The permission overwrites for this object.

Return type:

PermissionOverwrite

await permissions_are_synced()

Whether the permissions for this channel are synced with the category it belongs to.

If there is no category then this is False. :rtype: bool

Added in version 3.0.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

This function takes into consideration the following cases:

  • Guild owner

  • Guild roles

  • Channel overrides

  • Member overrides

If a Role is 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

Changed in version 2.0: The object passed in can now be a role object.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

await set_permissions(target, *, overwrite=Undefined.MISSING, reason=None, **permissions)

This function is a coroutine.

Sets the channel specific permission overwrites for a target in the channel.

The target parameter should either be a Member or a Role that belongs to guild.

The overwrite parameter, if given, must either be None or PermissionOverwrite. For convenience, you can pass in keyword arguments denoting Permissions attributes. If this is done, then you cannot mix the keyword arguments with the overwrite parameter.

If the overwrite parameter is None, then the permission overwrites are deleted.

You must have the manage_roles permission to use this.

Note

This method replaces the old overwrites with the ones given.

Examples

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 PermissionOverwrite

overwrite = discord.PermissionOverwrite()
overwrite.send_messages = False
overwrite.read_messages = True
await channel.set_permissions(member, overwrite=overwrite)
Parameters:
  • target (Union[Member, Role]) – The member or role to overwrite permissions for.

  • overwrite (Optional[PermissionOverwrite]) – The permissions to allow and deny to the target, or None to delete the overwrite.

  • **permissions (bool) – 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.

Raises:
  • 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 Role or Member.

Return type:

None

property type: ChannelType

The channel’s Discord channel type.

class discord.events.GuildChannelUpdate[source]

Called whenever a guild channel is updated (e.g., changed name, topic, permissions).

This requires Intents.guilds to be enabled.

This event inherits from the actual channel type that was updated (e.g., TextChannel, VoiceChannel, ForumChannel, etc.).

Note

While this class shows GuildChannel in the signature, at runtime the event will be an instance of the specific channel type that was updated.

old

The channel’s old info before the update, or None if not in cache. This will be the same type as the event itself.

Type:

TextChannel | VoiceChannel | CategoryChannel | StageChannel | ForumChannel | None

class discord.events.PrivateChannelUpdate[source]

Called whenever a private group DM is updated (e.g., changed name or topic).

This requires Intents.messages to be enabled.

This event inherits from GroupChannel.

old

The channel’s old info before the update, or None if not in cache.

Type:

GroupChannel | None

class discord.events.ChannelPinsUpdate[source]

Called whenever a message is pinned or unpinned from a channel.

channel

The channel that had its pins updated. Can be any messageable channel type.

Type:

abc.PrivateChannel | TextChannel | VoiceChannel | StageChannel | ForumChannel | Thread

last_pin

The latest message that was pinned as an aware datetime in UTC, or None if no pins exist.

Type:

datetime.datetime | None

Connection & Gateway

class discord.events.Ready[source]

Called when the client is done preparing the data received from Discord.

Usually after login is successful and the client’s guilds and cache are filled up.

Warning

This event is not guaranteed to be the first event called. Likewise, this event is not guaranteed to only be called once. This library implements reconnection logic and thus will end up calling this event whenever a RESUME request fails.

user

An instance representing the connected application user.

Type:

ClientUser

application_id

A snowflake of the application’s ID.

Type:

int

application_flags

An instance representing the application flags.

Type:

ApplicationFlags

guilds

A list of guilds received in this event. Note it may have incomplete data as GUILD_CREATE fills up other parts of guild data.

Type:

list[Guild]

class discord.events.Resumed[source]

Called when the client has resumed a session.

Entitlements & Monetization

class discord.events.EntitlementCreate[source]

Called when a user subscribes to an SKU.

This event inherits from Entitlement.

await consume()

This function is a coroutine.

Consumes this entitlement.

This can only be done on entitlements from an SKU of type SKUType.consumable.

Raises:

HTTPException – Consuming the entitlement failed.

Return type:

None

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() or User.create_test_entitlement().

Raises:

HTTPException – Deleting the entitlement failed.

Return type:

None

class discord.events.EntitlementUpdate[source]

Called when a user’s subscription to an Entitlement is cancelled.

Note

Before October 1, 2024, this event was called when a user’s subscription was renewed.

Entitlements that no longer follow this behavior will have a type of EntitlementType.purchase. Those that follow the old behavior will have a type of EntitlementType.application_subscription.

This event inherits from Entitlement.

await consume()

This function is a coroutine.

Consumes this entitlement.

This can only be done on entitlements from an SKU of type SKUType.consumable.

Raises:

HTTPException – Consuming the entitlement failed.

Return type:

None

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() or User.create_test_entitlement().

Raises:

HTTPException – Deleting the entitlement failed.

Return type:

None

class discord.events.EntitlementDelete[source]

Called when a user’s entitlement is deleted.

Entitlements are usually only deleted when Discord issues a refund for a subscription, or manually removes an entitlement from a user.

Note

This is not called when a user’s subscription is cancelled.

This event inherits from Entitlement.

await consume()

This function is a coroutine.

Consumes this entitlement.

This can only be done on entitlements from an SKU of type SKUType.consumable.

Raises:

HTTPException – Consuming the entitlement failed.

Return type:

None

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() or User.create_test_entitlement().

Raises:

HTTPException – Deleting the entitlement failed.

Return type:

None

class discord.events.SubscriptionCreate[source]

Called when a subscription is created for the application.

This event inherits from Subscription.

await get_user()

Optional[User]: The user that owns this subscription.

class discord.events.SubscriptionUpdate[source]

Called when a subscription has been updated.

This could be a renewal, cancellation, or other payment related update.

This event inherits from Subscription.

await get_user()

Optional[User]: The user that owns this subscription.

class discord.events.SubscriptionDelete[source]

Called when a subscription has been deleted.

This event inherits from Subscription.

await get_user()

Optional[User]: The user that owns this subscription.

Guilds

class discord.events.GuildJoin[source]

Called when the client joins a new guild or when a guild is created.

This requires Intents.guilds to be enabled.

This event inherits from Guild.

await active_threads()

This function is a coroutine.

Returns a list of active Thread that the client can access.

This includes both private and public threads.

Added in version 2.0.

Returns:

The active threads

Return type:

List[Thread]

Raises:

HTTPException – The request to get the active threads failed.

await audit_logs(*, limit=100, before=None, after=None, user=None, action=None)

Returns an AsyncIterator that enables receiving the guild’s audit logs.

You must have the view_audit_log permission to use this.

See API documentation for more information about the before and after parameters.

Parameters:
  • limit (Optional[int]) – The number of entries to retrieve. If None retrieve all entries.

  • before (Union[abc.Snowflake, datetime.datetime]) – 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 (Union[abc.Snowflake, datetime.datetime]) – 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 (abc.Snowflake) – The moderator to filter entries from.

  • action (AuditLogAction) – The action to filter with.

Yields:

AuditLogEntry – The audit log entry.

Raises:
  • Forbidden – You are not allowed to fetch audit logs

  • HTTPException – An error occurred while fetching the audit logs.

Return type:

AuditLogIterator

Examples

Getting the first 100 entries:

async for entry in guild.audit_logs(limit=100):
    print(f"{entry.user} did {entry.action} to {await entry.get_target()}")

Getting entries for a specific action:

async for entry in guild.audit_logs(action=discord.AuditLogAction.ban):
    print(f"{entry.user} banned {await entry.get_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 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.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to ban from their guild.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the user got banned.

Raises:
Return type:

None

property banner: Asset | None

Returns the guild’s banner asset, if available.

bans(limit=None, before=None, after=None)

This function is a coroutine.

Retrieves an AsyncIterator that enables receiving the guild’s bans. In order to use this, you must have the ban_members permission. Users will always be returned in ascending order sorted by user ID. If both the before and after parameters are provided, only before is respected.

Changed in version 2.5: The before. and after parameters were changed. They are now of the type abc.Snowflake instead of SnowflakeTime to comply with the discord api.

Changed in version 2.0: The limit, before. and after parameters were added. Now returns a BanIterator instead of a list of BanEntry objects.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of bans to retrieve. Defaults to 1000.

  • before (Optional[abc.Snowflake]) – Retrieve bans before the given user.

  • after (Optional[abc.Snowflake]) – Retrieve bans after the given user.

Yields:

BanEntry – The ban entry for the ban.

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

Return type:

BanIterator

Examples

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...
property bitrate_limit: int

The maximum bitrate for voice channels this guild can have.

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.Snowflake abc.

You must have the ban_members permission 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)
Parameters:
  • *users (abc.Snowflake) – An argument list of users to ban from the guild, up to 200.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the users were banned.

Returns:

Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.

Return type:

Tuple[List[abc.Snowflake], List[abc.Snowflake]]

Raises:
by_category()

Returns every CategoryChannel and 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.

Returns:

The categories and their associated channels.

Return type:

List[Tuple[Optional[CategoryChannel], List[abc.GuildChannel]]]

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.

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.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – Channel the client wants to join. Use None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

property channels: list[GuildChannel]

A list of channels that belong to this guild.

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.

Parameters:

cache (bool) – Whether to cache the members as well.

Raises:

ClientException – The members intent is not enabled.

Return type:

None

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.

Parameters:
  • 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[abc.Snowflake]) – A list of roles that are exempt from the rule.

  • exempt_channels (List[abc.Snowflake]) – A list of channels that are exempt from the rule.

  • reason (Optional[str]) – The reason for creating the rule. Shows up in the audit log.

Returns:

The new auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Creating the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

await create_category(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_category_channel(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_custom_emoji(*, name, image, roles=Undefined.MISSING, reason=None)

This function is a coroutine.

Creates a custom GuildEmoji for the guild.

There is currently a limit of 50 static and animated emojis respectively per guild, unless the guild has the MORE_EMOJI feature which extends the limit to 200.

You must have the manage_emojis permission to do this.

Parameters:
  • 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]) – A list of Roles that can use this emoji. Leave empty to make it available to everyone.

  • reason (Optional[str]) – The reason for creating this emoji. Shows up on the audit log.

Raises:
Returns:

The created emoji.

Return type:

GuildEmoji

await create_forum_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_reaction_emoji=Undefined.MISSING, available_tags=Undefined.MISSING, default_sort_order=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a ForumChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_reaction_emoji (Optional[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 (Optional[SortOrder]) –

    The default sort order type used to order posts in this channel.

    Added in version 2.7.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

ForumChannel

Raises:

Examples

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_integration(*, type, id)

This function is a coroutine.

Attaches an integration to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Parameters:
  • type (str) – The integration type (e.g. Twitch).

  • id (int) – The integration ID.

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – The account could not be found.

Return type:

None

await create_role(*, name=Undefined.MISSING, permissions=Undefined.MISSING, color=Undefined.MISSING, colour=Undefined.MISSING, colors=Undefined.MISSING, colours=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, reason=None, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Creates a Role for the guild.

All fields are optional.

You must have the manage_roles permission to do this.

Changed in version 1.6: Can now pass int to colour keyword-only parameter.

Parameters:
  • name (str) – The role name. Defaults to ‘new role’.

  • permissions (Permissions) – The permissions to have. Defaults to no permissions.

  • colour (Union[Colour, int]) – The colour for the role. Defaults to Colour.default(). This is aliased to color as well.

  • hoist (bool) – Indicates if the role should be shown separately in the member list. Defaults to False.

  • mentionable (bool) – Indicates if the role should be mentionable by others. Defaults to False.

  • reason (Optional[str]) – The reason for creating this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • color (Colour | int | utils.Undefined)

  • colors (RoleColours | utils.Undefined)

  • colours (RoleColours | utils.Undefined)

  • holographic (bool | utils.Undefined)

Returns:

The newly created role.

Return type:

Role

Raises:
await create_scheduled_event(*, name, description=Undefined.MISSING, start_time, end_time=Undefined.MISSING, location, privacy_level=ScheduledEventPrivacyLevel.guild_only, reason=None, image=Undefined.MISSING)

This function is a coroutine. Creates a scheduled event.

Parameters:
  • name (str) – The name of the scheduled event.

  • description (Optional[str]) – The description of the scheduled event.

  • start_time (datetime.datetime) – A datetime object of when the scheduled event is supposed to start.

  • end_time (Optional[datetime.datetime]) – A datetime object of when the scheduled event is supposed to end.

  • location (ScheduledEventLocation) – The location of where the event is happening.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event

Returns:

The created scheduled event.

Return type:

Optional[ScheduledEvent]

Raises:
await create_sound(name, sound, volume=1.0, emoji=None, reason=None)

This function is a coroutine. Creates a SoundboardSound in the guild. You must have Permissions.manage_expressions permission to use this.

Added in version 2.7.

Parameters:
  • 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 (Optional[Union[PartialEmoji, GuildEmoji, str]]) – The emoji of the sound.

  • reason (Optional[str]) – The reason for creating this sound. Shows up on the audit log.

Returns:

The created sound.

Return type:

SoundboardSound

Raises:
await create_stage_channel(name, *, topic, position=Undefined.MISSING, overwrites=Undefined.MISSING, category=None, reason=None, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a StageChannel instead.

Added in version 1.7.

Parameters:
  • name (str) – The channel’s name.

  • topic (str) – The new channel’s topic.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

StageChannel

Raises:
  • 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_sticker(*, name, description=None, emoji, file, reason=None)

This function is a coroutine.

Creates a Sticker for the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • name (str) – The sticker name. Must be 2 to 30 characters.

  • description (Optional[str]) – 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) – The reason for creating this sticker. Shows up on the audit log.

Returns:

The created sticker.

Return type:

GuildSticker

Raises:
  • 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 create_template(*, name, description=Undefined.MISSING)

This function is a coroutine.

Creates a template for the guild.

You must have the manage_guild permission to do this.

Added in version 1.7.

Parameters:
  • name (str) – The name of the template.

  • description (str) – The description of the template.

Return type:

Template

await create_test_entitlement(sku)

This function is a coroutine.

Creates a test entitlement for the guild.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

await create_text_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a TextChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

TextChannel

Raises:
  • 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.

Examples

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=Undefined.MISSING, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, overwrites=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a VoiceChannel instead.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 (Optional[str]) – 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

VoiceChannel

Raises:
  • 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.

property created_at: datetime

Returns the guild’s creation time in UTC.

property default_role: Role

Gets the @everyone role that all members have by default.

await delete()

This function is a coroutine.

Deletes the guild. You must be the guild owner to delete the guild.

Raises:
Return type:

None

await delete_auto_moderation_rule(id, *, reason=None)

Deletes an auto moderation rule.

Parameters:
  • id (int) – The ID of the auto moderation rule.

  • reason (Optional[str]) – The reason for deleting the rule. Shows up in the audit log.

Raises:
  • HTTPException – Deleting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Return type:

None

await delete_emoji(emoji, *, reason=None)

This function is a coroutine.

Deletes the custom GuildEmoji from the guild.

You must have manage_emojis permission to do this.

Parameters:
  • emoji (abc.Snowflake) – The emoji you are deleting.

  • reason (Optional[str]) – The reason for deleting this emoji. Shows up on the audit log.

Raises:
Return type:

None

await delete_sticker(sticker, *, reason=None)

This function is a coroutine.

Deletes the custom Sticker from the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • sticker (abc.Snowflake) – The sticker you are deleting.

  • reason (Optional[str]) – The reason for deleting this sticker. Shows up on the audit log.

Raises:
  • Forbidden – You are not allowed to delete stickers.

  • HTTPException – An error occurred deleting the sticker.

Return type:

None

property discovery_splash: Asset | None

Returns the guild’s discovery splash asset, if available.

await edit(*, reason=Undefined.MISSING, name=Undefined.MISSING, description=Undefined.MISSING, icon=Undefined.MISSING, banner=Undefined.MISSING, splash=Undefined.MISSING, discovery_splash=Undefined.MISSING, community=Undefined.MISSING, afk_channel=Undefined.MISSING, owner=Undefined.MISSING, afk_timeout=Undefined.MISSING, default_notifications=Undefined.MISSING, verification_level=Undefined.MISSING, explicit_content_filter=Undefined.MISSING, system_channel=Undefined.MISSING, system_channel_flags=Undefined.MISSING, preferred_locale=Undefined.MISSING, rules_channel=Undefined.MISSING, public_updates_channel=Undefined.MISSING, premium_progress_bar_enabled=Undefined.MISSING, disable_invites=Undefined.MISSING, discoverable=Undefined.MISSING, disable_raid_alerts=Undefined.MISSING, enable_activity_feed=Undefined.MISSING)

This function is a coroutine.

Edits the guild.

You must have the manage_guild permission to edit the guild.

Changed in version 1.4: The rules_channel and public_updates_channel keyword-only parameters were added.

Changed in version 2.0: The discovery_splash and community keyword-only parameters were added.

Changed in version 2.0: The newly updated guild is returned.

Parameters:
  • name (str) – The new name of the guild.

  • description (Optional[str]) – The new description of the guild. Could be None for no description. This is only available to guilds that contain PUBLIC in Guild.features.

  • icon (bytes) – A bytes-like object representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that contain ANIMATED_ICON in Guild.features. Could be None to denote removal of the icon.

  • banner (bytes) – A bytes-like object representing the banner. Could be None to denote removal of the banner. This is only available to guilds that contain BANNER in Guild.features.

  • splash (bytes) – A bytes-like object representing the invite splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain INVITE_SPLASH in Guild.features.

  • discovery_splash (bytes) – A bytes-like object representing the discovery splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain DISCOVERABLE in Guild.features.

  • community (bool) – Whether the guild should be a Community guild. If set to True, both rules_channel and public_updates_channel parameters are required.

  • afk_channel (Optional[VoiceChannel]) – The new channel that is the AFK channel. Could be None for no AFK channel.

  • afk_timeout (int) – The number of seconds until someone is moved to the AFK channel.

  • owner (Member) – The new owner of the guild to transfer ownership to. Note that you must be owner of the guild to do this.

  • 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 (Optional[TextChannel]) – The new channel that is used for the system channel. Could be None for 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-US or ja or zh-CN.

  • rules_channel (Optional[TextChannel]) – The new channel that is used for rules. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for no rules channel.

  • public_updates_channel (Optional[TextChannel]) – The new channel that is used for public updates from Discord. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for 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 (class:bool) – Whether the guild’s user activity feed should be enabled.

  • reason (Optional[str]) – The reason for editing this guild. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to edit the guild.

  • HTTPException – Editing the guild failed.

  • InvalidArgument – The image format passed in to icon is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the guild and request an ownership transfer.

Returns:

The newly updated guild. Note that this has the same limitations as mentioned in Client.fetch_guild() and may not have full data.

Return type:

Guild

await edit_onboarding(*, prompts=Undefined.MISSING, default_channels=Undefined.MISSING, enabled=Undefined.MISSING, mode=Undefined.MISSING, reason=Undefined.MISSING)

This function is a coroutine.

A shorthand for Onboarding.edit without fetching the onboarding flow.

You must have the manage_guild and manage_roles permissions in the guild to do this.

Parameters:
  • prompts (Optional[List[OnboardingPrompt]]) – The new list of prompts for this flow.

  • default_channels (Optional[List[Snowflake]]) – The new default channels that users are opted into.

  • enabled (Optional[bool]) – Whether onboarding should be enabled. Setting this to True requires the guild to have COMMUNITY in features and at least 7 default_channels.

  • mode (Optional[OnboardingMode]) – The new onboarding mode.

  • reason (Optional[str]) – The reason that shows up on Audit log.

Returns:

The updated onboarding flow.

Return type:

Onboarding

Raises:
  • HTTPException – Editing the onboarding flow failed somehow.

  • Forbidden – You don’t have permissions to edit the onboarding flow.

await edit_role_positions(positions, *, reason=None)

This function is a coroutine.

Bulk edits a list of Role in the guild.

You must have the manage_roles permission 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)
Parameters:
  • positions (Dict[Role, int]) – A dict of Role to int to change the positions of each given role.

  • reason (Optional[str]) – The reason for editing the role positions. Shows up on the audit log.

Returns:

A list of all the roles in the guild.

Return type:

List[Role]

Raises:
await edit_welcome_screen(**options)

This function is a coroutine.

A shorthand for WelcomeScreen.edit without fetching the welcome screen.

You must have the manage_guild permission in the guild to do this.

The guild must have COMMUNITY in Guild.features

Parameters:
  • 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.

Returns:

The edited welcome screen.

Return type:

WelcomeScreen

Raises:
  • 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 edit_widget(*, enabled=Undefined.MISSING, channel=Undefined.MISSING)

This function is a coroutine.

Edits the widget of the guild.

You must have the manage_guild permission to use this

Added in version 2.0.

Parameters:
  • enabled (bool) – Whether to enable the widget for the guild.

  • channel (Optional[Snowflake]) – The new widget channel. None removes the widget channel.

Raises:
Return type:

None

property emoji_limit: int

The maximum number of emoji slots this guild has.

entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)

Returns an AsyncIterator that enables fetching the guild’s entitlements.

This is identical to Client.entitlements() with the guild parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

Return type:

EntitlementIterator

await estimate_pruned_members(*, days, roles=Undefined.MISSING)

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.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • roles (List[abc.Snowflake]) –

    A list of abc.Snowflake that 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.

Returns:

The number of members estimated to be pruned.

Return type:

int

Raises:
  • 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 fetch_auto_moderation_rule(id)

This function is a coroutine.

Retrieves a AutoModRule from rule ID.

Returns:

The requested auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Getting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Parameters:

id (int)

await fetch_auto_moderation_rules()

This function is a coroutine.

Retrieves a list of auto moderation rules for this guild.

Returns:

The auto moderation rules for this guild.

Return type:

List[AutoModRule]

Raises:
  • HTTPException – Getting the auto moderation rules failed.

  • Forbidden – You do not have the Manage Guild permission.

await fetch_ban(user)

This function is a coroutine.

Retrieves the BanEntry for a user.

You must have the ban_members permission to get this information.

Parameters:

user (abc.Snowflake) – The user to get ban information from.

Returns:

The BanEntry object for the specified user.

Return type:

BanEntry

Raises:
  • 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.GuildChannel or Thread with the specified ID.

Note

This method is an API call. For general usage, consider get_channel_or_thread() instead.

Added in version 2.0.

Returns:

The channel from the ID.

Return type:

Union[abc.GuildChannel, Thread]

Raises:
  • 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.

Parameters:

channel_id (int)

await fetch_channels()

This function is a coroutine.

Retrieves all abc.GuildChannel that the guild has.

Note

This method is an API call. For general usage, consider channels instead.

Added in version 1.2.

Returns:

All channels in the guild.

Return type:

Sequence[discord.channel.base.GuildChannel]

Raises:
await fetch_emoji(emoji_id, /)

This function is a coroutine.

Retrieves a custom GuildEmoji from the guild.

Note

This method is an API call. For general usage, consider iterating over emojis instead.

Parameters:

emoji_id (int) – The emoji’s ID.

Returns:

The retrieved emoji.

Return type:

GuildEmoji

Raises:
  • NotFound – The emoji requested could not be found.

  • HTTPException – An error occurred fetching the emoji.

await fetch_emojis()

This function is a coroutine.

Retrieves all custom GuildEmojis from the guild.

Note

This method is an API call. For general usage, consider emojis instead.

Raises:

HTTPException – An error occurred fetching the emojis.

Returns:

The retrieved emojis.

Return type:

List[GuildEmoji]

await fetch_member(member_id, /)

This function is a coroutine.

Retrieves a Member from a guild ID, and a member ID.

Note

This method is an API call. If you have Intents.members and member cache enabled, consider get_member() instead.

Parameters:

member_id (int) – The member’s ID to fetch from.

Returns:

The member from the member ID.

Return type:

Member

Raises:
fetch_members(*, limit=1000, after=None)

Retrieves an AsyncIterator that enables receiving the guild’s members. In order to use this, Intents.members() must be enabled.

Note

This method is an API call. For general usage, consider members instead.

Added in version 1.3.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of members to retrieve. Defaults to 1000. Pass None to fetch all members. Note that this is potentially slow.

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Member – The member with the member data parsed.

Raises:
Return type:

MemberIterator

Examples

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...
await fetch_role(role_id)

This function is a coroutine.

Retrieves a Role that the guild has.

Note

This method is an API call. For general usage, consider using get_role instead.

Added in version 2.7.

Returns:

The role in the guild with the specified ID.

Return type:

Role

Raises:

HTTPException – Retrieving the role failed.

Parameters:

role_id (int)

await fetch_roles()

This function is a coroutine.

Retrieves all Role that the guild has.

Note

This method is an API call. For general usage, consider roles instead.

Added in version 1.3.

Returns:

All roles in the guild.

Return type:

List[Role]

Raises:

HTTPException – Retrieving the roles failed.

await fetch_scheduled_event(event_id, /, *, with_user_count=True)

This function is a coroutine.

Retrieves a ScheduledEvent from event ID.

Note

This method is an API call. If you have Intents.scheduled_events, consider get_scheduled_event() instead.

Parameters:
  • event_id (int) – The event’s ID to fetch with.

  • with_user_count (Optional[bool]) – If the scheduled vent should be fetched with the number of users that are interested in the event. Defaults to True.

Returns:

The scheduled event from the event ID.

Return type:

Optional[ScheduledEvent]

Raises:
await fetch_scheduled_events(*, with_user_count=True)

This function is a coroutine.

Returns a list of ScheduledEvent in the guild.

Note

This method is an API call. For general usage, consider scheduled_events instead.

Parameters:

with_user_count (Optional[bool]) – If the scheduled event should be fetched with the number of users that are interested in the events. Defaults to True.

Returns:

The fetched scheduled events.

Return type:

List[ScheduledEvent]

Raises:
await fetch_sound(sound_id)

This function is a coroutine. Fetches a soundboard sound in the guild.

Added in version 2.7.

Parameters:

sound_id (int) – The ID of the sound.

Returns:

The sound.

Return type:

SoundboardSound

await fetch_sounds()

This function is a coroutine. Fetches all the soundboard sounds in the guild.

Added in version 2.7.

Returns:

The sounds in the guild.

Return type:

List[SoundboardSound]

await fetch_sticker(sticker_id, /)

This function is a coroutine.

Retrieves a custom Sticker from the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider iterating over stickers instead.

Parameters:

sticker_id (int) – The sticker’s ID.

Returns:

The retrieved sticker.

Return type:

GuildSticker

Raises:
  • NotFound – The sticker requested could not be found.

  • HTTPException – An error occurred fetching the sticker.

await fetch_stickers()

This function is a coroutine.

Retrieves a list of all Stickers for the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider stickers instead.

Raises:

HTTPException – An error occurred fetching the stickers.

Returns:

The retrieved stickers.

Return type:

List[GuildSticker]

property filesize_limit: int

The maximum number of bytes files can have when uploaded to this guild.

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.

get_channel(channel_id, /)

Returns a channel with the given ID.

Note

This does not search for threads.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or None if not found.

Return type:

Optional[abc.GuildChannel]

get_channel_or_thread(channel_id, /)

Returns a channel or thread with the given ID.

Added in version 2.0.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or thread or None if not found.

Return type:

Optional[Union[Thread, abc.GuildChannel]]

await get_me()

Similar to Client.user except an instance of Member. This is essentially used to get the member version of yourself.

Return type:

Member

await get_member(user_id, /)

Returns a member with the given ID.

Parameters:

user_id (int) – The ID to search for.

Returns:

The member or None if not found.

Return type:

Optional[Member]

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, None is returned.

Parameters:

name (str) – The name of the member to lookup with an optional discriminator.

Returns:

The member in this guild with the associated name. If not found then None is returned.

Return type:

Optional[Member]

await get_members()

A list of members that belong to this guild.

Return type:

list[Member]

await get_owner()

The member that owns the guild.

Return type:

Member | None

get_role(role_id, /)

Returns a role with the given ID.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found.

Return type:

Optional[Role]

get_scheduled_event(event_id, /)

Returns a Scheduled Event with the given ID.

Parameters:

event_id (int) – The ID to search for.

Returns:

The scheduled event or None if not found.

Return type:

Optional[ScheduledEvent]

get_sound(sound_id)

Returns a sound with the given ID.

Added in version 2.7.

Parameters:

sound_id (int) – The ID to search for.

Returns:

The sound or None if not found.

Return type:

Optional[SoundboardSound]

get_stage_instance(stage_instance_id, /)

Returns a stage instance with the given ID.

Added in version 2.0.

Parameters:

stage_instance_id (int) – The ID to search for.

Returns:

The stage instance or None if not found.

Return type:

Optional[StageInstance]

get_thread(thread_id, /)

Returns a thread with the given ID.

Added in version 2.0.

Parameters:

thread_id (int) – The ID to search for.

Returns:

The returned thread or None if not found.

Return type:

Optional[Thread]

property icon: Asset | None

Returns the guild’s icon asset, if available.

await integrations()

This function is a coroutine.

Returns a list of all integrations attached to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Returns:

The list of integrations that are attached to the guild.

Return type:

List[Integration]

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – Fetching the integrations failed.

await invites()

This function is a coroutine.

Returns a list of all active instant invites from the guild.

You must have the manage_guild permission to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

property invites_disabled: bool

A boolean indicating whether the guild invites are disabled.

await is_chunked()

Returns a boolean indicating if the guild is “chunked”.

A chunked guild means that member_count is equal to the number of members stored in the internal members cache.

If this value returns False, then you should request for offline members.

Return type:

bool

await is_large()

Indicates if the guild is a ‘large’ guild.

A large guild is defined as having more than large_threshold count members, which for this library is set to the maximum of 250.

Return type:

bool

property jump_url: str

Returns a URL that allows the client to jump to the guild.

Added in version 2.0.

await kick(user, *, reason=None)

This function is a coroutine.

Kicks a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the kick_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to kick from their guild.

  • reason (Optional[str]) – The reason the user got kicked.

Raises:
Return type:

None

await leave()

This function is a coroutine.

Leaves the guild. :rtype: None

Note

You cannot leave the guild that you own, you must delete it instead via delete().

Raises:

HTTPException – Leaving the guild failed.

property member_count: int

Returns the true member count regardless of it being loaded fully or not.

Warning

Due to a Discord limitation, in order for this attribute to remain up-to-date and accurate, it requires Intents.members to be specified.

await modify_incident_actions(*, invites_disabled_until=Undefined.MISSING, dms_disabled_until=Undefined.MISSING, reason=Undefined.MISSING)

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_guild permission.

Parameters:
  • invites_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when invites will be enabled again, or None to enable invites immediately.

  • dms_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when DMs will be enabled again, or None to enable DMs immediately.

  • reason (Optional[str]) – The reason for this action, used for the audit log.

Returns:

The updated incidents data for the guild.

Return type:

IncidentsData

await onboarding()

This function is a coroutine.

Returns the Onboarding flow for the guild.

Added in version 2.5.

Returns:

The onboarding flow for the guild.

Return type:

Onboarding

Raises:

HTTPException – Retrieving the onboarding flow failed somehow.

property premium_subscriber_role: Role | None

Gets the premium subscriber role, AKA “boost” role, in this guild.

Added in version 1.6.

property premium_subscribers: list[Member]

A list of members who have “boosted” this guild.

await prune_members(*, days, compute_prune_count=True, roles=Undefined.MISSING, 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 days number of days and have no roles.

You must have the kick_members permission 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 roles parameter.

Changed in version 1.4: The roles keyword-only parameter was added.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

  • compute_prune_count (bool) – Whether to compute the prune count. This defaults to True which makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this to False. If this is set to False, then this function will always return None.

  • roles (List[abc.Snowflake]) – A list of abc.Snowflake that represent roles to include in the pruning process. If a member has a role that is not specified, they’ll be excluded.

Raises:
Returns:

The number of members pruned. If compute_prune_count is False then this returns None.

Return type:

Optional[int]

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.

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.

Parameters:
  • query (Optional[str]) – The string that the username’s start with.

  • user_ids (Optional[List[int]]) –

    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 (Optional[int]) – The maximum number of members to send back. If no query is passed, passing None returns all members. If a query or user_ids is passed, must be between 1 and 100. Defaults to 5.

  • presences (Optional[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 as get_member() work for those that matched. Defaults to True.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:
property roles: list[Role]

Returns a list of the guild’s roles in hierarchy order.

The first element of this list will be the lowest role in the hierarchy.

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 scheduled_events: list[ScheduledEvent]

A list of scheduled events in this guild.

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 require Intents.members().

Note

This method is an API call. For general usage, consider filtering members instead.

Added in version 2.6.

Parameters:
  • query (str) – Searches for usernames and nicknames that start with this string, case-insensitive.

  • limit (int) – The maximum number of members to retrieve, up to 1000.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:

HTTPException – Getting the members failed.

property self_role: Role | None

Gets the role associated with this client’s user, if any.

Added in version 1.6.

await set_mfa_required(required, *, reason=None)

This function is a coroutine.

Set whether it is required to have MFA enabled on your account to perform moderation actions. You must be the guild owner to do this.

Parameters:
  • required (bool) – Whether MFA should be required to perform moderation actions.

  • reason (str) – The reason to show up in the audit log.

Raises:
Return type:

None

property shard_id: int

Returns the shard ID for this guild if applicable.

property soundboard_limit: int

The maximum number of soundboard slots this guild has.

Added in version 2.7.

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.

property splash: Asset | None

Returns the guild’s invite splash asset, if available.

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 stage_instances: list[StageInstance]

Returns a list of the guild’s stage instances that are currently running.

Added in version 2.0.

property sticker_limit: int

The maximum number of sticker slots this guild has.

Added in version 2.0.

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.

await templates()

This function is a coroutine.

Gets the list of templates from this guild.

Requires manage_guild permissions.

Added in version 1.7.

Returns:

The templates for this guild.

Return type:

List[Template]

Raises:

Forbidden – You don’t have permissions to get the templates.

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 threads: list[Thread]

A list of threads that you have permission to view.

Added in version 2.0.

await unban(user, *, reason=None)

This function is a coroutine.

Unbans a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to unban.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
Return type:

None

await vanity_invite()

This function is a coroutine.

Returns the guild’s special vanity invite.

The guild must have VANITY_URL in features.

You must have the manage_guild permission to use this as well.

Returns:

The special vanity invite. If None then the guild does not have a vanity invite set.

Return type:

Optional[Invite]

Raises:
  • Forbidden – You do not have the proper permissions to get this.

  • HTTPException – Retrieving the vanity invite failed.

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 voice_client: VoiceClient | None

Returns the VoiceClient associated with this guild, if any.

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this guild.

Requires manage_webhooks permissions.

Returns:

The webhooks for this guild.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

await welcome_screen()

This function is a coroutine.

Returns the WelcomeScreen of the guild.

The guild must have COMMUNITY in features.

You must have the manage_guild permission in order to get this.

Added in version 2.0.

Returns:

The welcome screen of guild.

Return type:

WelcomeScreen

Raises:
  • 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 widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Returns:

The guild’s widget.

Return type:

Widget

Raises:
class discord.events.GuildCreate[source]

Internal event representing a guild becoming available via the gateway.

This event trickles down to the more distinct GuildJoin and GuildAvailable events. Users should typically listen to those events instead.

This event inherits from Guild.

await active_threads()

This function is a coroutine.

Returns a list of active Thread that the client can access.

This includes both private and public threads.

Added in version 2.0.

Returns:

The active threads

Return type:

List[Thread]

Raises:

HTTPException – The request to get the active threads failed.

await audit_logs(*, limit=100, before=None, after=None, user=None, action=None)

Returns an AsyncIterator that enables receiving the guild’s audit logs.

You must have the view_audit_log permission to use this.

See API documentation for more information about the before and after parameters.

Parameters:
  • limit (Optional[int]) – The number of entries to retrieve. If None retrieve all entries.

  • before (Union[abc.Snowflake, datetime.datetime]) – 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 (Union[abc.Snowflake, datetime.datetime]) – 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 (abc.Snowflake) – The moderator to filter entries from.

  • action (AuditLogAction) – The action to filter with.

Yields:

AuditLogEntry – The audit log entry.

Raises:
  • Forbidden – You are not allowed to fetch audit logs

  • HTTPException – An error occurred while fetching the audit logs.

Return type:

AuditLogIterator

Examples

Getting the first 100 entries:

async for entry in guild.audit_logs(limit=100):
    print(f"{entry.user} did {entry.action} to {await entry.get_target()}")

Getting entries for a specific action:

async for entry in guild.audit_logs(action=discord.AuditLogAction.ban):
    print(f"{entry.user} banned {await entry.get_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 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.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to ban from their guild.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the user got banned.

Raises:
Return type:

None

property banner: Asset | None

Returns the guild’s banner asset, if available.

bans(limit=None, before=None, after=None)

This function is a coroutine.

Retrieves an AsyncIterator that enables receiving the guild’s bans. In order to use this, you must have the ban_members permission. Users will always be returned in ascending order sorted by user ID. If both the before and after parameters are provided, only before is respected.

Changed in version 2.5: The before. and after parameters were changed. They are now of the type abc.Snowflake instead of SnowflakeTime to comply with the discord api.

Changed in version 2.0: The limit, before. and after parameters were added. Now returns a BanIterator instead of a list of BanEntry objects.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of bans to retrieve. Defaults to 1000.

  • before (Optional[abc.Snowflake]) – Retrieve bans before the given user.

  • after (Optional[abc.Snowflake]) – Retrieve bans after the given user.

Yields:

BanEntry – The ban entry for the ban.

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

Return type:

BanIterator

Examples

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...
property bitrate_limit: int

The maximum bitrate for voice channels this guild can have.

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.Snowflake abc.

You must have the ban_members permission 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)
Parameters:
  • *users (abc.Snowflake) – An argument list of users to ban from the guild, up to 200.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the users were banned.

Returns:

Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.

Return type:

Tuple[List[abc.Snowflake], List[abc.Snowflake]]

Raises:
by_category()

Returns every CategoryChannel and 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.

Returns:

The categories and their associated channels.

Return type:

List[Tuple[Optional[CategoryChannel], List[abc.GuildChannel]]]

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.

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.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – Channel the client wants to join. Use None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

property channels: list[GuildChannel]

A list of channels that belong to this guild.

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.

Parameters:

cache (bool) – Whether to cache the members as well.

Raises:

ClientException – The members intent is not enabled.

Return type:

None

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.

Parameters:
  • 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[abc.Snowflake]) – A list of roles that are exempt from the rule.

  • exempt_channels (List[abc.Snowflake]) – A list of channels that are exempt from the rule.

  • reason (Optional[str]) – The reason for creating the rule. Shows up in the audit log.

Returns:

The new auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Creating the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

await create_category(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_category_channel(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_custom_emoji(*, name, image, roles=Undefined.MISSING, reason=None)

This function is a coroutine.

Creates a custom GuildEmoji for the guild.

There is currently a limit of 50 static and animated emojis respectively per guild, unless the guild has the MORE_EMOJI feature which extends the limit to 200.

You must have the manage_emojis permission to do this.

Parameters:
  • 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]) – A list of Roles that can use this emoji. Leave empty to make it available to everyone.

  • reason (Optional[str]) – The reason for creating this emoji. Shows up on the audit log.

Raises:
Returns:

The created emoji.

Return type:

GuildEmoji

await create_forum_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_reaction_emoji=Undefined.MISSING, available_tags=Undefined.MISSING, default_sort_order=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a ForumChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_reaction_emoji (Optional[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 (Optional[SortOrder]) –

    The default sort order type used to order posts in this channel.

    Added in version 2.7.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

ForumChannel

Raises:

Examples

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_integration(*, type, id)

This function is a coroutine.

Attaches an integration to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Parameters:
  • type (str) – The integration type (e.g. Twitch).

  • id (int) – The integration ID.

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – The account could not be found.

Return type:

None

await create_role(*, name=Undefined.MISSING, permissions=Undefined.MISSING, color=Undefined.MISSING, colour=Undefined.MISSING, colors=Undefined.MISSING, colours=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, reason=None, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Creates a Role for the guild.

All fields are optional.

You must have the manage_roles permission to do this.

Changed in version 1.6: Can now pass int to colour keyword-only parameter.

Parameters:
  • name (str) – The role name. Defaults to ‘new role’.

  • permissions (Permissions) – The permissions to have. Defaults to no permissions.

  • colour (Union[Colour, int]) – The colour for the role. Defaults to Colour.default(). This is aliased to color as well.

  • hoist (bool) – Indicates if the role should be shown separately in the member list. Defaults to False.

  • mentionable (bool) – Indicates if the role should be mentionable by others. Defaults to False.

  • reason (Optional[str]) – The reason for creating this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • color (Colour | int | utils.Undefined)

  • colors (RoleColours | utils.Undefined)

  • colours (RoleColours | utils.Undefined)

  • holographic (bool | utils.Undefined)

Returns:

The newly created role.

Return type:

Role

Raises:
await create_scheduled_event(*, name, description=Undefined.MISSING, start_time, end_time=Undefined.MISSING, location, privacy_level=ScheduledEventPrivacyLevel.guild_only, reason=None, image=Undefined.MISSING)

This function is a coroutine. Creates a scheduled event.

Parameters:
  • name (str) – The name of the scheduled event.

  • description (Optional[str]) – The description of the scheduled event.

  • start_time (datetime.datetime) – A datetime object of when the scheduled event is supposed to start.

  • end_time (Optional[datetime.datetime]) – A datetime object of when the scheduled event is supposed to end.

  • location (ScheduledEventLocation) – The location of where the event is happening.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event

Returns:

The created scheduled event.

Return type:

Optional[ScheduledEvent]

Raises:
await create_sound(name, sound, volume=1.0, emoji=None, reason=None)

This function is a coroutine. Creates a SoundboardSound in the guild. You must have Permissions.manage_expressions permission to use this.

Added in version 2.7.

Parameters:
  • 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 (Optional[Union[PartialEmoji, GuildEmoji, str]]) – The emoji of the sound.

  • reason (Optional[str]) – The reason for creating this sound. Shows up on the audit log.

Returns:

The created sound.

Return type:

SoundboardSound

Raises:
await create_stage_channel(name, *, topic, position=Undefined.MISSING, overwrites=Undefined.MISSING, category=None, reason=None, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a StageChannel instead.

Added in version 1.7.

Parameters:
  • name (str) – The channel’s name.

  • topic (str) – The new channel’s topic.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

StageChannel

Raises:
  • 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_sticker(*, name, description=None, emoji, file, reason=None)

This function is a coroutine.

Creates a Sticker for the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • name (str) – The sticker name. Must be 2 to 30 characters.

  • description (Optional[str]) – 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) – The reason for creating this sticker. Shows up on the audit log.

Returns:

The created sticker.

Return type:

GuildSticker

Raises:
  • 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 create_template(*, name, description=Undefined.MISSING)

This function is a coroutine.

Creates a template for the guild.

You must have the manage_guild permission to do this.

Added in version 1.7.

Parameters:
  • name (str) – The name of the template.

  • description (str) – The description of the template.

Return type:

Template

await create_test_entitlement(sku)

This function is a coroutine.

Creates a test entitlement for the guild.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

await create_text_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a TextChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

TextChannel

Raises:
  • 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.

Examples

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=Undefined.MISSING, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, overwrites=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a VoiceChannel instead.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 (Optional[str]) – 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

VoiceChannel

Raises:
  • 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.

property created_at: datetime

Returns the guild’s creation time in UTC.

property default_role: Role

Gets the @everyone role that all members have by default.

await delete()

This function is a coroutine.

Deletes the guild. You must be the guild owner to delete the guild.

Raises:
Return type:

None

await delete_auto_moderation_rule(id, *, reason=None)

Deletes an auto moderation rule.

Parameters:
  • id (int) – The ID of the auto moderation rule.

  • reason (Optional[str]) – The reason for deleting the rule. Shows up in the audit log.

Raises:
  • HTTPException – Deleting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Return type:

None

await delete_emoji(emoji, *, reason=None)

This function is a coroutine.

Deletes the custom GuildEmoji from the guild.

You must have manage_emojis permission to do this.

Parameters:
  • emoji (abc.Snowflake) – The emoji you are deleting.

  • reason (Optional[str]) – The reason for deleting this emoji. Shows up on the audit log.

Raises:
Return type:

None

await delete_sticker(sticker, *, reason=None)

This function is a coroutine.

Deletes the custom Sticker from the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • sticker (abc.Snowflake) – The sticker you are deleting.

  • reason (Optional[str]) – The reason for deleting this sticker. Shows up on the audit log.

Raises:
  • Forbidden – You are not allowed to delete stickers.

  • HTTPException – An error occurred deleting the sticker.

Return type:

None

property discovery_splash: Asset | None

Returns the guild’s discovery splash asset, if available.

await edit(*, reason=Undefined.MISSING, name=Undefined.MISSING, description=Undefined.MISSING, icon=Undefined.MISSING, banner=Undefined.MISSING, splash=Undefined.MISSING, discovery_splash=Undefined.MISSING, community=Undefined.MISSING, afk_channel=Undefined.MISSING, owner=Undefined.MISSING, afk_timeout=Undefined.MISSING, default_notifications=Undefined.MISSING, verification_level=Undefined.MISSING, explicit_content_filter=Undefined.MISSING, system_channel=Undefined.MISSING, system_channel_flags=Undefined.MISSING, preferred_locale=Undefined.MISSING, rules_channel=Undefined.MISSING, public_updates_channel=Undefined.MISSING, premium_progress_bar_enabled=Undefined.MISSING, disable_invites=Undefined.MISSING, discoverable=Undefined.MISSING, disable_raid_alerts=Undefined.MISSING, enable_activity_feed=Undefined.MISSING)

This function is a coroutine.

Edits the guild.

You must have the manage_guild permission to edit the guild.

Changed in version 1.4: The rules_channel and public_updates_channel keyword-only parameters were added.

Changed in version 2.0: The discovery_splash and community keyword-only parameters were added.

Changed in version 2.0: The newly updated guild is returned.

Parameters:
  • name (str) – The new name of the guild.

  • description (Optional[str]) – The new description of the guild. Could be None for no description. This is only available to guilds that contain PUBLIC in Guild.features.

  • icon (bytes) – A bytes-like object representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that contain ANIMATED_ICON in Guild.features. Could be None to denote removal of the icon.

  • banner (bytes) – A bytes-like object representing the banner. Could be None to denote removal of the banner. This is only available to guilds that contain BANNER in Guild.features.

  • splash (bytes) – A bytes-like object representing the invite splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain INVITE_SPLASH in Guild.features.

  • discovery_splash (bytes) – A bytes-like object representing the discovery splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain DISCOVERABLE in Guild.features.

  • community (bool) – Whether the guild should be a Community guild. If set to True, both rules_channel and public_updates_channel parameters are required.

  • afk_channel (Optional[VoiceChannel]) – The new channel that is the AFK channel. Could be None for no AFK channel.

  • afk_timeout (int) – The number of seconds until someone is moved to the AFK channel.

  • owner (Member) – The new owner of the guild to transfer ownership to. Note that you must be owner of the guild to do this.

  • 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 (Optional[TextChannel]) – The new channel that is used for the system channel. Could be None for 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-US or ja or zh-CN.

  • rules_channel (Optional[TextChannel]) – The new channel that is used for rules. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for no rules channel.

  • public_updates_channel (Optional[TextChannel]) – The new channel that is used for public updates from Discord. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for 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 (class:bool) – Whether the guild’s user activity feed should be enabled.

  • reason (Optional[str]) – The reason for editing this guild. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to edit the guild.

  • HTTPException – Editing the guild failed.

  • InvalidArgument – The image format passed in to icon is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the guild and request an ownership transfer.

Returns:

The newly updated guild. Note that this has the same limitations as mentioned in Client.fetch_guild() and may not have full data.

Return type:

Guild

await edit_onboarding(*, prompts=Undefined.MISSING, default_channels=Undefined.MISSING, enabled=Undefined.MISSING, mode=Undefined.MISSING, reason=Undefined.MISSING)

This function is a coroutine.

A shorthand for Onboarding.edit without fetching the onboarding flow.

You must have the manage_guild and manage_roles permissions in the guild to do this.

Parameters:
  • prompts (Optional[List[OnboardingPrompt]]) – The new list of prompts for this flow.

  • default_channels (Optional[List[Snowflake]]) – The new default channels that users are opted into.

  • enabled (Optional[bool]) – Whether onboarding should be enabled. Setting this to True requires the guild to have COMMUNITY in features and at least 7 default_channels.

  • mode (Optional[OnboardingMode]) – The new onboarding mode.

  • reason (Optional[str]) – The reason that shows up on Audit log.

Returns:

The updated onboarding flow.

Return type:

Onboarding

Raises:
  • HTTPException – Editing the onboarding flow failed somehow.

  • Forbidden – You don’t have permissions to edit the onboarding flow.

await edit_role_positions(positions, *, reason=None)

This function is a coroutine.

Bulk edits a list of Role in the guild.

You must have the manage_roles permission 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)
Parameters:
  • positions (Dict[Role, int]) – A dict of Role to int to change the positions of each given role.

  • reason (Optional[str]) – The reason for editing the role positions. Shows up on the audit log.

Returns:

A list of all the roles in the guild.

Return type:

List[Role]

Raises:
await edit_welcome_screen(**options)

This function is a coroutine.

A shorthand for WelcomeScreen.edit without fetching the welcome screen.

You must have the manage_guild permission in the guild to do this.

The guild must have COMMUNITY in Guild.features

Parameters:
  • 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.

Returns:

The edited welcome screen.

Return type:

WelcomeScreen

Raises:
  • 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 edit_widget(*, enabled=Undefined.MISSING, channel=Undefined.MISSING)

This function is a coroutine.

Edits the widget of the guild.

You must have the manage_guild permission to use this

Added in version 2.0.

Parameters:
  • enabled (bool) – Whether to enable the widget for the guild.

  • channel (Optional[Snowflake]) – The new widget channel. None removes the widget channel.

Raises:
Return type:

None

property emoji_limit: int

The maximum number of emoji slots this guild has.

entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)

Returns an AsyncIterator that enables fetching the guild’s entitlements.

This is identical to Client.entitlements() with the guild parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

Return type:

EntitlementIterator

await estimate_pruned_members(*, days, roles=Undefined.MISSING)

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.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • roles (List[abc.Snowflake]) –

    A list of abc.Snowflake that 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.

Returns:

The number of members estimated to be pruned.

Return type:

int

Raises:
  • 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 fetch_auto_moderation_rule(id)

This function is a coroutine.

Retrieves a AutoModRule from rule ID.

Returns:

The requested auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Getting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Parameters:

id (int)

await fetch_auto_moderation_rules()

This function is a coroutine.

Retrieves a list of auto moderation rules for this guild.

Returns:

The auto moderation rules for this guild.

Return type:

List[AutoModRule]

Raises:
  • HTTPException – Getting the auto moderation rules failed.

  • Forbidden – You do not have the Manage Guild permission.

await fetch_ban(user)

This function is a coroutine.

Retrieves the BanEntry for a user.

You must have the ban_members permission to get this information.

Parameters:

user (abc.Snowflake) – The user to get ban information from.

Returns:

The BanEntry object for the specified user.

Return type:

BanEntry

Raises:
  • 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.GuildChannel or Thread with the specified ID.

Note

This method is an API call. For general usage, consider get_channel_or_thread() instead.

Added in version 2.0.

Returns:

The channel from the ID.

Return type:

Union[abc.GuildChannel, Thread]

Raises:
  • 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.

Parameters:

channel_id (int)

await fetch_channels()

This function is a coroutine.

Retrieves all abc.GuildChannel that the guild has.

Note

This method is an API call. For general usage, consider channels instead.

Added in version 1.2.

Returns:

All channels in the guild.

Return type:

Sequence[discord.channel.base.GuildChannel]

Raises:
await fetch_emoji(emoji_id, /)

This function is a coroutine.

Retrieves a custom GuildEmoji from the guild.

Note

This method is an API call. For general usage, consider iterating over emojis instead.

Parameters:

emoji_id (int) – The emoji’s ID.

Returns:

The retrieved emoji.

Return type:

GuildEmoji

Raises:
  • NotFound – The emoji requested could not be found.

  • HTTPException – An error occurred fetching the emoji.

await fetch_emojis()

This function is a coroutine.

Retrieves all custom GuildEmojis from the guild.

Note

This method is an API call. For general usage, consider emojis instead.

Raises:

HTTPException – An error occurred fetching the emojis.

Returns:

The retrieved emojis.

Return type:

List[GuildEmoji]

await fetch_member(member_id, /)

This function is a coroutine.

Retrieves a Member from a guild ID, and a member ID.

Note

This method is an API call. If you have Intents.members and member cache enabled, consider get_member() instead.

Parameters:

member_id (int) – The member’s ID to fetch from.

Returns:

The member from the member ID.

Return type:

Member

Raises:
fetch_members(*, limit=1000, after=None)

Retrieves an AsyncIterator that enables receiving the guild’s members. In order to use this, Intents.members() must be enabled.

Note

This method is an API call. For general usage, consider members instead.

Added in version 1.3.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of members to retrieve. Defaults to 1000. Pass None to fetch all members. Note that this is potentially slow.

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Member – The member with the member data parsed.

Raises:
Return type:

MemberIterator

Examples

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...
await fetch_role(role_id)

This function is a coroutine.

Retrieves a Role that the guild has.

Note

This method is an API call. For general usage, consider using get_role instead.

Added in version 2.7.

Returns:

The role in the guild with the specified ID.

Return type:

Role

Raises:

HTTPException – Retrieving the role failed.

Parameters:

role_id (int)

await fetch_roles()

This function is a coroutine.

Retrieves all Role that the guild has.

Note

This method is an API call. For general usage, consider roles instead.

Added in version 1.3.

Returns:

All roles in the guild.

Return type:

List[Role]

Raises:

HTTPException – Retrieving the roles failed.

await fetch_scheduled_event(event_id, /, *, with_user_count=True)

This function is a coroutine.

Retrieves a ScheduledEvent from event ID.

Note

This method is an API call. If you have Intents.scheduled_events, consider get_scheduled_event() instead.

Parameters:
  • event_id (int) – The event’s ID to fetch with.

  • with_user_count (Optional[bool]) – If the scheduled vent should be fetched with the number of users that are interested in the event. Defaults to True.

Returns:

The scheduled event from the event ID.

Return type:

Optional[ScheduledEvent]

Raises:
await fetch_scheduled_events(*, with_user_count=True)

This function is a coroutine.

Returns a list of ScheduledEvent in the guild.

Note

This method is an API call. For general usage, consider scheduled_events instead.

Parameters:

with_user_count (Optional[bool]) – If the scheduled event should be fetched with the number of users that are interested in the events. Defaults to True.

Returns:

The fetched scheduled events.

Return type:

List[ScheduledEvent]

Raises:
await fetch_sound(sound_id)

This function is a coroutine. Fetches a soundboard sound in the guild.

Added in version 2.7.

Parameters:

sound_id (int) – The ID of the sound.

Returns:

The sound.

Return type:

SoundboardSound

await fetch_sounds()

This function is a coroutine. Fetches all the soundboard sounds in the guild.

Added in version 2.7.

Returns:

The sounds in the guild.

Return type:

List[SoundboardSound]

await fetch_sticker(sticker_id, /)

This function is a coroutine.

Retrieves a custom Sticker from the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider iterating over stickers instead.

Parameters:

sticker_id (int) – The sticker’s ID.

Returns:

The retrieved sticker.

Return type:

GuildSticker

Raises:
  • NotFound – The sticker requested could not be found.

  • HTTPException – An error occurred fetching the sticker.

await fetch_stickers()

This function is a coroutine.

Retrieves a list of all Stickers for the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider stickers instead.

Raises:

HTTPException – An error occurred fetching the stickers.

Returns:

The retrieved stickers.

Return type:

List[GuildSticker]

property filesize_limit: int

The maximum number of bytes files can have when uploaded to this guild.

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.

get_channel(channel_id, /)

Returns a channel with the given ID.

Note

This does not search for threads.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or None if not found.

Return type:

Optional[abc.GuildChannel]

get_channel_or_thread(channel_id, /)

Returns a channel or thread with the given ID.

Added in version 2.0.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or thread or None if not found.

Return type:

Optional[Union[Thread, abc.GuildChannel]]

await get_me()

Similar to Client.user except an instance of Member. This is essentially used to get the member version of yourself.

Return type:

Member

await get_member(user_id, /)

Returns a member with the given ID.

Parameters:

user_id (int) – The ID to search for.

Returns:

The member or None if not found.

Return type:

Optional[Member]

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, None is returned.

Parameters:

name (str) – The name of the member to lookup with an optional discriminator.

Returns:

The member in this guild with the associated name. If not found then None is returned.

Return type:

Optional[Member]

await get_members()

A list of members that belong to this guild.

Return type:

list[Member]

await get_owner()

The member that owns the guild.

Return type:

Member | None

get_role(role_id, /)

Returns a role with the given ID.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found.

Return type:

Optional[Role]

get_scheduled_event(event_id, /)

Returns a Scheduled Event with the given ID.

Parameters:

event_id (int) – The ID to search for.

Returns:

The scheduled event or None if not found.

Return type:

Optional[ScheduledEvent]

get_sound(sound_id)

Returns a sound with the given ID.

Added in version 2.7.

Parameters:

sound_id (int) – The ID to search for.

Returns:

The sound or None if not found.

Return type:

Optional[SoundboardSound]

get_stage_instance(stage_instance_id, /)

Returns a stage instance with the given ID.

Added in version 2.0.

Parameters:

stage_instance_id (int) – The ID to search for.

Returns:

The stage instance or None if not found.

Return type:

Optional[StageInstance]

get_thread(thread_id, /)

Returns a thread with the given ID.

Added in version 2.0.

Parameters:

thread_id (int) – The ID to search for.

Returns:

The returned thread or None if not found.

Return type:

Optional[Thread]

property icon: Asset | None

Returns the guild’s icon asset, if available.

await integrations()

This function is a coroutine.

Returns a list of all integrations attached to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Returns:

The list of integrations that are attached to the guild.

Return type:

List[Integration]

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – Fetching the integrations failed.

await invites()

This function is a coroutine.

Returns a list of all active instant invites from the guild.

You must have the manage_guild permission to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

property invites_disabled: bool

A boolean indicating whether the guild invites are disabled.

await is_chunked()

Returns a boolean indicating if the guild is “chunked”.

A chunked guild means that member_count is equal to the number of members stored in the internal members cache.

If this value returns False, then you should request for offline members.

Return type:

bool

await is_large()

Indicates if the guild is a ‘large’ guild.

A large guild is defined as having more than large_threshold count members, which for this library is set to the maximum of 250.

Return type:

bool

property jump_url: str

Returns a URL that allows the client to jump to the guild.

Added in version 2.0.

await kick(user, *, reason=None)

This function is a coroutine.

Kicks a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the kick_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to kick from their guild.

  • reason (Optional[str]) – The reason the user got kicked.

Raises:
Return type:

None

await leave()

This function is a coroutine.

Leaves the guild. :rtype: None

Note

You cannot leave the guild that you own, you must delete it instead via delete().

Raises:

HTTPException – Leaving the guild failed.

property member_count: int

Returns the true member count regardless of it being loaded fully or not.

Warning

Due to a Discord limitation, in order for this attribute to remain up-to-date and accurate, it requires Intents.members to be specified.

await modify_incident_actions(*, invites_disabled_until=Undefined.MISSING, dms_disabled_until=Undefined.MISSING, reason=Undefined.MISSING)

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_guild permission.

Parameters:
  • invites_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when invites will be enabled again, or None to enable invites immediately.

  • dms_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when DMs will be enabled again, or None to enable DMs immediately.

  • reason (Optional[str]) – The reason for this action, used for the audit log.

Returns:

The updated incidents data for the guild.

Return type:

IncidentsData

await onboarding()

This function is a coroutine.

Returns the Onboarding flow for the guild.

Added in version 2.5.

Returns:

The onboarding flow for the guild.

Return type:

Onboarding

Raises:

HTTPException – Retrieving the onboarding flow failed somehow.

property premium_subscriber_role: Role | None

Gets the premium subscriber role, AKA “boost” role, in this guild.

Added in version 1.6.

property premium_subscribers: list[Member]

A list of members who have “boosted” this guild.

await prune_members(*, days, compute_prune_count=True, roles=Undefined.MISSING, 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 days number of days and have no roles.

You must have the kick_members permission 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 roles parameter.

Changed in version 1.4: The roles keyword-only parameter was added.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

  • compute_prune_count (bool) – Whether to compute the prune count. This defaults to True which makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this to False. If this is set to False, then this function will always return None.

  • roles (List[abc.Snowflake]) – A list of abc.Snowflake that represent roles to include in the pruning process. If a member has a role that is not specified, they’ll be excluded.

Raises:
Returns:

The number of members pruned. If compute_prune_count is False then this returns None.

Return type:

Optional[int]

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.

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.

Parameters:
  • query (Optional[str]) – The string that the username’s start with.

  • user_ids (Optional[List[int]]) –

    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 (Optional[int]) – The maximum number of members to send back. If no query is passed, passing None returns all members. If a query or user_ids is passed, must be between 1 and 100. Defaults to 5.

  • presences (Optional[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 as get_member() work for those that matched. Defaults to True.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:
property roles: list[Role]

Returns a list of the guild’s roles in hierarchy order.

The first element of this list will be the lowest role in the hierarchy.

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 scheduled_events: list[ScheduledEvent]

A list of scheduled events in this guild.

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 require Intents.members().

Note

This method is an API call. For general usage, consider filtering members instead.

Added in version 2.6.

Parameters:
  • query (str) – Searches for usernames and nicknames that start with this string, case-insensitive.

  • limit (int) – The maximum number of members to retrieve, up to 1000.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:

HTTPException – Getting the members failed.

property self_role: Role | None

Gets the role associated with this client’s user, if any.

Added in version 1.6.

await set_mfa_required(required, *, reason=None)

This function is a coroutine.

Set whether it is required to have MFA enabled on your account to perform moderation actions. You must be the guild owner to do this.

Parameters:
  • required (bool) – Whether MFA should be required to perform moderation actions.

  • reason (str) – The reason to show up in the audit log.

Raises:
Return type:

None

property shard_id: int

Returns the shard ID for this guild if applicable.

property soundboard_limit: int

The maximum number of soundboard slots this guild has.

Added in version 2.7.

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.

property splash: Asset | None

Returns the guild’s invite splash asset, if available.

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 stage_instances: list[StageInstance]

Returns a list of the guild’s stage instances that are currently running.

Added in version 2.0.

property sticker_limit: int

The maximum number of sticker slots this guild has.

Added in version 2.0.

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.

await templates()

This function is a coroutine.

Gets the list of templates from this guild.

Requires manage_guild permissions.

Added in version 1.7.

Returns:

The templates for this guild.

Return type:

List[Template]

Raises:

Forbidden – You don’t have permissions to get the templates.

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 threads: list[Thread]

A list of threads that you have permission to view.

Added in version 2.0.

await unban(user, *, reason=None)

This function is a coroutine.

Unbans a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to unban.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
Return type:

None

await vanity_invite()

This function is a coroutine.

Returns the guild’s special vanity invite.

The guild must have VANITY_URL in features.

You must have the manage_guild permission to use this as well.

Returns:

The special vanity invite. If None then the guild does not have a vanity invite set.

Return type:

Optional[Invite]

Raises:
  • Forbidden – You do not have the proper permissions to get this.

  • HTTPException – Retrieving the vanity invite failed.

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 voice_client: VoiceClient | None

Returns the VoiceClient associated with this guild, if any.

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this guild.

Requires manage_webhooks permissions.

Returns:

The webhooks for this guild.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

await welcome_screen()

This function is a coroutine.

Returns the WelcomeScreen of the guild.

The guild must have COMMUNITY in features.

You must have the manage_guild permission in order to get this.

Added in version 2.0.

Returns:

The welcome screen of guild.

Return type:

WelcomeScreen

Raises:
  • 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 widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Returns:

The guild’s widget.

Return type:

Widget

Raises:
class discord.events.GuildDelete[source]

Called when a guild is removed from the client.

This happens through, but not limited to, these circumstances: - The client got banned. - The client got kicked. - The client left the guild. - The client or the guild owner deleted the guild.

In order for this event to be invoked then the client must have been part of the guild to begin with (i.e., it is part of Client.guilds).

This requires Intents.guilds to be enabled.

This event inherits from Guild.

old

The guild that was removed.

Type:

Guild

await active_threads()

This function is a coroutine.

Returns a list of active Thread that the client can access.

This includes both private and public threads.

Added in version 2.0.

Returns:

The active threads

Return type:

List[Thread]

Raises:

HTTPException – The request to get the active threads failed.

await audit_logs(*, limit=100, before=None, after=None, user=None, action=None)

Returns an AsyncIterator that enables receiving the guild’s audit logs.

You must have the view_audit_log permission to use this.

See API documentation for more information about the before and after parameters.

Parameters:
  • limit (Optional[int]) – The number of entries to retrieve. If None retrieve all entries.

  • before (Union[abc.Snowflake, datetime.datetime]) – 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 (Union[abc.Snowflake, datetime.datetime]) – 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 (abc.Snowflake) – The moderator to filter entries from.

  • action (AuditLogAction) – The action to filter with.

Yields:

AuditLogEntry – The audit log entry.

Raises:
  • Forbidden – You are not allowed to fetch audit logs

  • HTTPException – An error occurred while fetching the audit logs.

Return type:

AuditLogIterator

Examples

Getting the first 100 entries:

async for entry in guild.audit_logs(limit=100):
    print(f"{entry.user} did {entry.action} to {await entry.get_target()}")

Getting entries for a specific action:

async for entry in guild.audit_logs(action=discord.AuditLogAction.ban):
    print(f"{entry.user} banned {await entry.get_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 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.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to ban from their guild.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the user got banned.

Raises:
Return type:

None

property banner: Asset | None

Returns the guild’s banner asset, if available.

bans(limit=None, before=None, after=None)

This function is a coroutine.

Retrieves an AsyncIterator that enables receiving the guild’s bans. In order to use this, you must have the ban_members permission. Users will always be returned in ascending order sorted by user ID. If both the before and after parameters are provided, only before is respected.

Changed in version 2.5: The before. and after parameters were changed. They are now of the type abc.Snowflake instead of SnowflakeTime to comply with the discord api.

Changed in version 2.0: The limit, before. and after parameters were added. Now returns a BanIterator instead of a list of BanEntry objects.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of bans to retrieve. Defaults to 1000.

  • before (Optional[abc.Snowflake]) – Retrieve bans before the given user.

  • after (Optional[abc.Snowflake]) – Retrieve bans after the given user.

Yields:

BanEntry – The ban entry for the ban.

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

Return type:

BanIterator

Examples

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...
property bitrate_limit: int

The maximum bitrate for voice channels this guild can have.

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.Snowflake abc.

You must have the ban_members permission 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)
Parameters:
  • *users (abc.Snowflake) – An argument list of users to ban from the guild, up to 200.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the users were banned.

Returns:

Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.

Return type:

Tuple[List[abc.Snowflake], List[abc.Snowflake]]

Raises:
by_category()

Returns every CategoryChannel and 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.

Returns:

The categories and their associated channels.

Return type:

List[Tuple[Optional[CategoryChannel], List[abc.GuildChannel]]]

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.

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.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – Channel the client wants to join. Use None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

property channels: list[GuildChannel]

A list of channels that belong to this guild.

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.

Parameters:

cache (bool) – Whether to cache the members as well.

Raises:

ClientException – The members intent is not enabled.

Return type:

None

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.

Parameters:
  • 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[abc.Snowflake]) – A list of roles that are exempt from the rule.

  • exempt_channels (List[abc.Snowflake]) – A list of channels that are exempt from the rule.

  • reason (Optional[str]) – The reason for creating the rule. Shows up in the audit log.

Returns:

The new auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Creating the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

await create_category(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_category_channel(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_custom_emoji(*, name, image, roles=Undefined.MISSING, reason=None)

This function is a coroutine.

Creates a custom GuildEmoji for the guild.

There is currently a limit of 50 static and animated emojis respectively per guild, unless the guild has the MORE_EMOJI feature which extends the limit to 200.

You must have the manage_emojis permission to do this.

Parameters:
  • 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]) – A list of Roles that can use this emoji. Leave empty to make it available to everyone.

  • reason (Optional[str]) – The reason for creating this emoji. Shows up on the audit log.

Raises:
Returns:

The created emoji.

Return type:

GuildEmoji

await create_forum_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_reaction_emoji=Undefined.MISSING, available_tags=Undefined.MISSING, default_sort_order=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a ForumChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_reaction_emoji (Optional[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 (Optional[SortOrder]) –

    The default sort order type used to order posts in this channel.

    Added in version 2.7.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

ForumChannel

Raises:

Examples

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_integration(*, type, id)

This function is a coroutine.

Attaches an integration to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Parameters:
  • type (str) – The integration type (e.g. Twitch).

  • id (int) – The integration ID.

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – The account could not be found.

Return type:

None

await create_role(*, name=Undefined.MISSING, permissions=Undefined.MISSING, color=Undefined.MISSING, colour=Undefined.MISSING, colors=Undefined.MISSING, colours=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, reason=None, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Creates a Role for the guild.

All fields are optional.

You must have the manage_roles permission to do this.

Changed in version 1.6: Can now pass int to colour keyword-only parameter.

Parameters:
  • name (str) – The role name. Defaults to ‘new role’.

  • permissions (Permissions) – The permissions to have. Defaults to no permissions.

  • colour (Union[Colour, int]) – The colour for the role. Defaults to Colour.default(). This is aliased to color as well.

  • hoist (bool) – Indicates if the role should be shown separately in the member list. Defaults to False.

  • mentionable (bool) – Indicates if the role should be mentionable by others. Defaults to False.

  • reason (Optional[str]) – The reason for creating this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • color (Colour | int | utils.Undefined)

  • colors (RoleColours | utils.Undefined)

  • colours (RoleColours | utils.Undefined)

  • holographic (bool | utils.Undefined)

Returns:

The newly created role.

Return type:

Role

Raises:
await create_scheduled_event(*, name, description=Undefined.MISSING, start_time, end_time=Undefined.MISSING, location, privacy_level=ScheduledEventPrivacyLevel.guild_only, reason=None, image=Undefined.MISSING)

This function is a coroutine. Creates a scheduled event.

Parameters:
  • name (str) – The name of the scheduled event.

  • description (Optional[str]) – The description of the scheduled event.

  • start_time (datetime.datetime) – A datetime object of when the scheduled event is supposed to start.

  • end_time (Optional[datetime.datetime]) – A datetime object of when the scheduled event is supposed to end.

  • location (ScheduledEventLocation) – The location of where the event is happening.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event

Returns:

The created scheduled event.

Return type:

Optional[ScheduledEvent]

Raises:
await create_sound(name, sound, volume=1.0, emoji=None, reason=None)

This function is a coroutine. Creates a SoundboardSound in the guild. You must have Permissions.manage_expressions permission to use this.

Added in version 2.7.

Parameters:
  • 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 (Optional[Union[PartialEmoji, GuildEmoji, str]]) – The emoji of the sound.

  • reason (Optional[str]) – The reason for creating this sound. Shows up on the audit log.

Returns:

The created sound.

Return type:

SoundboardSound

Raises:
await create_stage_channel(name, *, topic, position=Undefined.MISSING, overwrites=Undefined.MISSING, category=None, reason=None, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a StageChannel instead.

Added in version 1.7.

Parameters:
  • name (str) – The channel’s name.

  • topic (str) – The new channel’s topic.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

StageChannel

Raises:
  • 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_sticker(*, name, description=None, emoji, file, reason=None)

This function is a coroutine.

Creates a Sticker for the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • name (str) – The sticker name. Must be 2 to 30 characters.

  • description (Optional[str]) – 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) – The reason for creating this sticker. Shows up on the audit log.

Returns:

The created sticker.

Return type:

GuildSticker

Raises:
  • 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 create_template(*, name, description=Undefined.MISSING)

This function is a coroutine.

Creates a template for the guild.

You must have the manage_guild permission to do this.

Added in version 1.7.

Parameters:
  • name (str) – The name of the template.

  • description (str) – The description of the template.

Return type:

Template

await create_test_entitlement(sku)

This function is a coroutine.

Creates a test entitlement for the guild.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

await create_text_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a TextChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

TextChannel

Raises:
  • 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.

Examples

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=Undefined.MISSING, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, overwrites=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a VoiceChannel instead.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 (Optional[str]) – 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

VoiceChannel

Raises:
  • 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.

property created_at: datetime

Returns the guild’s creation time in UTC.

property default_role: Role

Gets the @everyone role that all members have by default.

await delete()

This function is a coroutine.

Deletes the guild. You must be the guild owner to delete the guild.

Raises:
Return type:

None

await delete_auto_moderation_rule(id, *, reason=None)

Deletes an auto moderation rule.

Parameters:
  • id (int) – The ID of the auto moderation rule.

  • reason (Optional[str]) – The reason for deleting the rule. Shows up in the audit log.

Raises:
  • HTTPException – Deleting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Return type:

None

await delete_emoji(emoji, *, reason=None)

This function is a coroutine.

Deletes the custom GuildEmoji from the guild.

You must have manage_emojis permission to do this.

Parameters:
  • emoji (abc.Snowflake) – The emoji you are deleting.

  • reason (Optional[str]) – The reason for deleting this emoji. Shows up on the audit log.

Raises:
Return type:

None

await delete_sticker(sticker, *, reason=None)

This function is a coroutine.

Deletes the custom Sticker from the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • sticker (abc.Snowflake) – The sticker you are deleting.

  • reason (Optional[str]) – The reason for deleting this sticker. Shows up on the audit log.

Raises:
  • Forbidden – You are not allowed to delete stickers.

  • HTTPException – An error occurred deleting the sticker.

Return type:

None

property discovery_splash: Asset | None

Returns the guild’s discovery splash asset, if available.

await edit(*, reason=Undefined.MISSING, name=Undefined.MISSING, description=Undefined.MISSING, icon=Undefined.MISSING, banner=Undefined.MISSING, splash=Undefined.MISSING, discovery_splash=Undefined.MISSING, community=Undefined.MISSING, afk_channel=Undefined.MISSING, owner=Undefined.MISSING, afk_timeout=Undefined.MISSING, default_notifications=Undefined.MISSING, verification_level=Undefined.MISSING, explicit_content_filter=Undefined.MISSING, system_channel=Undefined.MISSING, system_channel_flags=Undefined.MISSING, preferred_locale=Undefined.MISSING, rules_channel=Undefined.MISSING, public_updates_channel=Undefined.MISSING, premium_progress_bar_enabled=Undefined.MISSING, disable_invites=Undefined.MISSING, discoverable=Undefined.MISSING, disable_raid_alerts=Undefined.MISSING, enable_activity_feed=Undefined.MISSING)

This function is a coroutine.

Edits the guild.

You must have the manage_guild permission to edit the guild.

Changed in version 1.4: The rules_channel and public_updates_channel keyword-only parameters were added.

Changed in version 2.0: The discovery_splash and community keyword-only parameters were added.

Changed in version 2.0: The newly updated guild is returned.

Parameters:
  • name (str) – The new name of the guild.

  • description (Optional[str]) – The new description of the guild. Could be None for no description. This is only available to guilds that contain PUBLIC in Guild.features.

  • icon (bytes) – A bytes-like object representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that contain ANIMATED_ICON in Guild.features. Could be None to denote removal of the icon.

  • banner (bytes) – A bytes-like object representing the banner. Could be None to denote removal of the banner. This is only available to guilds that contain BANNER in Guild.features.

  • splash (bytes) – A bytes-like object representing the invite splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain INVITE_SPLASH in Guild.features.

  • discovery_splash (bytes) – A bytes-like object representing the discovery splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain DISCOVERABLE in Guild.features.

  • community (bool) – Whether the guild should be a Community guild. If set to True, both rules_channel and public_updates_channel parameters are required.

  • afk_channel (Optional[VoiceChannel]) – The new channel that is the AFK channel. Could be None for no AFK channel.

  • afk_timeout (int) – The number of seconds until someone is moved to the AFK channel.

  • owner (Member) – The new owner of the guild to transfer ownership to. Note that you must be owner of the guild to do this.

  • 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 (Optional[TextChannel]) – The new channel that is used for the system channel. Could be None for 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-US or ja or zh-CN.

  • rules_channel (Optional[TextChannel]) – The new channel that is used for rules. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for no rules channel.

  • public_updates_channel (Optional[TextChannel]) – The new channel that is used for public updates from Discord. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for 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 (class:bool) – Whether the guild’s user activity feed should be enabled.

  • reason (Optional[str]) – The reason for editing this guild. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to edit the guild.

  • HTTPException – Editing the guild failed.

  • InvalidArgument – The image format passed in to icon is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the guild and request an ownership transfer.

Returns:

The newly updated guild. Note that this has the same limitations as mentioned in Client.fetch_guild() and may not have full data.

Return type:

Guild

await edit_onboarding(*, prompts=Undefined.MISSING, default_channels=Undefined.MISSING, enabled=Undefined.MISSING, mode=Undefined.MISSING, reason=Undefined.MISSING)

This function is a coroutine.

A shorthand for Onboarding.edit without fetching the onboarding flow.

You must have the manage_guild and manage_roles permissions in the guild to do this.

Parameters:
  • prompts (Optional[List[OnboardingPrompt]]) – The new list of prompts for this flow.

  • default_channels (Optional[List[Snowflake]]) – The new default channels that users are opted into.

  • enabled (Optional[bool]) – Whether onboarding should be enabled. Setting this to True requires the guild to have COMMUNITY in features and at least 7 default_channels.

  • mode (Optional[OnboardingMode]) – The new onboarding mode.

  • reason (Optional[str]) – The reason that shows up on Audit log.

Returns:

The updated onboarding flow.

Return type:

Onboarding

Raises:
  • HTTPException – Editing the onboarding flow failed somehow.

  • Forbidden – You don’t have permissions to edit the onboarding flow.

await edit_role_positions(positions, *, reason=None)

This function is a coroutine.

Bulk edits a list of Role in the guild.

You must have the manage_roles permission 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)
Parameters:
  • positions (Dict[Role, int]) – A dict of Role to int to change the positions of each given role.

  • reason (Optional[str]) – The reason for editing the role positions. Shows up on the audit log.

Returns:

A list of all the roles in the guild.

Return type:

List[Role]

Raises:
await edit_welcome_screen(**options)

This function is a coroutine.

A shorthand for WelcomeScreen.edit without fetching the welcome screen.

You must have the manage_guild permission in the guild to do this.

The guild must have COMMUNITY in Guild.features

Parameters:
  • 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.

Returns:

The edited welcome screen.

Return type:

WelcomeScreen

Raises:
  • 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 edit_widget(*, enabled=Undefined.MISSING, channel=Undefined.MISSING)

This function is a coroutine.

Edits the widget of the guild.

You must have the manage_guild permission to use this

Added in version 2.0.

Parameters:
  • enabled (bool) – Whether to enable the widget for the guild.

  • channel (Optional[Snowflake]) – The new widget channel. None removes the widget channel.

Raises:
Return type:

None

property emoji_limit: int

The maximum number of emoji slots this guild has.

entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)

Returns an AsyncIterator that enables fetching the guild’s entitlements.

This is identical to Client.entitlements() with the guild parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

Return type:

EntitlementIterator

await estimate_pruned_members(*, days, roles=Undefined.MISSING)

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.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • roles (List[abc.Snowflake]) –

    A list of abc.Snowflake that 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.

Returns:

The number of members estimated to be pruned.

Return type:

int

Raises:
  • 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 fetch_auto_moderation_rule(id)

This function is a coroutine.

Retrieves a AutoModRule from rule ID.

Returns:

The requested auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Getting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Parameters:

id (int)

await fetch_auto_moderation_rules()

This function is a coroutine.

Retrieves a list of auto moderation rules for this guild.

Returns:

The auto moderation rules for this guild.

Return type:

List[AutoModRule]

Raises:
  • HTTPException – Getting the auto moderation rules failed.

  • Forbidden – You do not have the Manage Guild permission.

await fetch_ban(user)

This function is a coroutine.

Retrieves the BanEntry for a user.

You must have the ban_members permission to get this information.

Parameters:

user (abc.Snowflake) – The user to get ban information from.

Returns:

The BanEntry object for the specified user.

Return type:

BanEntry

Raises:
  • 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.GuildChannel or Thread with the specified ID.

Note

This method is an API call. For general usage, consider get_channel_or_thread() instead.

Added in version 2.0.

Returns:

The channel from the ID.

Return type:

Union[abc.GuildChannel, Thread]

Raises:
  • 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.

Parameters:

channel_id (int)

await fetch_channels()

This function is a coroutine.

Retrieves all abc.GuildChannel that the guild has.

Note

This method is an API call. For general usage, consider channels instead.

Added in version 1.2.

Returns:

All channels in the guild.

Return type:

Sequence[discord.channel.base.GuildChannel]

Raises:
await fetch_emoji(emoji_id, /)

This function is a coroutine.

Retrieves a custom GuildEmoji from the guild.

Note

This method is an API call. For general usage, consider iterating over emojis instead.

Parameters:

emoji_id (int) – The emoji’s ID.

Returns:

The retrieved emoji.

Return type:

GuildEmoji

Raises:
  • NotFound – The emoji requested could not be found.

  • HTTPException – An error occurred fetching the emoji.

await fetch_emojis()

This function is a coroutine.

Retrieves all custom GuildEmojis from the guild.

Note

This method is an API call. For general usage, consider emojis instead.

Raises:

HTTPException – An error occurred fetching the emojis.

Returns:

The retrieved emojis.

Return type:

List[GuildEmoji]

await fetch_member(member_id, /)

This function is a coroutine.

Retrieves a Member from a guild ID, and a member ID.

Note

This method is an API call. If you have Intents.members and member cache enabled, consider get_member() instead.

Parameters:

member_id (int) – The member’s ID to fetch from.

Returns:

The member from the member ID.

Return type:

Member

Raises:
fetch_members(*, limit=1000, after=None)

Retrieves an AsyncIterator that enables receiving the guild’s members. In order to use this, Intents.members() must be enabled.

Note

This method is an API call. For general usage, consider members instead.

Added in version 1.3.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of members to retrieve. Defaults to 1000. Pass None to fetch all members. Note that this is potentially slow.

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Member – The member with the member data parsed.

Raises:
Return type:

MemberIterator

Examples

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...
await fetch_role(role_id)

This function is a coroutine.

Retrieves a Role that the guild has.

Note

This method is an API call. For general usage, consider using get_role instead.

Added in version 2.7.

Returns:

The role in the guild with the specified ID.

Return type:

Role

Raises:

HTTPException – Retrieving the role failed.

Parameters:

role_id (int)

await fetch_roles()

This function is a coroutine.

Retrieves all Role that the guild has.

Note

This method is an API call. For general usage, consider roles instead.

Added in version 1.3.

Returns:

All roles in the guild.

Return type:

List[Role]

Raises:

HTTPException – Retrieving the roles failed.

await fetch_scheduled_event(event_id, /, *, with_user_count=True)

This function is a coroutine.

Retrieves a ScheduledEvent from event ID.

Note

This method is an API call. If you have Intents.scheduled_events, consider get_scheduled_event() instead.

Parameters:
  • event_id (int) – The event’s ID to fetch with.

  • with_user_count (Optional[bool]) – If the scheduled vent should be fetched with the number of users that are interested in the event. Defaults to True.

Returns:

The scheduled event from the event ID.

Return type:

Optional[ScheduledEvent]

Raises:
await fetch_scheduled_events(*, with_user_count=True)

This function is a coroutine.

Returns a list of ScheduledEvent in the guild.

Note

This method is an API call. For general usage, consider scheduled_events instead.

Parameters:

with_user_count (Optional[bool]) – If the scheduled event should be fetched with the number of users that are interested in the events. Defaults to True.

Returns:

The fetched scheduled events.

Return type:

List[ScheduledEvent]

Raises:
await fetch_sound(sound_id)

This function is a coroutine. Fetches a soundboard sound in the guild.

Added in version 2.7.

Parameters:

sound_id (int) – The ID of the sound.

Returns:

The sound.

Return type:

SoundboardSound

await fetch_sounds()

This function is a coroutine. Fetches all the soundboard sounds in the guild.

Added in version 2.7.

Returns:

The sounds in the guild.

Return type:

List[SoundboardSound]

await fetch_sticker(sticker_id, /)

This function is a coroutine.

Retrieves a custom Sticker from the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider iterating over stickers instead.

Parameters:

sticker_id (int) – The sticker’s ID.

Returns:

The retrieved sticker.

Return type:

GuildSticker

Raises:
  • NotFound – The sticker requested could not be found.

  • HTTPException – An error occurred fetching the sticker.

await fetch_stickers()

This function is a coroutine.

Retrieves a list of all Stickers for the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider stickers instead.

Raises:

HTTPException – An error occurred fetching the stickers.

Returns:

The retrieved stickers.

Return type:

List[GuildSticker]

property filesize_limit: int

The maximum number of bytes files can have when uploaded to this guild.

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.

get_channel(channel_id, /)

Returns a channel with the given ID.

Note

This does not search for threads.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or None if not found.

Return type:

Optional[abc.GuildChannel]

get_channel_or_thread(channel_id, /)

Returns a channel or thread with the given ID.

Added in version 2.0.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or thread or None if not found.

Return type:

Optional[Union[Thread, abc.GuildChannel]]

await get_me()

Similar to Client.user except an instance of Member. This is essentially used to get the member version of yourself.

Return type:

Member

await get_member(user_id, /)

Returns a member with the given ID.

Parameters:

user_id (int) – The ID to search for.

Returns:

The member or None if not found.

Return type:

Optional[Member]

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, None is returned.

Parameters:

name (str) – The name of the member to lookup with an optional discriminator.

Returns:

The member in this guild with the associated name. If not found then None is returned.

Return type:

Optional[Member]

await get_members()

A list of members that belong to this guild.

Return type:

list[Member]

await get_owner()

The member that owns the guild.

Return type:

Member | None

get_role(role_id, /)

Returns a role with the given ID.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found.

Return type:

Optional[Role]

get_scheduled_event(event_id, /)

Returns a Scheduled Event with the given ID.

Parameters:

event_id (int) – The ID to search for.

Returns:

The scheduled event or None if not found.

Return type:

Optional[ScheduledEvent]

get_sound(sound_id)

Returns a sound with the given ID.

Added in version 2.7.

Parameters:

sound_id (int) – The ID to search for.

Returns:

The sound or None if not found.

Return type:

Optional[SoundboardSound]

get_stage_instance(stage_instance_id, /)

Returns a stage instance with the given ID.

Added in version 2.0.

Parameters:

stage_instance_id (int) – The ID to search for.

Returns:

The stage instance or None if not found.

Return type:

Optional[StageInstance]

get_thread(thread_id, /)

Returns a thread with the given ID.

Added in version 2.0.

Parameters:

thread_id (int) – The ID to search for.

Returns:

The returned thread or None if not found.

Return type:

Optional[Thread]

property icon: Asset | None

Returns the guild’s icon asset, if available.

await integrations()

This function is a coroutine.

Returns a list of all integrations attached to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Returns:

The list of integrations that are attached to the guild.

Return type:

List[Integration]

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – Fetching the integrations failed.

await invites()

This function is a coroutine.

Returns a list of all active instant invites from the guild.

You must have the manage_guild permission to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

property invites_disabled: bool

A boolean indicating whether the guild invites are disabled.

await is_chunked()

Returns a boolean indicating if the guild is “chunked”.

A chunked guild means that member_count is equal to the number of members stored in the internal members cache.

If this value returns False, then you should request for offline members.

Return type:

bool

await is_large()

Indicates if the guild is a ‘large’ guild.

A large guild is defined as having more than large_threshold count members, which for this library is set to the maximum of 250.

Return type:

bool

property jump_url: str

Returns a URL that allows the client to jump to the guild.

Added in version 2.0.

await kick(user, *, reason=None)

This function is a coroutine.

Kicks a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the kick_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to kick from their guild.

  • reason (Optional[str]) – The reason the user got kicked.

Raises:
Return type:

None

await leave()

This function is a coroutine.

Leaves the guild. :rtype: None

Note

You cannot leave the guild that you own, you must delete it instead via delete().

Raises:

HTTPException – Leaving the guild failed.

property member_count: int

Returns the true member count regardless of it being loaded fully or not.

Warning

Due to a Discord limitation, in order for this attribute to remain up-to-date and accurate, it requires Intents.members to be specified.

await modify_incident_actions(*, invites_disabled_until=Undefined.MISSING, dms_disabled_until=Undefined.MISSING, reason=Undefined.MISSING)

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_guild permission.

Parameters:
  • invites_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when invites will be enabled again, or None to enable invites immediately.

  • dms_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when DMs will be enabled again, or None to enable DMs immediately.

  • reason (Optional[str]) – The reason for this action, used for the audit log.

Returns:

The updated incidents data for the guild.

Return type:

IncidentsData

await onboarding()

This function is a coroutine.

Returns the Onboarding flow for the guild.

Added in version 2.5.

Returns:

The onboarding flow for the guild.

Return type:

Onboarding

Raises:

HTTPException – Retrieving the onboarding flow failed somehow.

property premium_subscriber_role: Role | None

Gets the premium subscriber role, AKA “boost” role, in this guild.

Added in version 1.6.

property premium_subscribers: list[Member]

A list of members who have “boosted” this guild.

await prune_members(*, days, compute_prune_count=True, roles=Undefined.MISSING, 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 days number of days and have no roles.

You must have the kick_members permission 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 roles parameter.

Changed in version 1.4: The roles keyword-only parameter was added.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

  • compute_prune_count (bool) – Whether to compute the prune count. This defaults to True which makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this to False. If this is set to False, then this function will always return None.

  • roles (List[abc.Snowflake]) – A list of abc.Snowflake that represent roles to include in the pruning process. If a member has a role that is not specified, they’ll be excluded.

Raises:
Returns:

The number of members pruned. If compute_prune_count is False then this returns None.

Return type:

Optional[int]

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.

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.

Parameters:
  • query (Optional[str]) – The string that the username’s start with.

  • user_ids (Optional[List[int]]) –

    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 (Optional[int]) – The maximum number of members to send back. If no query is passed, passing None returns all members. If a query or user_ids is passed, must be between 1 and 100. Defaults to 5.

  • presences (Optional[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 as get_member() work for those that matched. Defaults to True.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:
property roles: list[Role]

Returns a list of the guild’s roles in hierarchy order.

The first element of this list will be the lowest role in the hierarchy.

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 scheduled_events: list[ScheduledEvent]

A list of scheduled events in this guild.

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 require Intents.members().

Note

This method is an API call. For general usage, consider filtering members instead.

Added in version 2.6.

Parameters:
  • query (str) – Searches for usernames and nicknames that start with this string, case-insensitive.

  • limit (int) – The maximum number of members to retrieve, up to 1000.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:

HTTPException – Getting the members failed.

property self_role: Role | None

Gets the role associated with this client’s user, if any.

Added in version 1.6.

await set_mfa_required(required, *, reason=None)

This function is a coroutine.

Set whether it is required to have MFA enabled on your account to perform moderation actions. You must be the guild owner to do this.

Parameters:
  • required (bool) – Whether MFA should be required to perform moderation actions.

  • reason (str) – The reason to show up in the audit log.

Raises:
Return type:

None

property shard_id: int

Returns the shard ID for this guild if applicable.

property soundboard_limit: int

The maximum number of soundboard slots this guild has.

Added in version 2.7.

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.

property splash: Asset | None

Returns the guild’s invite splash asset, if available.

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 stage_instances: list[StageInstance]

Returns a list of the guild’s stage instances that are currently running.

Added in version 2.0.

property sticker_limit: int

The maximum number of sticker slots this guild has.

Added in version 2.0.

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.

await templates()

This function is a coroutine.

Gets the list of templates from this guild.

Requires manage_guild permissions.

Added in version 1.7.

Returns:

The templates for this guild.

Return type:

List[Template]

Raises:

Forbidden – You don’t have permissions to get the templates.

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 threads: list[Thread]

A list of threads that you have permission to view.

Added in version 2.0.

await unban(user, *, reason=None)

This function is a coroutine.

Unbans a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to unban.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
Return type:

None

await vanity_invite()

This function is a coroutine.

Returns the guild’s special vanity invite.

The guild must have VANITY_URL in features.

You must have the manage_guild permission to use this as well.

Returns:

The special vanity invite. If None then the guild does not have a vanity invite set.

Return type:

Optional[Invite]

Raises:
  • Forbidden – You do not have the proper permissions to get this.

  • HTTPException – Retrieving the vanity invite failed.

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 voice_client: VoiceClient | None

Returns the VoiceClient associated with this guild, if any.

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this guild.

Requires manage_webhooks permissions.

Returns:

The webhooks for this guild.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

await welcome_screen()

This function is a coroutine.

Returns the WelcomeScreen of the guild.

The guild must have COMMUNITY in features.

You must have the manage_guild permission in order to get this.

Added in version 2.0.

Returns:

The welcome screen of guild.

Return type:

WelcomeScreen

Raises:
  • 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 widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Returns:

The guild’s widget.

Return type:

Widget

Raises:
class discord.events.GuildUpdate[source]

Called when a guild is updated.

Examples of when this is called: - Changed name - Changed AFK channel - Changed AFK timeout - etc.

This requires Intents.guilds to be enabled.

This event inherits from Guild.

old

The guild prior to being updated.

Type:

Guild

await active_threads()

This function is a coroutine.

Returns a list of active Thread that the client can access.

This includes both private and public threads.

Added in version 2.0.

Returns:

The active threads

Return type:

List[Thread]

Raises:

HTTPException – The request to get the active threads failed.

await audit_logs(*, limit=100, before=None, after=None, user=None, action=None)

Returns an AsyncIterator that enables receiving the guild’s audit logs.

You must have the view_audit_log permission to use this.

See API documentation for more information about the before and after parameters.

Parameters:
  • limit (Optional[int]) – The number of entries to retrieve. If None retrieve all entries.

  • before (Union[abc.Snowflake, datetime.datetime]) – 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 (Union[abc.Snowflake, datetime.datetime]) – 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 (abc.Snowflake) – The moderator to filter entries from.

  • action (AuditLogAction) – The action to filter with.

Yields:

AuditLogEntry – The audit log entry.

Raises:
  • Forbidden – You are not allowed to fetch audit logs

  • HTTPException – An error occurred while fetching the audit logs.

Return type:

AuditLogIterator

Examples

Getting the first 100 entries:

async for entry in guild.audit_logs(limit=100):
    print(f"{entry.user} did {entry.action} to {await entry.get_target()}")

Getting entries for a specific action:

async for entry in guild.audit_logs(action=discord.AuditLogAction.ban):
    print(f"{entry.user} banned {await entry.get_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 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.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to ban from their guild.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the user got banned.

Raises:
Return type:

None

property banner: Asset | None

Returns the guild’s banner asset, if available.

bans(limit=None, before=None, after=None)

This function is a coroutine.

Retrieves an AsyncIterator that enables receiving the guild’s bans. In order to use this, you must have the ban_members permission. Users will always be returned in ascending order sorted by user ID. If both the before and after parameters are provided, only before is respected.

Changed in version 2.5: The before. and after parameters were changed. They are now of the type abc.Snowflake instead of SnowflakeTime to comply with the discord api.

Changed in version 2.0: The limit, before. and after parameters were added. Now returns a BanIterator instead of a list of BanEntry objects.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of bans to retrieve. Defaults to 1000.

  • before (Optional[abc.Snowflake]) – Retrieve bans before the given user.

  • after (Optional[abc.Snowflake]) – Retrieve bans after the given user.

Yields:

BanEntry – The ban entry for the ban.

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

Return type:

BanIterator

Examples

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...
property bitrate_limit: int

The maximum bitrate for voice channels this guild can have.

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.Snowflake abc.

You must have the ban_members permission 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)
Parameters:
  • *users (abc.Snowflake) – An argument list of users to ban from the guild, up to 200.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the users were banned.

Returns:

Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.

Return type:

Tuple[List[abc.Snowflake], List[abc.Snowflake]]

Raises:
by_category()

Returns every CategoryChannel and 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.

Returns:

The categories and their associated channels.

Return type:

List[Tuple[Optional[CategoryChannel], List[abc.GuildChannel]]]

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.

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.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – Channel the client wants to join. Use None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

property channels: list[GuildChannel]

A list of channels that belong to this guild.

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.

Parameters:

cache (bool) – Whether to cache the members as well.

Raises:

ClientException – The members intent is not enabled.

Return type:

None

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.

Parameters:
  • 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[abc.Snowflake]) – A list of roles that are exempt from the rule.

  • exempt_channels (List[abc.Snowflake]) – A list of channels that are exempt from the rule.

  • reason (Optional[str]) – The reason for creating the rule. Shows up in the audit log.

Returns:

The new auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Creating the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

await create_category(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_category_channel(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_custom_emoji(*, name, image, roles=Undefined.MISSING, reason=None)

This function is a coroutine.

Creates a custom GuildEmoji for the guild.

There is currently a limit of 50 static and animated emojis respectively per guild, unless the guild has the MORE_EMOJI feature which extends the limit to 200.

You must have the manage_emojis permission to do this.

Parameters:
  • 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]) – A list of Roles that can use this emoji. Leave empty to make it available to everyone.

  • reason (Optional[str]) – The reason for creating this emoji. Shows up on the audit log.

Raises:
Returns:

The created emoji.

Return type:

GuildEmoji

await create_forum_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_reaction_emoji=Undefined.MISSING, available_tags=Undefined.MISSING, default_sort_order=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a ForumChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_reaction_emoji (Optional[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 (Optional[SortOrder]) –

    The default sort order type used to order posts in this channel.

    Added in version 2.7.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

ForumChannel

Raises:

Examples

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_integration(*, type, id)

This function is a coroutine.

Attaches an integration to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Parameters:
  • type (str) – The integration type (e.g. Twitch).

  • id (int) – The integration ID.

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – The account could not be found.

Return type:

None

await create_role(*, name=Undefined.MISSING, permissions=Undefined.MISSING, color=Undefined.MISSING, colour=Undefined.MISSING, colors=Undefined.MISSING, colours=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, reason=None, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Creates a Role for the guild.

All fields are optional.

You must have the manage_roles permission to do this.

Changed in version 1.6: Can now pass int to colour keyword-only parameter.

Parameters:
  • name (str) – The role name. Defaults to ‘new role’.

  • permissions (Permissions) – The permissions to have. Defaults to no permissions.

  • colour (Union[Colour, int]) – The colour for the role. Defaults to Colour.default(). This is aliased to color as well.

  • hoist (bool) – Indicates if the role should be shown separately in the member list. Defaults to False.

  • mentionable (bool) – Indicates if the role should be mentionable by others. Defaults to False.

  • reason (Optional[str]) – The reason for creating this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • color (Colour | int | utils.Undefined)

  • colors (RoleColours | utils.Undefined)

  • colours (RoleColours | utils.Undefined)

  • holographic (bool | utils.Undefined)

Returns:

The newly created role.

Return type:

Role

Raises:
await create_scheduled_event(*, name, description=Undefined.MISSING, start_time, end_time=Undefined.MISSING, location, privacy_level=ScheduledEventPrivacyLevel.guild_only, reason=None, image=Undefined.MISSING)

This function is a coroutine. Creates a scheduled event.

Parameters:
  • name (str) – The name of the scheduled event.

  • description (Optional[str]) – The description of the scheduled event.

  • start_time (datetime.datetime) – A datetime object of when the scheduled event is supposed to start.

  • end_time (Optional[datetime.datetime]) – A datetime object of when the scheduled event is supposed to end.

  • location (ScheduledEventLocation) – The location of where the event is happening.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event

Returns:

The created scheduled event.

Return type:

Optional[ScheduledEvent]

Raises:
await create_sound(name, sound, volume=1.0, emoji=None, reason=None)

This function is a coroutine. Creates a SoundboardSound in the guild. You must have Permissions.manage_expressions permission to use this.

Added in version 2.7.

Parameters:
  • 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 (Optional[Union[PartialEmoji, GuildEmoji, str]]) – The emoji of the sound.

  • reason (Optional[str]) – The reason for creating this sound. Shows up on the audit log.

Returns:

The created sound.

Return type:

SoundboardSound

Raises:
await create_stage_channel(name, *, topic, position=Undefined.MISSING, overwrites=Undefined.MISSING, category=None, reason=None, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a StageChannel instead.

Added in version 1.7.

Parameters:
  • name (str) – The channel’s name.

  • topic (str) – The new channel’s topic.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

StageChannel

Raises:
  • 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_sticker(*, name, description=None, emoji, file, reason=None)

This function is a coroutine.

Creates a Sticker for the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • name (str) – The sticker name. Must be 2 to 30 characters.

  • description (Optional[str]) – 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) – The reason for creating this sticker. Shows up on the audit log.

Returns:

The created sticker.

Return type:

GuildSticker

Raises:
  • 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 create_template(*, name, description=Undefined.MISSING)

This function is a coroutine.

Creates a template for the guild.

You must have the manage_guild permission to do this.

Added in version 1.7.

Parameters:
  • name (str) – The name of the template.

  • description (str) – The description of the template.

Return type:

Template

await create_test_entitlement(sku)

This function is a coroutine.

Creates a test entitlement for the guild.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

await create_text_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a TextChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

TextChannel

Raises:
  • 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.

Examples

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=Undefined.MISSING, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, overwrites=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a VoiceChannel instead.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 (Optional[str]) – 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

VoiceChannel

Raises:
  • 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.

property created_at: datetime

Returns the guild’s creation time in UTC.

property default_role: Role

Gets the @everyone role that all members have by default.

await delete()

This function is a coroutine.

Deletes the guild. You must be the guild owner to delete the guild.

Raises:
Return type:

None

await delete_auto_moderation_rule(id, *, reason=None)

Deletes an auto moderation rule.

Parameters:
  • id (int) – The ID of the auto moderation rule.

  • reason (Optional[str]) – The reason for deleting the rule. Shows up in the audit log.

Raises:
  • HTTPException – Deleting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Return type:

None

await delete_emoji(emoji, *, reason=None)

This function is a coroutine.

Deletes the custom GuildEmoji from the guild.

You must have manage_emojis permission to do this.

Parameters:
  • emoji (abc.Snowflake) – The emoji you are deleting.

  • reason (Optional[str]) – The reason for deleting this emoji. Shows up on the audit log.

Raises:
Return type:

None

await delete_sticker(sticker, *, reason=None)

This function is a coroutine.

Deletes the custom Sticker from the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • sticker (abc.Snowflake) – The sticker you are deleting.

  • reason (Optional[str]) – The reason for deleting this sticker. Shows up on the audit log.

Raises:
  • Forbidden – You are not allowed to delete stickers.

  • HTTPException – An error occurred deleting the sticker.

Return type:

None

property discovery_splash: Asset | None

Returns the guild’s discovery splash asset, if available.

await edit(*, reason=Undefined.MISSING, name=Undefined.MISSING, description=Undefined.MISSING, icon=Undefined.MISSING, banner=Undefined.MISSING, splash=Undefined.MISSING, discovery_splash=Undefined.MISSING, community=Undefined.MISSING, afk_channel=Undefined.MISSING, owner=Undefined.MISSING, afk_timeout=Undefined.MISSING, default_notifications=Undefined.MISSING, verification_level=Undefined.MISSING, explicit_content_filter=Undefined.MISSING, system_channel=Undefined.MISSING, system_channel_flags=Undefined.MISSING, preferred_locale=Undefined.MISSING, rules_channel=Undefined.MISSING, public_updates_channel=Undefined.MISSING, premium_progress_bar_enabled=Undefined.MISSING, disable_invites=Undefined.MISSING, discoverable=Undefined.MISSING, disable_raid_alerts=Undefined.MISSING, enable_activity_feed=Undefined.MISSING)

This function is a coroutine.

Edits the guild.

You must have the manage_guild permission to edit the guild.

Changed in version 1.4: The rules_channel and public_updates_channel keyword-only parameters were added.

Changed in version 2.0: The discovery_splash and community keyword-only parameters were added.

Changed in version 2.0: The newly updated guild is returned.

Parameters:
  • name (str) – The new name of the guild.

  • description (Optional[str]) – The new description of the guild. Could be None for no description. This is only available to guilds that contain PUBLIC in Guild.features.

  • icon (bytes) – A bytes-like object representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that contain ANIMATED_ICON in Guild.features. Could be None to denote removal of the icon.

  • banner (bytes) – A bytes-like object representing the banner. Could be None to denote removal of the banner. This is only available to guilds that contain BANNER in Guild.features.

  • splash (bytes) – A bytes-like object representing the invite splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain INVITE_SPLASH in Guild.features.

  • discovery_splash (bytes) – A bytes-like object representing the discovery splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain DISCOVERABLE in Guild.features.

  • community (bool) – Whether the guild should be a Community guild. If set to True, both rules_channel and public_updates_channel parameters are required.

  • afk_channel (Optional[VoiceChannel]) – The new channel that is the AFK channel. Could be None for no AFK channel.

  • afk_timeout (int) – The number of seconds until someone is moved to the AFK channel.

  • owner (Member) – The new owner of the guild to transfer ownership to. Note that you must be owner of the guild to do this.

  • 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 (Optional[TextChannel]) – The new channel that is used for the system channel. Could be None for 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-US or ja or zh-CN.

  • rules_channel (Optional[TextChannel]) – The new channel that is used for rules. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for no rules channel.

  • public_updates_channel (Optional[TextChannel]) – The new channel that is used for public updates from Discord. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for 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 (class:bool) – Whether the guild’s user activity feed should be enabled.

  • reason (Optional[str]) – The reason for editing this guild. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to edit the guild.

  • HTTPException – Editing the guild failed.

  • InvalidArgument – The image format passed in to icon is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the guild and request an ownership transfer.

Returns:

The newly updated guild. Note that this has the same limitations as mentioned in Client.fetch_guild() and may not have full data.

Return type:

Guild

await edit_onboarding(*, prompts=Undefined.MISSING, default_channels=Undefined.MISSING, enabled=Undefined.MISSING, mode=Undefined.MISSING, reason=Undefined.MISSING)

This function is a coroutine.

A shorthand for Onboarding.edit without fetching the onboarding flow.

You must have the manage_guild and manage_roles permissions in the guild to do this.

Parameters:
  • prompts (Optional[List[OnboardingPrompt]]) – The new list of prompts for this flow.

  • default_channels (Optional[List[Snowflake]]) – The new default channels that users are opted into.

  • enabled (Optional[bool]) – Whether onboarding should be enabled. Setting this to True requires the guild to have COMMUNITY in features and at least 7 default_channels.

  • mode (Optional[OnboardingMode]) – The new onboarding mode.

  • reason (Optional[str]) – The reason that shows up on Audit log.

Returns:

The updated onboarding flow.

Return type:

Onboarding

Raises:
  • HTTPException – Editing the onboarding flow failed somehow.

  • Forbidden – You don’t have permissions to edit the onboarding flow.

await edit_role_positions(positions, *, reason=None)

This function is a coroutine.

Bulk edits a list of Role in the guild.

You must have the manage_roles permission 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)
Parameters:
  • positions (Dict[Role, int]) – A dict of Role to int to change the positions of each given role.

  • reason (Optional[str]) – The reason for editing the role positions. Shows up on the audit log.

Returns:

A list of all the roles in the guild.

Return type:

List[Role]

Raises:
await edit_welcome_screen(**options)

This function is a coroutine.

A shorthand for WelcomeScreen.edit without fetching the welcome screen.

You must have the manage_guild permission in the guild to do this.

The guild must have COMMUNITY in Guild.features

Parameters:
  • 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.

Returns:

The edited welcome screen.

Return type:

WelcomeScreen

Raises:
  • 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 edit_widget(*, enabled=Undefined.MISSING, channel=Undefined.MISSING)

This function is a coroutine.

Edits the widget of the guild.

You must have the manage_guild permission to use this

Added in version 2.0.

Parameters:
  • enabled (bool) – Whether to enable the widget for the guild.

  • channel (Optional[Snowflake]) – The new widget channel. None removes the widget channel.

Raises:
Return type:

None

property emoji_limit: int

The maximum number of emoji slots this guild has.

entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)

Returns an AsyncIterator that enables fetching the guild’s entitlements.

This is identical to Client.entitlements() with the guild parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

Return type:

EntitlementIterator

await estimate_pruned_members(*, days, roles=Undefined.MISSING)

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.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • roles (List[abc.Snowflake]) –

    A list of abc.Snowflake that 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.

Returns:

The number of members estimated to be pruned.

Return type:

int

Raises:
  • 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 fetch_auto_moderation_rule(id)

This function is a coroutine.

Retrieves a AutoModRule from rule ID.

Returns:

The requested auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Getting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Parameters:

id (int)

await fetch_auto_moderation_rules()

This function is a coroutine.

Retrieves a list of auto moderation rules for this guild.

Returns:

The auto moderation rules for this guild.

Return type:

List[AutoModRule]

Raises:
  • HTTPException – Getting the auto moderation rules failed.

  • Forbidden – You do not have the Manage Guild permission.

await fetch_ban(user)

This function is a coroutine.

Retrieves the BanEntry for a user.

You must have the ban_members permission to get this information.

Parameters:

user (abc.Snowflake) – The user to get ban information from.

Returns:

The BanEntry object for the specified user.

Return type:

BanEntry

Raises:
  • 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.GuildChannel or Thread with the specified ID.

Note

This method is an API call. For general usage, consider get_channel_or_thread() instead.

Added in version 2.0.

Returns:

The channel from the ID.

Return type:

Union[abc.GuildChannel, Thread]

Raises:
  • 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.

Parameters:

channel_id (int)

await fetch_channels()

This function is a coroutine.

Retrieves all abc.GuildChannel that the guild has.

Note

This method is an API call. For general usage, consider channels instead.

Added in version 1.2.

Returns:

All channels in the guild.

Return type:

Sequence[discord.channel.base.GuildChannel]

Raises:
await fetch_emoji(emoji_id, /)

This function is a coroutine.

Retrieves a custom GuildEmoji from the guild.

Note

This method is an API call. For general usage, consider iterating over emojis instead.

Parameters:

emoji_id (int) – The emoji’s ID.

Returns:

The retrieved emoji.

Return type:

GuildEmoji

Raises:
  • NotFound – The emoji requested could not be found.

  • HTTPException – An error occurred fetching the emoji.

await fetch_emojis()

This function is a coroutine.

Retrieves all custom GuildEmojis from the guild.

Note

This method is an API call. For general usage, consider emojis instead.

Raises:

HTTPException – An error occurred fetching the emojis.

Returns:

The retrieved emojis.

Return type:

List[GuildEmoji]

await fetch_member(member_id, /)

This function is a coroutine.

Retrieves a Member from a guild ID, and a member ID.

Note

This method is an API call. If you have Intents.members and member cache enabled, consider get_member() instead.

Parameters:

member_id (int) – The member’s ID to fetch from.

Returns:

The member from the member ID.

Return type:

Member

Raises:
fetch_members(*, limit=1000, after=None)

Retrieves an AsyncIterator that enables receiving the guild’s members. In order to use this, Intents.members() must be enabled.

Note

This method is an API call. For general usage, consider members instead.

Added in version 1.3.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of members to retrieve. Defaults to 1000. Pass None to fetch all members. Note that this is potentially slow.

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Member – The member with the member data parsed.

Raises:
Return type:

MemberIterator

Examples

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...
await fetch_role(role_id)

This function is a coroutine.

Retrieves a Role that the guild has.

Note

This method is an API call. For general usage, consider using get_role instead.

Added in version 2.7.

Returns:

The role in the guild with the specified ID.

Return type:

Role

Raises:

HTTPException – Retrieving the role failed.

Parameters:

role_id (int)

await fetch_roles()

This function is a coroutine.

Retrieves all Role that the guild has.

Note

This method is an API call. For general usage, consider roles instead.

Added in version 1.3.

Returns:

All roles in the guild.

Return type:

List[Role]

Raises:

HTTPException – Retrieving the roles failed.

await fetch_scheduled_event(event_id, /, *, with_user_count=True)

This function is a coroutine.

Retrieves a ScheduledEvent from event ID.

Note

This method is an API call. If you have Intents.scheduled_events, consider get_scheduled_event() instead.

Parameters:
  • event_id (int) – The event’s ID to fetch with.

  • with_user_count (Optional[bool]) – If the scheduled vent should be fetched with the number of users that are interested in the event. Defaults to True.

Returns:

The scheduled event from the event ID.

Return type:

Optional[ScheduledEvent]

Raises:
await fetch_scheduled_events(*, with_user_count=True)

This function is a coroutine.

Returns a list of ScheduledEvent in the guild.

Note

This method is an API call. For general usage, consider scheduled_events instead.

Parameters:

with_user_count (Optional[bool]) – If the scheduled event should be fetched with the number of users that are interested in the events. Defaults to True.

Returns:

The fetched scheduled events.

Return type:

List[ScheduledEvent]

Raises:
await fetch_sound(sound_id)

This function is a coroutine. Fetches a soundboard sound in the guild.

Added in version 2.7.

Parameters:

sound_id (int) – The ID of the sound.

Returns:

The sound.

Return type:

SoundboardSound

await fetch_sounds()

This function is a coroutine. Fetches all the soundboard sounds in the guild.

Added in version 2.7.

Returns:

The sounds in the guild.

Return type:

List[SoundboardSound]

await fetch_sticker(sticker_id, /)

This function is a coroutine.

Retrieves a custom Sticker from the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider iterating over stickers instead.

Parameters:

sticker_id (int) – The sticker’s ID.

Returns:

The retrieved sticker.

Return type:

GuildSticker

Raises:
  • NotFound – The sticker requested could not be found.

  • HTTPException – An error occurred fetching the sticker.

await fetch_stickers()

This function is a coroutine.

Retrieves a list of all Stickers for the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider stickers instead.

Raises:

HTTPException – An error occurred fetching the stickers.

Returns:

The retrieved stickers.

Return type:

List[GuildSticker]

property filesize_limit: int

The maximum number of bytes files can have when uploaded to this guild.

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.

get_channel(channel_id, /)

Returns a channel with the given ID.

Note

This does not search for threads.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or None if not found.

Return type:

Optional[abc.GuildChannel]

get_channel_or_thread(channel_id, /)

Returns a channel or thread with the given ID.

Added in version 2.0.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or thread or None if not found.

Return type:

Optional[Union[Thread, abc.GuildChannel]]

await get_me()

Similar to Client.user except an instance of Member. This is essentially used to get the member version of yourself.

Return type:

Member

await get_member(user_id, /)

Returns a member with the given ID.

Parameters:

user_id (int) – The ID to search for.

Returns:

The member or None if not found.

Return type:

Optional[Member]

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, None is returned.

Parameters:

name (str) – The name of the member to lookup with an optional discriminator.

Returns:

The member in this guild with the associated name. If not found then None is returned.

Return type:

Optional[Member]

await get_members()

A list of members that belong to this guild.

Return type:

list[Member]

await get_owner()

The member that owns the guild.

Return type:

Member | None

get_role(role_id, /)

Returns a role with the given ID.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found.

Return type:

Optional[Role]

get_scheduled_event(event_id, /)

Returns a Scheduled Event with the given ID.

Parameters:

event_id (int) – The ID to search for.

Returns:

The scheduled event or None if not found.

Return type:

Optional[ScheduledEvent]

get_sound(sound_id)

Returns a sound with the given ID.

Added in version 2.7.

Parameters:

sound_id (int) – The ID to search for.

Returns:

The sound or None if not found.

Return type:

Optional[SoundboardSound]

get_stage_instance(stage_instance_id, /)

Returns a stage instance with the given ID.

Added in version 2.0.

Parameters:

stage_instance_id (int) – The ID to search for.

Returns:

The stage instance or None if not found.

Return type:

Optional[StageInstance]

get_thread(thread_id, /)

Returns a thread with the given ID.

Added in version 2.0.

Parameters:

thread_id (int) – The ID to search for.

Returns:

The returned thread or None if not found.

Return type:

Optional[Thread]

property icon: Asset | None

Returns the guild’s icon asset, if available.

await integrations()

This function is a coroutine.

Returns a list of all integrations attached to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Returns:

The list of integrations that are attached to the guild.

Return type:

List[Integration]

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – Fetching the integrations failed.

await invites()

This function is a coroutine.

Returns a list of all active instant invites from the guild.

You must have the manage_guild permission to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

property invites_disabled: bool

A boolean indicating whether the guild invites are disabled.

await is_chunked()

Returns a boolean indicating if the guild is “chunked”.

A chunked guild means that member_count is equal to the number of members stored in the internal members cache.

If this value returns False, then you should request for offline members.

Return type:

bool

await is_large()

Indicates if the guild is a ‘large’ guild.

A large guild is defined as having more than large_threshold count members, which for this library is set to the maximum of 250.

Return type:

bool

property jump_url: str

Returns a URL that allows the client to jump to the guild.

Added in version 2.0.

await kick(user, *, reason=None)

This function is a coroutine.

Kicks a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the kick_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to kick from their guild.

  • reason (Optional[str]) – The reason the user got kicked.

Raises:
Return type:

None

await leave()

This function is a coroutine.

Leaves the guild. :rtype: None

Note

You cannot leave the guild that you own, you must delete it instead via delete().

Raises:

HTTPException – Leaving the guild failed.

property member_count: int

Returns the true member count regardless of it being loaded fully or not.

Warning

Due to a Discord limitation, in order for this attribute to remain up-to-date and accurate, it requires Intents.members to be specified.

await modify_incident_actions(*, invites_disabled_until=Undefined.MISSING, dms_disabled_until=Undefined.MISSING, reason=Undefined.MISSING)

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_guild permission.

Parameters:
  • invites_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when invites will be enabled again, or None to enable invites immediately.

  • dms_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when DMs will be enabled again, or None to enable DMs immediately.

  • reason (Optional[str]) – The reason for this action, used for the audit log.

Returns:

The updated incidents data for the guild.

Return type:

IncidentsData

await onboarding()

This function is a coroutine.

Returns the Onboarding flow for the guild.

Added in version 2.5.

Returns:

The onboarding flow for the guild.

Return type:

Onboarding

Raises:

HTTPException – Retrieving the onboarding flow failed somehow.

property premium_subscriber_role: Role | None

Gets the premium subscriber role, AKA “boost” role, in this guild.

Added in version 1.6.

property premium_subscribers: list[Member]

A list of members who have “boosted” this guild.

await prune_members(*, days, compute_prune_count=True, roles=Undefined.MISSING, 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 days number of days and have no roles.

You must have the kick_members permission 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 roles parameter.

Changed in version 1.4: The roles keyword-only parameter was added.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

  • compute_prune_count (bool) – Whether to compute the prune count. This defaults to True which makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this to False. If this is set to False, then this function will always return None.

  • roles (List[abc.Snowflake]) – A list of abc.Snowflake that represent roles to include in the pruning process. If a member has a role that is not specified, they’ll be excluded.

Raises:
Returns:

The number of members pruned. If compute_prune_count is False then this returns None.

Return type:

Optional[int]

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.

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.

Parameters:
  • query (Optional[str]) – The string that the username’s start with.

  • user_ids (Optional[List[int]]) –

    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 (Optional[int]) – The maximum number of members to send back. If no query is passed, passing None returns all members. If a query or user_ids is passed, must be between 1 and 100. Defaults to 5.

  • presences (Optional[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 as get_member() work for those that matched. Defaults to True.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:
property roles: list[Role]

Returns a list of the guild’s roles in hierarchy order.

The first element of this list will be the lowest role in the hierarchy.

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 scheduled_events: list[ScheduledEvent]

A list of scheduled events in this guild.

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 require Intents.members().

Note

This method is an API call. For general usage, consider filtering members instead.

Added in version 2.6.

Parameters:
  • query (str) – Searches for usernames and nicknames that start with this string, case-insensitive.

  • limit (int) – The maximum number of members to retrieve, up to 1000.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:

HTTPException – Getting the members failed.

property self_role: Role | None

Gets the role associated with this client’s user, if any.

Added in version 1.6.

await set_mfa_required(required, *, reason=None)

This function is a coroutine.

Set whether it is required to have MFA enabled on your account to perform moderation actions. You must be the guild owner to do this.

Parameters:
  • required (bool) – Whether MFA should be required to perform moderation actions.

  • reason (str) – The reason to show up in the audit log.

Raises:
Return type:

None

property shard_id: int

Returns the shard ID for this guild if applicable.

property soundboard_limit: int

The maximum number of soundboard slots this guild has.

Added in version 2.7.

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.

property splash: Asset | None

Returns the guild’s invite splash asset, if available.

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 stage_instances: list[StageInstance]

Returns a list of the guild’s stage instances that are currently running.

Added in version 2.0.

property sticker_limit: int

The maximum number of sticker slots this guild has.

Added in version 2.0.

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.

await templates()

This function is a coroutine.

Gets the list of templates from this guild.

Requires manage_guild permissions.

Added in version 1.7.

Returns:

The templates for this guild.

Return type:

List[Template]

Raises:

Forbidden – You don’t have permissions to get the templates.

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 threads: list[Thread]

A list of threads that you have permission to view.

Added in version 2.0.

await unban(user, *, reason=None)

This function is a coroutine.

Unbans a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to unban.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
Return type:

None

await vanity_invite()

This function is a coroutine.

Returns the guild’s special vanity invite.

The guild must have VANITY_URL in features.

You must have the manage_guild permission to use this as well.

Returns:

The special vanity invite. If None then the guild does not have a vanity invite set.

Return type:

Optional[Invite]

Raises:
  • Forbidden – You do not have the proper permissions to get this.

  • HTTPException – Retrieving the vanity invite failed.

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 voice_client: VoiceClient | None

Returns the VoiceClient associated with this guild, if any.

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this guild.

Requires manage_webhooks permissions.

Returns:

The webhooks for this guild.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

await welcome_screen()

This function is a coroutine.

Returns the WelcomeScreen of the guild.

The guild must have COMMUNITY in features.

You must have the manage_guild permission in order to get this.

Added in version 2.0.

Returns:

The welcome screen of guild.

Return type:

WelcomeScreen

Raises:
  • 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 widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Returns:

The guild’s widget.

Return type:

Widget

Raises:
class discord.events.GuildAvailable[source]

Called when a guild becomes available.

The guild must have existed in the client’s cache. This requires Intents.guilds to be enabled.

This event inherits from Guild.

await active_threads()

This function is a coroutine.

Returns a list of active Thread that the client can access.

This includes both private and public threads.

Added in version 2.0.

Returns:

The active threads

Return type:

List[Thread]

Raises:

HTTPException – The request to get the active threads failed.

await audit_logs(*, limit=100, before=None, after=None, user=None, action=None)

Returns an AsyncIterator that enables receiving the guild’s audit logs.

You must have the view_audit_log permission to use this.

See API documentation for more information about the before and after parameters.

Parameters:
  • limit (Optional[int]) – The number of entries to retrieve. If None retrieve all entries.

  • before (Union[abc.Snowflake, datetime.datetime]) – 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 (Union[abc.Snowflake, datetime.datetime]) – 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 (abc.Snowflake) – The moderator to filter entries from.

  • action (AuditLogAction) – The action to filter with.

Yields:

AuditLogEntry – The audit log entry.

Raises:
  • Forbidden – You are not allowed to fetch audit logs

  • HTTPException – An error occurred while fetching the audit logs.

Return type:

AuditLogIterator

Examples

Getting the first 100 entries:

async for entry in guild.audit_logs(limit=100):
    print(f"{entry.user} did {entry.action} to {await entry.get_target()}")

Getting entries for a specific action:

async for entry in guild.audit_logs(action=discord.AuditLogAction.ban):
    print(f"{entry.user} banned {await entry.get_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 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.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to ban from their guild.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the user got banned.

Raises:
Return type:

None

property banner: Asset | None

Returns the guild’s banner asset, if available.

bans(limit=None, before=None, after=None)

This function is a coroutine.

Retrieves an AsyncIterator that enables receiving the guild’s bans. In order to use this, you must have the ban_members permission. Users will always be returned in ascending order sorted by user ID. If both the before and after parameters are provided, only before is respected.

Changed in version 2.5: The before. and after parameters were changed. They are now of the type abc.Snowflake instead of SnowflakeTime to comply with the discord api.

Changed in version 2.0: The limit, before. and after parameters were added. Now returns a BanIterator instead of a list of BanEntry objects.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of bans to retrieve. Defaults to 1000.

  • before (Optional[abc.Snowflake]) – Retrieve bans before the given user.

  • after (Optional[abc.Snowflake]) – Retrieve bans after the given user.

Yields:

BanEntry – The ban entry for the ban.

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

Return type:

BanIterator

Examples

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...
property bitrate_limit: int

The maximum bitrate for voice channels this guild can have.

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.Snowflake abc.

You must have the ban_members permission 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)
Parameters:
  • *users (abc.Snowflake) – An argument list of users to ban from the guild, up to 200.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the users were banned.

Returns:

Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.

Return type:

Tuple[List[abc.Snowflake], List[abc.Snowflake]]

Raises:
by_category()

Returns every CategoryChannel and 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.

Returns:

The categories and their associated channels.

Return type:

List[Tuple[Optional[CategoryChannel], List[abc.GuildChannel]]]

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.

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.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – Channel the client wants to join. Use None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

property channels: list[GuildChannel]

A list of channels that belong to this guild.

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.

Parameters:

cache (bool) – Whether to cache the members as well.

Raises:

ClientException – The members intent is not enabled.

Return type:

None

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.

Parameters:
  • 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[abc.Snowflake]) – A list of roles that are exempt from the rule.

  • exempt_channels (List[abc.Snowflake]) – A list of channels that are exempt from the rule.

  • reason (Optional[str]) – The reason for creating the rule. Shows up in the audit log.

Returns:

The new auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Creating the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

await create_category(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_category_channel(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_custom_emoji(*, name, image, roles=Undefined.MISSING, reason=None)

This function is a coroutine.

Creates a custom GuildEmoji for the guild.

There is currently a limit of 50 static and animated emojis respectively per guild, unless the guild has the MORE_EMOJI feature which extends the limit to 200.

You must have the manage_emojis permission to do this.

Parameters:
  • 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]) – A list of Roles that can use this emoji. Leave empty to make it available to everyone.

  • reason (Optional[str]) – The reason for creating this emoji. Shows up on the audit log.

Raises:
Returns:

The created emoji.

Return type:

GuildEmoji

await create_forum_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_reaction_emoji=Undefined.MISSING, available_tags=Undefined.MISSING, default_sort_order=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a ForumChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_reaction_emoji (Optional[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 (Optional[SortOrder]) –

    The default sort order type used to order posts in this channel.

    Added in version 2.7.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

ForumChannel

Raises:

Examples

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_integration(*, type, id)

This function is a coroutine.

Attaches an integration to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Parameters:
  • type (str) – The integration type (e.g. Twitch).

  • id (int) – The integration ID.

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – The account could not be found.

Return type:

None

await create_role(*, name=Undefined.MISSING, permissions=Undefined.MISSING, color=Undefined.MISSING, colour=Undefined.MISSING, colors=Undefined.MISSING, colours=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, reason=None, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Creates a Role for the guild.

All fields are optional.

You must have the manage_roles permission to do this.

Changed in version 1.6: Can now pass int to colour keyword-only parameter.

Parameters:
  • name (str) – The role name. Defaults to ‘new role’.

  • permissions (Permissions) – The permissions to have. Defaults to no permissions.

  • colour (Union[Colour, int]) – The colour for the role. Defaults to Colour.default(). This is aliased to color as well.

  • hoist (bool) – Indicates if the role should be shown separately in the member list. Defaults to False.

  • mentionable (bool) – Indicates if the role should be mentionable by others. Defaults to False.

  • reason (Optional[str]) – The reason for creating this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • color (Colour | int | utils.Undefined)

  • colors (RoleColours | utils.Undefined)

  • colours (RoleColours | utils.Undefined)

  • holographic (bool | utils.Undefined)

Returns:

The newly created role.

Return type:

Role

Raises:
await create_scheduled_event(*, name, description=Undefined.MISSING, start_time, end_time=Undefined.MISSING, location, privacy_level=ScheduledEventPrivacyLevel.guild_only, reason=None, image=Undefined.MISSING)

This function is a coroutine. Creates a scheduled event.

Parameters:
  • name (str) – The name of the scheduled event.

  • description (Optional[str]) – The description of the scheduled event.

  • start_time (datetime.datetime) – A datetime object of when the scheduled event is supposed to start.

  • end_time (Optional[datetime.datetime]) – A datetime object of when the scheduled event is supposed to end.

  • location (ScheduledEventLocation) – The location of where the event is happening.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event

Returns:

The created scheduled event.

Return type:

Optional[ScheduledEvent]

Raises:
await create_sound(name, sound, volume=1.0, emoji=None, reason=None)

This function is a coroutine. Creates a SoundboardSound in the guild. You must have Permissions.manage_expressions permission to use this.

Added in version 2.7.

Parameters:
  • 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 (Optional[Union[PartialEmoji, GuildEmoji, str]]) – The emoji of the sound.

  • reason (Optional[str]) – The reason for creating this sound. Shows up on the audit log.

Returns:

The created sound.

Return type:

SoundboardSound

Raises:
await create_stage_channel(name, *, topic, position=Undefined.MISSING, overwrites=Undefined.MISSING, category=None, reason=None, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a StageChannel instead.

Added in version 1.7.

Parameters:
  • name (str) – The channel’s name.

  • topic (str) – The new channel’s topic.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

StageChannel

Raises:
  • 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_sticker(*, name, description=None, emoji, file, reason=None)

This function is a coroutine.

Creates a Sticker for the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • name (str) – The sticker name. Must be 2 to 30 characters.

  • description (Optional[str]) – 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) – The reason for creating this sticker. Shows up on the audit log.

Returns:

The created sticker.

Return type:

GuildSticker

Raises:
  • 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 create_template(*, name, description=Undefined.MISSING)

This function is a coroutine.

Creates a template for the guild.

You must have the manage_guild permission to do this.

Added in version 1.7.

Parameters:
  • name (str) – The name of the template.

  • description (str) – The description of the template.

Return type:

Template

await create_test_entitlement(sku)

This function is a coroutine.

Creates a test entitlement for the guild.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

await create_text_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a TextChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

TextChannel

Raises:
  • 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.

Examples

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=Undefined.MISSING, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, overwrites=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a VoiceChannel instead.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 (Optional[str]) – 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

VoiceChannel

Raises:
  • 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.

property created_at: datetime

Returns the guild’s creation time in UTC.

property default_role: Role

Gets the @everyone role that all members have by default.

await delete()

This function is a coroutine.

Deletes the guild. You must be the guild owner to delete the guild.

Raises:
Return type:

None

await delete_auto_moderation_rule(id, *, reason=None)

Deletes an auto moderation rule.

Parameters:
  • id (int) – The ID of the auto moderation rule.

  • reason (Optional[str]) – The reason for deleting the rule. Shows up in the audit log.

Raises:
  • HTTPException – Deleting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Return type:

None

await delete_emoji(emoji, *, reason=None)

This function is a coroutine.

Deletes the custom GuildEmoji from the guild.

You must have manage_emojis permission to do this.

Parameters:
  • emoji (abc.Snowflake) – The emoji you are deleting.

  • reason (Optional[str]) – The reason for deleting this emoji. Shows up on the audit log.

Raises:
Return type:

None

await delete_sticker(sticker, *, reason=None)

This function is a coroutine.

Deletes the custom Sticker from the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • sticker (abc.Snowflake) – The sticker you are deleting.

  • reason (Optional[str]) – The reason for deleting this sticker. Shows up on the audit log.

Raises:
  • Forbidden – You are not allowed to delete stickers.

  • HTTPException – An error occurred deleting the sticker.

Return type:

None

property discovery_splash: Asset | None

Returns the guild’s discovery splash asset, if available.

await edit(*, reason=Undefined.MISSING, name=Undefined.MISSING, description=Undefined.MISSING, icon=Undefined.MISSING, banner=Undefined.MISSING, splash=Undefined.MISSING, discovery_splash=Undefined.MISSING, community=Undefined.MISSING, afk_channel=Undefined.MISSING, owner=Undefined.MISSING, afk_timeout=Undefined.MISSING, default_notifications=Undefined.MISSING, verification_level=Undefined.MISSING, explicit_content_filter=Undefined.MISSING, system_channel=Undefined.MISSING, system_channel_flags=Undefined.MISSING, preferred_locale=Undefined.MISSING, rules_channel=Undefined.MISSING, public_updates_channel=Undefined.MISSING, premium_progress_bar_enabled=Undefined.MISSING, disable_invites=Undefined.MISSING, discoverable=Undefined.MISSING, disable_raid_alerts=Undefined.MISSING, enable_activity_feed=Undefined.MISSING)

This function is a coroutine.

Edits the guild.

You must have the manage_guild permission to edit the guild.

Changed in version 1.4: The rules_channel and public_updates_channel keyword-only parameters were added.

Changed in version 2.0: The discovery_splash and community keyword-only parameters were added.

Changed in version 2.0: The newly updated guild is returned.

Parameters:
  • name (str) – The new name of the guild.

  • description (Optional[str]) – The new description of the guild. Could be None for no description. This is only available to guilds that contain PUBLIC in Guild.features.

  • icon (bytes) – A bytes-like object representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that contain ANIMATED_ICON in Guild.features. Could be None to denote removal of the icon.

  • banner (bytes) – A bytes-like object representing the banner. Could be None to denote removal of the banner. This is only available to guilds that contain BANNER in Guild.features.

  • splash (bytes) – A bytes-like object representing the invite splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain INVITE_SPLASH in Guild.features.

  • discovery_splash (bytes) – A bytes-like object representing the discovery splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain DISCOVERABLE in Guild.features.

  • community (bool) – Whether the guild should be a Community guild. If set to True, both rules_channel and public_updates_channel parameters are required.

  • afk_channel (Optional[VoiceChannel]) – The new channel that is the AFK channel. Could be None for no AFK channel.

  • afk_timeout (int) – The number of seconds until someone is moved to the AFK channel.

  • owner (Member) – The new owner of the guild to transfer ownership to. Note that you must be owner of the guild to do this.

  • 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 (Optional[TextChannel]) – The new channel that is used for the system channel. Could be None for 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-US or ja or zh-CN.

  • rules_channel (Optional[TextChannel]) – The new channel that is used for rules. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for no rules channel.

  • public_updates_channel (Optional[TextChannel]) – The new channel that is used for public updates from Discord. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for 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 (class:bool) – Whether the guild’s user activity feed should be enabled.

  • reason (Optional[str]) – The reason for editing this guild. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to edit the guild.

  • HTTPException – Editing the guild failed.

  • InvalidArgument – The image format passed in to icon is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the guild and request an ownership transfer.

Returns:

The newly updated guild. Note that this has the same limitations as mentioned in Client.fetch_guild() and may not have full data.

Return type:

Guild

await edit_onboarding(*, prompts=Undefined.MISSING, default_channels=Undefined.MISSING, enabled=Undefined.MISSING, mode=Undefined.MISSING, reason=Undefined.MISSING)

This function is a coroutine.

A shorthand for Onboarding.edit without fetching the onboarding flow.

You must have the manage_guild and manage_roles permissions in the guild to do this.

Parameters:
  • prompts (Optional[List[OnboardingPrompt]]) – The new list of prompts for this flow.

  • default_channels (Optional[List[Snowflake]]) – The new default channels that users are opted into.

  • enabled (Optional[bool]) – Whether onboarding should be enabled. Setting this to True requires the guild to have COMMUNITY in features and at least 7 default_channels.

  • mode (Optional[OnboardingMode]) – The new onboarding mode.

  • reason (Optional[str]) – The reason that shows up on Audit log.

Returns:

The updated onboarding flow.

Return type:

Onboarding

Raises:
  • HTTPException – Editing the onboarding flow failed somehow.

  • Forbidden – You don’t have permissions to edit the onboarding flow.

await edit_role_positions(positions, *, reason=None)

This function is a coroutine.

Bulk edits a list of Role in the guild.

You must have the manage_roles permission 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)
Parameters:
  • positions (Dict[Role, int]) – A dict of Role to int to change the positions of each given role.

  • reason (Optional[str]) – The reason for editing the role positions. Shows up on the audit log.

Returns:

A list of all the roles in the guild.

Return type:

List[Role]

Raises:
await edit_welcome_screen(**options)

This function is a coroutine.

A shorthand for WelcomeScreen.edit without fetching the welcome screen.

You must have the manage_guild permission in the guild to do this.

The guild must have COMMUNITY in Guild.features

Parameters:
  • 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.

Returns:

The edited welcome screen.

Return type:

WelcomeScreen

Raises:
  • 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 edit_widget(*, enabled=Undefined.MISSING, channel=Undefined.MISSING)

This function is a coroutine.

Edits the widget of the guild.

You must have the manage_guild permission to use this

Added in version 2.0.

Parameters:
  • enabled (bool) – Whether to enable the widget for the guild.

  • channel (Optional[Snowflake]) – The new widget channel. None removes the widget channel.

Raises:
Return type:

None

property emoji_limit: int

The maximum number of emoji slots this guild has.

entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)

Returns an AsyncIterator that enables fetching the guild’s entitlements.

This is identical to Client.entitlements() with the guild parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

Return type:

EntitlementIterator

await estimate_pruned_members(*, days, roles=Undefined.MISSING)

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.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • roles (List[abc.Snowflake]) –

    A list of abc.Snowflake that 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.

Returns:

The number of members estimated to be pruned.

Return type:

int

Raises:
  • 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 fetch_auto_moderation_rule(id)

This function is a coroutine.

Retrieves a AutoModRule from rule ID.

Returns:

The requested auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Getting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Parameters:

id (int)

await fetch_auto_moderation_rules()

This function is a coroutine.

Retrieves a list of auto moderation rules for this guild.

Returns:

The auto moderation rules for this guild.

Return type:

List[AutoModRule]

Raises:
  • HTTPException – Getting the auto moderation rules failed.

  • Forbidden – You do not have the Manage Guild permission.

await fetch_ban(user)

This function is a coroutine.

Retrieves the BanEntry for a user.

You must have the ban_members permission to get this information.

Parameters:

user (abc.Snowflake) – The user to get ban information from.

Returns:

The BanEntry object for the specified user.

Return type:

BanEntry

Raises:
  • 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.GuildChannel or Thread with the specified ID.

Note

This method is an API call. For general usage, consider get_channel_or_thread() instead.

Added in version 2.0.

Returns:

The channel from the ID.

Return type:

Union[abc.GuildChannel, Thread]

Raises:
  • 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.

Parameters:

channel_id (int)

await fetch_channels()

This function is a coroutine.

Retrieves all abc.GuildChannel that the guild has.

Note

This method is an API call. For general usage, consider channels instead.

Added in version 1.2.

Returns:

All channels in the guild.

Return type:

Sequence[discord.channel.base.GuildChannel]

Raises:
await fetch_emoji(emoji_id, /)

This function is a coroutine.

Retrieves a custom GuildEmoji from the guild.

Note

This method is an API call. For general usage, consider iterating over emojis instead.

Parameters:

emoji_id (int) – The emoji’s ID.

Returns:

The retrieved emoji.

Return type:

GuildEmoji

Raises:
  • NotFound – The emoji requested could not be found.

  • HTTPException – An error occurred fetching the emoji.

await fetch_emojis()

This function is a coroutine.

Retrieves all custom GuildEmojis from the guild.

Note

This method is an API call. For general usage, consider emojis instead.

Raises:

HTTPException – An error occurred fetching the emojis.

Returns:

The retrieved emojis.

Return type:

List[GuildEmoji]

await fetch_member(member_id, /)

This function is a coroutine.

Retrieves a Member from a guild ID, and a member ID.

Note

This method is an API call. If you have Intents.members and member cache enabled, consider get_member() instead.

Parameters:

member_id (int) – The member’s ID to fetch from.

Returns:

The member from the member ID.

Return type:

Member

Raises:
fetch_members(*, limit=1000, after=None)

Retrieves an AsyncIterator that enables receiving the guild’s members. In order to use this, Intents.members() must be enabled.

Note

This method is an API call. For general usage, consider members instead.

Added in version 1.3.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of members to retrieve. Defaults to 1000. Pass None to fetch all members. Note that this is potentially slow.

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Member – The member with the member data parsed.

Raises:
Return type:

MemberIterator

Examples

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...
await fetch_role(role_id)

This function is a coroutine.

Retrieves a Role that the guild has.

Note

This method is an API call. For general usage, consider using get_role instead.

Added in version 2.7.

Returns:

The role in the guild with the specified ID.

Return type:

Role

Raises:

HTTPException – Retrieving the role failed.

Parameters:

role_id (int)

await fetch_roles()

This function is a coroutine.

Retrieves all Role that the guild has.

Note

This method is an API call. For general usage, consider roles instead.

Added in version 1.3.

Returns:

All roles in the guild.

Return type:

List[Role]

Raises:

HTTPException – Retrieving the roles failed.

await fetch_scheduled_event(event_id, /, *, with_user_count=True)

This function is a coroutine.

Retrieves a ScheduledEvent from event ID.

Note

This method is an API call. If you have Intents.scheduled_events, consider get_scheduled_event() instead.

Parameters:
  • event_id (int) – The event’s ID to fetch with.

  • with_user_count (Optional[bool]) – If the scheduled vent should be fetched with the number of users that are interested in the event. Defaults to True.

Returns:

The scheduled event from the event ID.

Return type:

Optional[ScheduledEvent]

Raises:
await fetch_scheduled_events(*, with_user_count=True)

This function is a coroutine.

Returns a list of ScheduledEvent in the guild.

Note

This method is an API call. For general usage, consider scheduled_events instead.

Parameters:

with_user_count (Optional[bool]) – If the scheduled event should be fetched with the number of users that are interested in the events. Defaults to True.

Returns:

The fetched scheduled events.

Return type:

List[ScheduledEvent]

Raises:
await fetch_sound(sound_id)

This function is a coroutine. Fetches a soundboard sound in the guild.

Added in version 2.7.

Parameters:

sound_id (int) – The ID of the sound.

Returns:

The sound.

Return type:

SoundboardSound

await fetch_sounds()

This function is a coroutine. Fetches all the soundboard sounds in the guild.

Added in version 2.7.

Returns:

The sounds in the guild.

Return type:

List[SoundboardSound]

await fetch_sticker(sticker_id, /)

This function is a coroutine.

Retrieves a custom Sticker from the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider iterating over stickers instead.

Parameters:

sticker_id (int) – The sticker’s ID.

Returns:

The retrieved sticker.

Return type:

GuildSticker

Raises:
  • NotFound – The sticker requested could not be found.

  • HTTPException – An error occurred fetching the sticker.

await fetch_stickers()

This function is a coroutine.

Retrieves a list of all Stickers for the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider stickers instead.

Raises:

HTTPException – An error occurred fetching the stickers.

Returns:

The retrieved stickers.

Return type:

List[GuildSticker]

property filesize_limit: int

The maximum number of bytes files can have when uploaded to this guild.

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.

get_channel(channel_id, /)

Returns a channel with the given ID.

Note

This does not search for threads.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or None if not found.

Return type:

Optional[abc.GuildChannel]

get_channel_or_thread(channel_id, /)

Returns a channel or thread with the given ID.

Added in version 2.0.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or thread or None if not found.

Return type:

Optional[Union[Thread, abc.GuildChannel]]

await get_me()

Similar to Client.user except an instance of Member. This is essentially used to get the member version of yourself.

Return type:

Member

await get_member(user_id, /)

Returns a member with the given ID.

Parameters:

user_id (int) – The ID to search for.

Returns:

The member or None if not found.

Return type:

Optional[Member]

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, None is returned.

Parameters:

name (str) – The name of the member to lookup with an optional discriminator.

Returns:

The member in this guild with the associated name. If not found then None is returned.

Return type:

Optional[Member]

await get_members()

A list of members that belong to this guild.

Return type:

list[Member]

await get_owner()

The member that owns the guild.

Return type:

Member | None

get_role(role_id, /)

Returns a role with the given ID.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found.

Return type:

Optional[Role]

get_scheduled_event(event_id, /)

Returns a Scheduled Event with the given ID.

Parameters:

event_id (int) – The ID to search for.

Returns:

The scheduled event or None if not found.

Return type:

Optional[ScheduledEvent]

get_sound(sound_id)

Returns a sound with the given ID.

Added in version 2.7.

Parameters:

sound_id (int) – The ID to search for.

Returns:

The sound or None if not found.

Return type:

Optional[SoundboardSound]

get_stage_instance(stage_instance_id, /)

Returns a stage instance with the given ID.

Added in version 2.0.

Parameters:

stage_instance_id (int) – The ID to search for.

Returns:

The stage instance or None if not found.

Return type:

Optional[StageInstance]

get_thread(thread_id, /)

Returns a thread with the given ID.

Added in version 2.0.

Parameters:

thread_id (int) – The ID to search for.

Returns:

The returned thread or None if not found.

Return type:

Optional[Thread]

property icon: Asset | None

Returns the guild’s icon asset, if available.

await integrations()

This function is a coroutine.

Returns a list of all integrations attached to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Returns:

The list of integrations that are attached to the guild.

Return type:

List[Integration]

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – Fetching the integrations failed.

await invites()

This function is a coroutine.

Returns a list of all active instant invites from the guild.

You must have the manage_guild permission to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

property invites_disabled: bool

A boolean indicating whether the guild invites are disabled.

await is_chunked()

Returns a boolean indicating if the guild is “chunked”.

A chunked guild means that member_count is equal to the number of members stored in the internal members cache.

If this value returns False, then you should request for offline members.

Return type:

bool

await is_large()

Indicates if the guild is a ‘large’ guild.

A large guild is defined as having more than large_threshold count members, which for this library is set to the maximum of 250.

Return type:

bool

property jump_url: str

Returns a URL that allows the client to jump to the guild.

Added in version 2.0.

await kick(user, *, reason=None)

This function is a coroutine.

Kicks a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the kick_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to kick from their guild.

  • reason (Optional[str]) – The reason the user got kicked.

Raises:
Return type:

None

await leave()

This function is a coroutine.

Leaves the guild. :rtype: None

Note

You cannot leave the guild that you own, you must delete it instead via delete().

Raises:

HTTPException – Leaving the guild failed.

property member_count: int

Returns the true member count regardless of it being loaded fully or not.

Warning

Due to a Discord limitation, in order for this attribute to remain up-to-date and accurate, it requires Intents.members to be specified.

await modify_incident_actions(*, invites_disabled_until=Undefined.MISSING, dms_disabled_until=Undefined.MISSING, reason=Undefined.MISSING)

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_guild permission.

Parameters:
  • invites_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when invites will be enabled again, or None to enable invites immediately.

  • dms_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when DMs will be enabled again, or None to enable DMs immediately.

  • reason (Optional[str]) – The reason for this action, used for the audit log.

Returns:

The updated incidents data for the guild.

Return type:

IncidentsData

await onboarding()

This function is a coroutine.

Returns the Onboarding flow for the guild.

Added in version 2.5.

Returns:

The onboarding flow for the guild.

Return type:

Onboarding

Raises:

HTTPException – Retrieving the onboarding flow failed somehow.

property premium_subscriber_role: Role | None

Gets the premium subscriber role, AKA “boost” role, in this guild.

Added in version 1.6.

property premium_subscribers: list[Member]

A list of members who have “boosted” this guild.

await prune_members(*, days, compute_prune_count=True, roles=Undefined.MISSING, 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 days number of days and have no roles.

You must have the kick_members permission 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 roles parameter.

Changed in version 1.4: The roles keyword-only parameter was added.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

  • compute_prune_count (bool) – Whether to compute the prune count. This defaults to True which makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this to False. If this is set to False, then this function will always return None.

  • roles (List[abc.Snowflake]) – A list of abc.Snowflake that represent roles to include in the pruning process. If a member has a role that is not specified, they’ll be excluded.

Raises:
Returns:

The number of members pruned. If compute_prune_count is False then this returns None.

Return type:

Optional[int]

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.

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.

Parameters:
  • query (Optional[str]) – The string that the username’s start with.

  • user_ids (Optional[List[int]]) –

    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 (Optional[int]) – The maximum number of members to send back. If no query is passed, passing None returns all members. If a query or user_ids is passed, must be between 1 and 100. Defaults to 5.

  • presences (Optional[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 as get_member() work for those that matched. Defaults to True.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:
property roles: list[Role]

Returns a list of the guild’s roles in hierarchy order.

The first element of this list will be the lowest role in the hierarchy.

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 scheduled_events: list[ScheduledEvent]

A list of scheduled events in this guild.

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 require Intents.members().

Note

This method is an API call. For general usage, consider filtering members instead.

Added in version 2.6.

Parameters:
  • query (str) – Searches for usernames and nicknames that start with this string, case-insensitive.

  • limit (int) – The maximum number of members to retrieve, up to 1000.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:

HTTPException – Getting the members failed.

property self_role: Role | None

Gets the role associated with this client’s user, if any.

Added in version 1.6.

await set_mfa_required(required, *, reason=None)

This function is a coroutine.

Set whether it is required to have MFA enabled on your account to perform moderation actions. You must be the guild owner to do this.

Parameters:
  • required (bool) – Whether MFA should be required to perform moderation actions.

  • reason (str) – The reason to show up in the audit log.

Raises:
Return type:

None

property shard_id: int

Returns the shard ID for this guild if applicable.

property soundboard_limit: int

The maximum number of soundboard slots this guild has.

Added in version 2.7.

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.

property splash: Asset | None

Returns the guild’s invite splash asset, if available.

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 stage_instances: list[StageInstance]

Returns a list of the guild’s stage instances that are currently running.

Added in version 2.0.

property sticker_limit: int

The maximum number of sticker slots this guild has.

Added in version 2.0.

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.

await templates()

This function is a coroutine.

Gets the list of templates from this guild.

Requires manage_guild permissions.

Added in version 1.7.

Returns:

The templates for this guild.

Return type:

List[Template]

Raises:

Forbidden – You don’t have permissions to get the templates.

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 threads: list[Thread]

A list of threads that you have permission to view.

Added in version 2.0.

await unban(user, *, reason=None)

This function is a coroutine.

Unbans a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to unban.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
Return type:

None

await vanity_invite()

This function is a coroutine.

Returns the guild’s special vanity invite.

The guild must have VANITY_URL in features.

You must have the manage_guild permission to use this as well.

Returns:

The special vanity invite. If None then the guild does not have a vanity invite set.

Return type:

Optional[Invite]

Raises:
  • Forbidden – You do not have the proper permissions to get this.

  • HTTPException – Retrieving the vanity invite failed.

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 voice_client: VoiceClient | None

Returns the VoiceClient associated with this guild, if any.

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this guild.

Requires manage_webhooks permissions.

Returns:

The webhooks for this guild.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

await welcome_screen()

This function is a coroutine.

Returns the WelcomeScreen of the guild.

The guild must have COMMUNITY in features.

You must have the manage_guild permission in order to get this.

Added in version 2.0.

Returns:

The welcome screen of guild.

Return type:

WelcomeScreen

Raises:
  • 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 widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Returns:

The guild’s widget.

Return type:

Widget

Raises:
class discord.events.GuildUnavailable[source]

Called when a guild becomes unavailable.

The guild must have existed in the client’s cache. This requires Intents.guilds to be enabled.

This event inherits from Guild.

await active_threads()

This function is a coroutine.

Returns a list of active Thread that the client can access.

This includes both private and public threads.

Added in version 2.0.

Returns:

The active threads

Return type:

List[Thread]

Raises:

HTTPException – The request to get the active threads failed.

await audit_logs(*, limit=100, before=None, after=None, user=None, action=None)

Returns an AsyncIterator that enables receiving the guild’s audit logs.

You must have the view_audit_log permission to use this.

See API documentation for more information about the before and after parameters.

Parameters:
  • limit (Optional[int]) – The number of entries to retrieve. If None retrieve all entries.

  • before (Union[abc.Snowflake, datetime.datetime]) – 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 (Union[abc.Snowflake, datetime.datetime]) – 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 (abc.Snowflake) – The moderator to filter entries from.

  • action (AuditLogAction) – The action to filter with.

Yields:

AuditLogEntry – The audit log entry.

Raises:
  • Forbidden – You are not allowed to fetch audit logs

  • HTTPException – An error occurred while fetching the audit logs.

Return type:

AuditLogIterator

Examples

Getting the first 100 entries:

async for entry in guild.audit_logs(limit=100):
    print(f"{entry.user} did {entry.action} to {await entry.get_target()}")

Getting entries for a specific action:

async for entry in guild.audit_logs(action=discord.AuditLogAction.ban):
    print(f"{entry.user} banned {await entry.get_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 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.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to ban from their guild.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the user got banned.

Raises:
Return type:

None

property banner: Asset | None

Returns the guild’s banner asset, if available.

bans(limit=None, before=None, after=None)

This function is a coroutine.

Retrieves an AsyncIterator that enables receiving the guild’s bans. In order to use this, you must have the ban_members permission. Users will always be returned in ascending order sorted by user ID. If both the before and after parameters are provided, only before is respected.

Changed in version 2.5: The before. and after parameters were changed. They are now of the type abc.Snowflake instead of SnowflakeTime to comply with the discord api.

Changed in version 2.0: The limit, before. and after parameters were added. Now returns a BanIterator instead of a list of BanEntry objects.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of bans to retrieve. Defaults to 1000.

  • before (Optional[abc.Snowflake]) – Retrieve bans before the given user.

  • after (Optional[abc.Snowflake]) – Retrieve bans after the given user.

Yields:

BanEntry – The ban entry for the ban.

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

Return type:

BanIterator

Examples

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...
property bitrate_limit: int

The maximum bitrate for voice channels this guild can have.

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.Snowflake abc.

You must have the ban_members permission 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)
Parameters:
  • *users (abc.Snowflake) – An argument list of users to ban from the guild, up to 200.

  • delete_message_seconds (Optional[int]) – The number of seconds worth of messages to delete from the user in the guild. The minimum is 0 and the maximum is 604800 (i.e. 7 days). The default is 0.

  • reason (Optional[str]) – The reason the users were banned.

Returns:

Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.

Return type:

Tuple[List[abc.Snowflake], List[abc.Snowflake]]

Raises:
by_category()

Returns every CategoryChannel and 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.

Returns:

The categories and their associated channels.

Return type:

List[Tuple[Optional[CategoryChannel], List[abc.GuildChannel]]]

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.

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.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – Channel the client wants to join. Use None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

property channels: list[GuildChannel]

A list of channels that belong to this guild.

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.

Parameters:

cache (bool) – Whether to cache the members as well.

Raises:

ClientException – The members intent is not enabled.

Return type:

None

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.

Parameters:
  • 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[abc.Snowflake]) – A list of roles that are exempt from the rule.

  • exempt_channels (List[abc.Snowflake]) – A list of channels that are exempt from the rule.

  • reason (Optional[str]) – The reason for creating the rule. Shows up in the audit log.

Returns:

The new auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Creating the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

await create_category(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_category_channel(name, *, overwrites=Undefined.MISSING, reason=None, position=Undefined.MISSING)

This function is a coroutine.

Same as create_text_channel() except makes a CategoryChannel instead.

Note

The category parameter is not supported in this function since categories cannot have categories.

Returns:

The channel that was just created.

Return type:

CategoryChannel

Raises:
  • 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.

Parameters:
await create_custom_emoji(*, name, image, roles=Undefined.MISSING, reason=None)

This function is a coroutine.

Creates a custom GuildEmoji for the guild.

There is currently a limit of 50 static and animated emojis respectively per guild, unless the guild has the MORE_EMOJI feature which extends the limit to 200.

You must have the manage_emojis permission to do this.

Parameters:
  • 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]) – A list of Roles that can use this emoji. Leave empty to make it available to everyone.

  • reason (Optional[str]) – The reason for creating this emoji. Shows up on the audit log.

Raises:
Returns:

The created emoji.

Return type:

GuildEmoji

await create_forum_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_reaction_emoji=Undefined.MISSING, available_tags=Undefined.MISSING, default_sort_order=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a ForumChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_reaction_emoji (Optional[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 (Optional[SortOrder]) –

    The default sort order type used to order posts in this channel.

    Added in version 2.7.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

ForumChannel

Raises:

Examples

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_integration(*, type, id)

This function is a coroutine.

Attaches an integration to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Parameters:
  • type (str) – The integration type (e.g. Twitch).

  • id (int) – The integration ID.

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – The account could not be found.

Return type:

None

await create_role(*, name=Undefined.MISSING, permissions=Undefined.MISSING, color=Undefined.MISSING, colour=Undefined.MISSING, colors=Undefined.MISSING, colours=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, reason=None, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Creates a Role for the guild.

All fields are optional.

You must have the manage_roles permission to do this.

Changed in version 1.6: Can now pass int to colour keyword-only parameter.

Parameters:
  • name (str) – The role name. Defaults to ‘new role’.

  • permissions (Permissions) – The permissions to have. Defaults to no permissions.

  • colour (Union[Colour, int]) – The colour for the role. Defaults to Colour.default(). This is aliased to color as well.

  • hoist (bool) – Indicates if the role should be shown separately in the member list. Defaults to False.

  • mentionable (bool) – Indicates if the role should be mentionable by others. Defaults to False.

  • reason (Optional[str]) – The reason for creating this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

  • color (Colour | int | utils.Undefined)

  • colors (RoleColours | utils.Undefined)

  • colours (RoleColours | utils.Undefined)

  • holographic (bool | utils.Undefined)

Returns:

The newly created role.

Return type:

Role

Raises:
await create_scheduled_event(*, name, description=Undefined.MISSING, start_time, end_time=Undefined.MISSING, location, privacy_level=ScheduledEventPrivacyLevel.guild_only, reason=None, image=Undefined.MISSING)

This function is a coroutine. Creates a scheduled event.

Parameters:
  • name (str) – The name of the scheduled event.

  • description (Optional[str]) – The description of the scheduled event.

  • start_time (datetime.datetime) – A datetime object of when the scheduled event is supposed to start.

  • end_time (Optional[datetime.datetime]) – A datetime object of when the scheduled event is supposed to end.

  • location (ScheduledEventLocation) – The location of where the event is happening.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event

Returns:

The created scheduled event.

Return type:

Optional[ScheduledEvent]

Raises:
await create_sound(name, sound, volume=1.0, emoji=None, reason=None)

This function is a coroutine. Creates a SoundboardSound in the guild. You must have Permissions.manage_expressions permission to use this.

Added in version 2.7.

Parameters:
  • 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 (Optional[Union[PartialEmoji, GuildEmoji, str]]) – The emoji of the sound.

  • reason (Optional[str]) – The reason for creating this sound. Shows up on the audit log.

Returns:

The created sound.

Return type:

SoundboardSound

Raises:
await create_stage_channel(name, *, topic, position=Undefined.MISSING, overwrites=Undefined.MISSING, category=None, reason=None, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a StageChannel instead.

Added in version 1.7.

Parameters:
  • name (str) – The channel’s name.

  • topic (str) – The new channel’s topic.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

StageChannel

Raises:
  • 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_sticker(*, name, description=None, emoji, file, reason=None)

This function is a coroutine.

Creates a Sticker for the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • name (str) – The sticker name. Must be 2 to 30 characters.

  • description (Optional[str]) – 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) – The reason for creating this sticker. Shows up on the audit log.

Returns:

The created sticker.

Return type:

GuildSticker

Raises:
  • 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 create_template(*, name, description=Undefined.MISSING)

This function is a coroutine.

Creates a template for the guild.

You must have the manage_guild permission to do this.

Added in version 1.7.

Parameters:
  • name (str) – The name of the template.

  • description (str) – The description of the template.

Return type:

Template

await create_test_entitlement(sku)

This function is a coroutine.

Creates a test entitlement for the guild.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

await create_text_channel(name, *, reason=None, category=None, position=Undefined.MISSING, topic=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING, overwrites=Undefined.MISSING, default_thread_slowmode_delay=Undefined.MISSING, default_auto_archive_duration=Undefined.MISSING)

This function is a coroutine.

Creates a TextChannel for the guild.

Note that you need the manage_channels permission to create the channel.

The overwrites parameter can be used to create a ‘secret’ channel upon creation. This parameter expects a dict of overwrites with the target (either a Member or a Role) as the key and a PermissionOverwrite as the value.

Note

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.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[str]) – The reason for creating this channel. Shows up on the audit log.

  • default_thread_slowmode_delay (Optional[int]) –

    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.

Returns:

The channel that was just created.

Return type:

TextChannel

Raises:
  • 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.

Examples

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=Undefined.MISSING, bitrate=Undefined.MISSING, user_limit=Undefined.MISSING, rtc_region=Undefined.MISSING, video_quality_mode=Undefined.MISSING, overwrites=Undefined.MISSING, slowmode_delay=Undefined.MISSING, nsfw=Undefined.MISSING)

This function is a coroutine.

This is similar to create_text_channel() except makes a VoiceChannel instead.

Parameters:
  • name (str) – The channel’s name.

  • overwrites (Dict[Union[Role, Member, Snowflake], PermissionOverwrite]) – The overwrites to apply to the channel. Useful for creating secret channels.

  • category (Optional[CategoryChannel]) – 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 (Optional[VoiceRegion]) –

    The region for the voice channel’s voice communication. A value of None indicates 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 (Optional[str]) – 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 0 disables slowmode. The maximum value possible is 21600.

    Added in version 2.7.

  • nsfw (bool) –

    Whether the channel is marked as NSFW.

    Added in version 2.7.

Returns:

The channel that was just created.

Return type:

VoiceChannel

Raises:
  • 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.

property created_at: datetime

Returns the guild’s creation time in UTC.

property default_role: Role

Gets the @everyone role that all members have by default.

await delete()

This function is a coroutine.

Deletes the guild. You must be the guild owner to delete the guild.

Raises:
Return type:

None

await delete_auto_moderation_rule(id, *, reason=None)

Deletes an auto moderation rule.

Parameters:
  • id (int) – The ID of the auto moderation rule.

  • reason (Optional[str]) – The reason for deleting the rule. Shows up in the audit log.

Raises:
  • HTTPException – Deleting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Return type:

None

await delete_emoji(emoji, *, reason=None)

This function is a coroutine.

Deletes the custom GuildEmoji from the guild.

You must have manage_emojis permission to do this.

Parameters:
  • emoji (abc.Snowflake) – The emoji you are deleting.

  • reason (Optional[str]) – The reason for deleting this emoji. Shows up on the audit log.

Raises:
Return type:

None

await delete_sticker(sticker, *, reason=None)

This function is a coroutine.

Deletes the custom Sticker from the guild.

You must have manage_emojis_and_stickers permission to do this.

Added in version 2.0.

Parameters:
  • sticker (abc.Snowflake) – The sticker you are deleting.

  • reason (Optional[str]) – The reason for deleting this sticker. Shows up on the audit log.

Raises:
  • Forbidden – You are not allowed to delete stickers.

  • HTTPException – An error occurred deleting the sticker.

Return type:

None

property discovery_splash: Asset | None

Returns the guild’s discovery splash asset, if available.

await edit(*, reason=Undefined.MISSING, name=Undefined.MISSING, description=Undefined.MISSING, icon=Undefined.MISSING, banner=Undefined.MISSING, splash=Undefined.MISSING, discovery_splash=Undefined.MISSING, community=Undefined.MISSING, afk_channel=Undefined.MISSING, owner=Undefined.MISSING, afk_timeout=Undefined.MISSING, default_notifications=Undefined.MISSING, verification_level=Undefined.MISSING, explicit_content_filter=Undefined.MISSING, system_channel=Undefined.MISSING, system_channel_flags=Undefined.MISSING, preferred_locale=Undefined.MISSING, rules_channel=Undefined.MISSING, public_updates_channel=Undefined.MISSING, premium_progress_bar_enabled=Undefined.MISSING, disable_invites=Undefined.MISSING, discoverable=Undefined.MISSING, disable_raid_alerts=Undefined.MISSING, enable_activity_feed=Undefined.MISSING)

This function is a coroutine.

Edits the guild.

You must have the manage_guild permission to edit the guild.

Changed in version 1.4: The rules_channel and public_updates_channel keyword-only parameters were added.

Changed in version 2.0: The discovery_splash and community keyword-only parameters were added.

Changed in version 2.0: The newly updated guild is returned.

Parameters:
  • name (str) – The new name of the guild.

  • description (Optional[str]) – The new description of the guild. Could be None for no description. This is only available to guilds that contain PUBLIC in Guild.features.

  • icon (bytes) – A bytes-like object representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that contain ANIMATED_ICON in Guild.features. Could be None to denote removal of the icon.

  • banner (bytes) – A bytes-like object representing the banner. Could be None to denote removal of the banner. This is only available to guilds that contain BANNER in Guild.features.

  • splash (bytes) – A bytes-like object representing the invite splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain INVITE_SPLASH in Guild.features.

  • discovery_splash (bytes) – A bytes-like object representing the discovery splash. Only PNG/JPEG supported. Could be None to denote removing the splash. This is only available to guilds that contain DISCOVERABLE in Guild.features.

  • community (bool) – Whether the guild should be a Community guild. If set to True, both rules_channel and public_updates_channel parameters are required.

  • afk_channel (Optional[VoiceChannel]) – The new channel that is the AFK channel. Could be None for no AFK channel.

  • afk_timeout (int) – The number of seconds until someone is moved to the AFK channel.

  • owner (Member) – The new owner of the guild to transfer ownership to. Note that you must be owner of the guild to do this.

  • 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 (Optional[TextChannel]) – The new channel that is used for the system channel. Could be None for 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-US or ja or zh-CN.

  • rules_channel (Optional[TextChannel]) – The new channel that is used for rules. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for no rules channel.

  • public_updates_channel (Optional[TextChannel]) – The new channel that is used for public updates from Discord. This is only available to guilds that contain PUBLIC in Guild.features. Could be None for 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 (class:bool) – Whether the guild’s user activity feed should be enabled.

  • reason (Optional[str]) – The reason for editing this guild. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to edit the guild.

  • HTTPException – Editing the guild failed.

  • InvalidArgument – The image format passed in to icon is invalid. It must be PNG or JPG. This is also raised if you are not the owner of the guild and request an ownership transfer.

Returns:

The newly updated guild. Note that this has the same limitations as mentioned in Client.fetch_guild() and may not have full data.

Return type:

Guild

await edit_onboarding(*, prompts=Undefined.MISSING, default_channels=Undefined.MISSING, enabled=Undefined.MISSING, mode=Undefined.MISSING, reason=Undefined.MISSING)

This function is a coroutine.

A shorthand for Onboarding.edit without fetching the onboarding flow.

You must have the manage_guild and manage_roles permissions in the guild to do this.

Parameters:
  • prompts (Optional[List[OnboardingPrompt]]) – The new list of prompts for this flow.

  • default_channels (Optional[List[Snowflake]]) – The new default channels that users are opted into.

  • enabled (Optional[bool]) – Whether onboarding should be enabled. Setting this to True requires the guild to have COMMUNITY in features and at least 7 default_channels.

  • mode (Optional[OnboardingMode]) – The new onboarding mode.

  • reason (Optional[str]) – The reason that shows up on Audit log.

Returns:

The updated onboarding flow.

Return type:

Onboarding

Raises:
  • HTTPException – Editing the onboarding flow failed somehow.

  • Forbidden – You don’t have permissions to edit the onboarding flow.

await edit_role_positions(positions, *, reason=None)

This function is a coroutine.

Bulk edits a list of Role in the guild.

You must have the manage_roles permission 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)
Parameters:
  • positions (Dict[Role, int]) – A dict of Role to int to change the positions of each given role.

  • reason (Optional[str]) – The reason for editing the role positions. Shows up on the audit log.

Returns:

A list of all the roles in the guild.

Return type:

List[Role]

Raises:
await edit_welcome_screen(**options)

This function is a coroutine.

A shorthand for WelcomeScreen.edit without fetching the welcome screen.

You must have the manage_guild permission in the guild to do this.

The guild must have COMMUNITY in Guild.features

Parameters:
  • 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.

Returns:

The edited welcome screen.

Return type:

WelcomeScreen

Raises:
  • 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 edit_widget(*, enabled=Undefined.MISSING, channel=Undefined.MISSING)

This function is a coroutine.

Edits the widget of the guild.

You must have the manage_guild permission to use this

Added in version 2.0.

Parameters:
  • enabled (bool) – Whether to enable the widget for the guild.

  • channel (Optional[Snowflake]) – The new widget channel. None removes the widget channel.

Raises:
Return type:

None

property emoji_limit: int

The maximum number of emoji slots this guild has.

entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)

Returns an AsyncIterator that enables fetching the guild’s entitlements.

This is identical to Client.entitlements() with the guild parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

Return type:

EntitlementIterator

await estimate_pruned_members(*, days, roles=Undefined.MISSING)

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.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • roles (List[abc.Snowflake]) –

    A list of abc.Snowflake that 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.

Returns:

The number of members estimated to be pruned.

Return type:

int

Raises:
  • 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 fetch_auto_moderation_rule(id)

This function is a coroutine.

Retrieves a AutoModRule from rule ID.

Returns:

The requested auto moderation rule.

Return type:

AutoModRule

Raises:
  • HTTPException – Getting the auto moderation rule failed.

  • Forbidden – You do not have the Manage Guild permission.

Parameters:

id (int)

await fetch_auto_moderation_rules()

This function is a coroutine.

Retrieves a list of auto moderation rules for this guild.

Returns:

The auto moderation rules for this guild.

Return type:

List[AutoModRule]

Raises:
  • HTTPException – Getting the auto moderation rules failed.

  • Forbidden – You do not have the Manage Guild permission.

await fetch_ban(user)

This function is a coroutine.

Retrieves the BanEntry for a user.

You must have the ban_members permission to get this information.

Parameters:

user (abc.Snowflake) – The user to get ban information from.

Returns:

The BanEntry object for the specified user.

Return type:

BanEntry

Raises:
  • 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.GuildChannel or Thread with the specified ID.

Note

This method is an API call. For general usage, consider get_channel_or_thread() instead.

Added in version 2.0.

Returns:

The channel from the ID.

Return type:

Union[abc.GuildChannel, Thread]

Raises:
  • 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.

Parameters:

channel_id (int)

await fetch_channels()

This function is a coroutine.

Retrieves all abc.GuildChannel that the guild has.

Note

This method is an API call. For general usage, consider channels instead.

Added in version 1.2.

Returns:

All channels in the guild.

Return type:

Sequence[discord.channel.base.GuildChannel]

Raises:
await fetch_emoji(emoji_id, /)

This function is a coroutine.

Retrieves a custom GuildEmoji from the guild.

Note

This method is an API call. For general usage, consider iterating over emojis instead.

Parameters:

emoji_id (int) – The emoji’s ID.

Returns:

The retrieved emoji.

Return type:

GuildEmoji

Raises:
  • NotFound – The emoji requested could not be found.

  • HTTPException – An error occurred fetching the emoji.

await fetch_emojis()

This function is a coroutine.

Retrieves all custom GuildEmojis from the guild.

Note

This method is an API call. For general usage, consider emojis instead.

Raises:

HTTPException – An error occurred fetching the emojis.

Returns:

The retrieved emojis.

Return type:

List[GuildEmoji]

await fetch_member(member_id, /)

This function is a coroutine.

Retrieves a Member from a guild ID, and a member ID.

Note

This method is an API call. If you have Intents.members and member cache enabled, consider get_member() instead.

Parameters:

member_id (int) – The member’s ID to fetch from.

Returns:

The member from the member ID.

Return type:

Member

Raises:
fetch_members(*, limit=1000, after=None)

Retrieves an AsyncIterator that enables receiving the guild’s members. In order to use this, Intents.members() must be enabled.

Note

This method is an API call. For general usage, consider members instead.

Added in version 1.3.

All parameters are optional.

Parameters:
  • limit (Optional[int]) – The number of members to retrieve. Defaults to 1000. Pass None to fetch all members. Note that this is potentially slow.

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Member – The member with the member data parsed.

Raises:
Return type:

MemberIterator

Examples

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...
await fetch_role(role_id)

This function is a coroutine.

Retrieves a Role that the guild has.

Note

This method is an API call. For general usage, consider using get_role instead.

Added in version 2.7.

Returns:

The role in the guild with the specified ID.

Return type:

Role

Raises:

HTTPException – Retrieving the role failed.

Parameters:

role_id (int)

await fetch_roles()

This function is a coroutine.

Retrieves all Role that the guild has.

Note

This method is an API call. For general usage, consider roles instead.

Added in version 1.3.

Returns:

All roles in the guild.

Return type:

List[Role]

Raises:

HTTPException – Retrieving the roles failed.

await fetch_scheduled_event(event_id, /, *, with_user_count=True)

This function is a coroutine.

Retrieves a ScheduledEvent from event ID.

Note

This method is an API call. If you have Intents.scheduled_events, consider get_scheduled_event() instead.

Parameters:
  • event_id (int) – The event’s ID to fetch with.

  • with_user_count (Optional[bool]) – If the scheduled vent should be fetched with the number of users that are interested in the event. Defaults to True.

Returns:

The scheduled event from the event ID.

Return type:

Optional[ScheduledEvent]

Raises:
await fetch_scheduled_events(*, with_user_count=True)

This function is a coroutine.

Returns a list of ScheduledEvent in the guild.

Note

This method is an API call. For general usage, consider scheduled_events instead.

Parameters:

with_user_count (Optional[bool]) – If the scheduled event should be fetched with the number of users that are interested in the events. Defaults to True.

Returns:

The fetched scheduled events.

Return type:

List[ScheduledEvent]

Raises:
await fetch_sound(sound_id)

This function is a coroutine. Fetches a soundboard sound in the guild.

Added in version 2.7.

Parameters:

sound_id (int) – The ID of the sound.

Returns:

The sound.

Return type:

SoundboardSound

await fetch_sounds()

This function is a coroutine. Fetches all the soundboard sounds in the guild.

Added in version 2.7.

Returns:

The sounds in the guild.

Return type:

List[SoundboardSound]

await fetch_sticker(sticker_id, /)

This function is a coroutine.

Retrieves a custom Sticker from the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider iterating over stickers instead.

Parameters:

sticker_id (int) – The sticker’s ID.

Returns:

The retrieved sticker.

Return type:

GuildSticker

Raises:
  • NotFound – The sticker requested could not be found.

  • HTTPException – An error occurred fetching the sticker.

await fetch_stickers()

This function is a coroutine.

Retrieves a list of all Stickers for the guild.

Added in version 2.0.

Note

This method is an API call. For general usage, consider stickers instead.

Raises:

HTTPException – An error occurred fetching the stickers.

Returns:

The retrieved stickers.

Return type:

List[GuildSticker]

property filesize_limit: int

The maximum number of bytes files can have when uploaded to this guild.

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.

get_channel(channel_id, /)

Returns a channel with the given ID.

Note

This does not search for threads.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or None if not found.

Return type:

Optional[abc.GuildChannel]

get_channel_or_thread(channel_id, /)

Returns a channel or thread with the given ID.

Added in version 2.0.

Parameters:

channel_id (int) – The ID to search for.

Returns:

The returned channel or thread or None if not found.

Return type:

Optional[Union[Thread, abc.GuildChannel]]

await get_me()

Similar to Client.user except an instance of Member. This is essentially used to get the member version of yourself.

Return type:

Member

await get_member(user_id, /)

Returns a member with the given ID.

Parameters:

user_id (int) – The ID to search for.

Returns:

The member or None if not found.

Return type:

Optional[Member]

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, None is returned.

Parameters:

name (str) – The name of the member to lookup with an optional discriminator.

Returns:

The member in this guild with the associated name. If not found then None is returned.

Return type:

Optional[Member]

await get_members()

A list of members that belong to this guild.

Return type:

list[Member]

await get_owner()

The member that owns the guild.

Return type:

Member | None

get_role(role_id, /)

Returns a role with the given ID.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found.

Return type:

Optional[Role]

get_scheduled_event(event_id, /)

Returns a Scheduled Event with the given ID.

Parameters:

event_id (int) – The ID to search for.

Returns:

The scheduled event or None if not found.

Return type:

Optional[ScheduledEvent]

get_sound(sound_id)

Returns a sound with the given ID.

Added in version 2.7.

Parameters:

sound_id (int) – The ID to search for.

Returns:

The sound or None if not found.

Return type:

Optional[SoundboardSound]

get_stage_instance(stage_instance_id, /)

Returns a stage instance with the given ID.

Added in version 2.0.

Parameters:

stage_instance_id (int) – The ID to search for.

Returns:

The stage instance or None if not found.

Return type:

Optional[StageInstance]

get_thread(thread_id, /)

Returns a thread with the given ID.

Added in version 2.0.

Parameters:

thread_id (int) – The ID to search for.

Returns:

The returned thread or None if not found.

Return type:

Optional[Thread]

property icon: Asset | None

Returns the guild’s icon asset, if available.

await integrations()

This function is a coroutine.

Returns a list of all integrations attached to the guild.

You must have the manage_guild permission to do this.

Added in version 1.4.

Returns:

The list of integrations that are attached to the guild.

Return type:

List[Integration]

Raises:
  • Forbidden – You do not have permission to create the integration.

  • HTTPException – Fetching the integrations failed.

await invites()

This function is a coroutine.

Returns a list of all active instant invites from the guild.

You must have the manage_guild permission to get this information.

Returns:

The list of invites that are currently active.

Return type:

List[Invite]

Raises:
  • Forbidden – You do not have proper permissions to get the information.

  • HTTPException – An error occurred while fetching the information.

property invites_disabled: bool

A boolean indicating whether the guild invites are disabled.

await is_chunked()

Returns a boolean indicating if the guild is “chunked”.

A chunked guild means that member_count is equal to the number of members stored in the internal members cache.

If this value returns False, then you should request for offline members.

Return type:

bool

await is_large()

Indicates if the guild is a ‘large’ guild.

A large guild is defined as having more than large_threshold count members, which for this library is set to the maximum of 250.

Return type:

bool

property jump_url: str

Returns a URL that allows the client to jump to the guild.

Added in version 2.0.

await kick(user, *, reason=None)

This function is a coroutine.

Kicks a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the kick_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to kick from their guild.

  • reason (Optional[str]) – The reason the user got kicked.

Raises:
Return type:

None

await leave()

This function is a coroutine.

Leaves the guild. :rtype: None

Note

You cannot leave the guild that you own, you must delete it instead via delete().

Raises:

HTTPException – Leaving the guild failed.

property member_count: int

Returns the true member count regardless of it being loaded fully or not.

Warning

Due to a Discord limitation, in order for this attribute to remain up-to-date and accurate, it requires Intents.members to be specified.

await modify_incident_actions(*, invites_disabled_until=Undefined.MISSING, dms_disabled_until=Undefined.MISSING, reason=Undefined.MISSING)

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_guild permission.

Parameters:
  • invites_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when invites will be enabled again, or None to enable invites immediately.

  • dms_disabled_until (Optional[datetime.datetime]) – The ISO8601 timestamp indicating when DMs will be enabled again, or None to enable DMs immediately.

  • reason (Optional[str]) – The reason for this action, used for the audit log.

Returns:

The updated incidents data for the guild.

Return type:

IncidentsData

await onboarding()

This function is a coroutine.

Returns the Onboarding flow for the guild.

Added in version 2.5.

Returns:

The onboarding flow for the guild.

Return type:

Onboarding

Raises:

HTTPException – Retrieving the onboarding flow failed somehow.

property premium_subscriber_role: Role | None

Gets the premium subscriber role, AKA “boost” role, in this guild.

Added in version 1.6.

property premium_subscribers: list[Member]

A list of members who have “boosted” this guild.

await prune_members(*, days, compute_prune_count=True, roles=Undefined.MISSING, 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 days number of days and have no roles.

You must have the kick_members permission 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 roles parameter.

Changed in version 1.4: The roles keyword-only parameter was added.

Parameters:
  • days (int) – The number of days before counting as inactive.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

  • compute_prune_count (bool) – Whether to compute the prune count. This defaults to True which makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this to False. If this is set to False, then this function will always return None.

  • roles (List[abc.Snowflake]) – A list of abc.Snowflake that represent roles to include in the pruning process. If a member has a role that is not specified, they’ll be excluded.

Raises:
Returns:

The number of members pruned. If compute_prune_count is False then this returns None.

Return type:

Optional[int]

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.

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.

Parameters:
  • query (Optional[str]) – The string that the username’s start with.

  • user_ids (Optional[List[int]]) –

    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 (Optional[int]) – The maximum number of members to send back. If no query is passed, passing None returns all members. If a query or user_ids is passed, must be between 1 and 100. Defaults to 5.

  • presences (Optional[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 as get_member() work for those that matched. Defaults to True.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:
property roles: list[Role]

Returns a list of the guild’s roles in hierarchy order.

The first element of this list will be the lowest role in the hierarchy.

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 scheduled_events: list[ScheduledEvent]

A list of scheduled events in this guild.

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 require Intents.members().

Note

This method is an API call. For general usage, consider filtering members instead.

Added in version 2.6.

Parameters:
  • query (str) – Searches for usernames and nicknames that start with this string, case-insensitive.

  • limit (int) – The maximum number of members to retrieve, up to 1000.

Returns:

The list of members that have matched the query.

Return type:

List[Member]

Raises:

HTTPException – Getting the members failed.

property self_role: Role | None

Gets the role associated with this client’s user, if any.

Added in version 1.6.

await set_mfa_required(required, *, reason=None)

This function is a coroutine.

Set whether it is required to have MFA enabled on your account to perform moderation actions. You must be the guild owner to do this.

Parameters:
  • required (bool) – Whether MFA should be required to perform moderation actions.

  • reason (str) – The reason to show up in the audit log.

Raises:
Return type:

None

property shard_id: int

Returns the shard ID for this guild if applicable.

property soundboard_limit: int

The maximum number of soundboard slots this guild has.

Added in version 2.7.

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.

property splash: Asset | None

Returns the guild’s invite splash asset, if available.

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 stage_instances: list[StageInstance]

Returns a list of the guild’s stage instances that are currently running.

Added in version 2.0.

property sticker_limit: int

The maximum number of sticker slots this guild has.

Added in version 2.0.

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.

await templates()

This function is a coroutine.

Gets the list of templates from this guild.

Requires manage_guild permissions.

Added in version 1.7.

Returns:

The templates for this guild.

Return type:

List[Template]

Raises:

Forbidden – You don’t have permissions to get the templates.

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 threads: list[Thread]

A list of threads that you have permission to view.

Added in version 2.0.

await unban(user, *, reason=None)

This function is a coroutine.

Unbans a user from the guild.

The user must meet the abc.Snowflake abc.

You must have the ban_members permission to do this.

Parameters:
  • user (abc.Snowflake) – The user to unban.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
Return type:

None

await vanity_invite()

This function is a coroutine.

Returns the guild’s special vanity invite.

The guild must have VANITY_URL in features.

You must have the manage_guild permission to use this as well.

Returns:

The special vanity invite. If None then the guild does not have a vanity invite set.

Return type:

Optional[Invite]

Raises:
  • Forbidden – You do not have the proper permissions to get this.

  • HTTPException – Retrieving the vanity invite failed.

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 voice_client: VoiceClient | None

Returns the VoiceClient associated with this guild, if any.

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this guild.

Requires manage_webhooks permissions.

Returns:

The webhooks for this guild.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

await welcome_screen()

This function is a coroutine.

Returns the WelcomeScreen of the guild.

The guild must have COMMUNITY in features.

You must have the manage_guild permission in order to get this.

Added in version 2.0.

Returns:

The welcome screen of guild.

Return type:

WelcomeScreen

Raises:
  • 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 widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Returns:

The guild’s widget.

Return type:

Widget

Raises:
class discord.events.GuildBanAdd[source]

Called when a user gets banned from a guild.

This requires Intents.moderation to be enabled.

This event inherits from Member.

property accent_color

Equivalent to User.accent_color

property accent_colour

Equivalent to User.accent_colour

property activity: Activity | Game | CustomActivity | Streaming | Spotify | None

Returns the primary activity the user is currently doing. Could be None if no activity is being done.

Note

Due to a Discord API limitation, this may be None if the user is listening to a song on Spotify with a title longer than 128 characters.

Note

A user may have multiple activities, these can be accessed under activities.

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_roles permission to use this, and the added Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to give to the member.

  • reason (Optional[str]) – 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.

Raises:
Return type:

None

property avatar

Equivalent to User.avatar

property avatar_decoration

Equivalent to User.avatar_decoration

await ban(*, delete_message_seconds=None, reason=None)

This function is a coroutine.

Bans this member. Equivalent to Guild.ban().

Parameters:
Return type:

None

property banner

Equivalent to User.banner

property bot

Equivalent to User.bot

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property color: Colour

A property that returns a color denoting the rendered color for the member. If the default color is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named colour.

property colour: Colour

A property that returns a colour denoting the rendered colour for the member. If the default colour is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named color.

await create_dm() DMChannel

This function is a coroutine.

Creates a DMChannel with this user.

This should be rarely called, as this is done transparently for most people.

Returns:

The channel that was created.

Return type:

DMChannel

await create_test_entitlement(sku: discord.abc.Snowflake) Entitlement

This function is a coroutine.

Creates a test entitlement for the user.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

property created_at

Equivalent to User.created_at

property default_avatar

Equivalent to User.default_avatar

property desktop_status: Status

The member’s status on the desktop client, if applicable.

property discriminator

Equivalent to User.discriminator

property display_avatar: Asset

Returns the member’s display avatar.

For regular members this is just their avatar, but if they have a guild specific avatar then that is returned instead.

Added in version 2.0.

property display_banner: Asset | None

Returns the member’s display banner.

For regular members this is just their banner, but if they have a guild specific banner then that is returned instead.

Added in version 2.7.

property display_name: str

Returns the user’s display name. This will either be their guild specific nickname, global name or username.

await edit(*, nick=Undefined.MISSING, mute=Undefined.MISSING, deafen=Undefined.MISSING, suppress=Undefined.MISSING, roles=Undefined.MISSING, voice_channel=Undefined.MISSING, reason=None, communication_disabled_until=Undefined.MISSING, bypass_verification=Undefined.MISSING, banner=Undefined.MISSING, avatar=Undefined.MISSING, bio=Undefined.MISSING)

This function is a coroutine.

Edits the member’s data.

Depending on the parameter passed, this requires different permissions listed below:

Parameter

Permission

nick

Permissions.manage_nicknames

mute

Permissions.mute_members

deafen

Permissions.deafen_members

roles

Permissions.manage_roles

voice_channel

Permissions.move_members

communication_disabled_until

Permissions.moderate_members

bypass_verification

See note below

Note

bypass_verification may be edited under three scenarios:

  • Client has Permissions.manage_guild

  • Client has Permissions.manage_roles

  • Client has ALL THREE of Permissions.moderate_members, Permissions.kick_members, and Permissions.ban_members

Note

The following parameters are only available when editing the bot’s own member:

  • avatar

  • banner

  • bio

All parameters are optional.

Changed in version 1.1: Can now pass None to voice_channel to kick a member from voice.

Changed in version 2.0: The newly member is now optionally returned, if applicable.

Parameters:
  • nick (Optional[str]) – The member’s new nickname. Use None to 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[Role]) – The member’s new list of roles. This replaces the roles.

  • voice_channel (Optional[Union[VoiceChannel, StageChannel]]) – The voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for editing this member. Shows up on the audit log.

  • communication_disabled_until (Optional[datetime.datetime]) –

    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 (Optional[bool]) –

    Indicates if the member should bypass the guild’s verification requirements.

    Added in version 2.6.

  • banner (Optional[bytes]) –

    A bytes-like object representing the banner. Could be None to 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.

  • avatar (Optional[bytes]) –

    A bytes-like object representing the avatar. Could be None to 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.

  • bio (Optional[str]) –

    The new bio for the member. Could be None to 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.

Returns:

The newly updated member, if applicable. This is only returned when certain fields are updated.

Return type:

Optional[Member]

Raises:
  • 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.

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 AsyncIterator that enables fetching the user’s entitlements.

This is identical to Client.entitlements() with the user parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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 get_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 the create_dm() coroutine function.

await get_mutual_guilds() list[Guild]

The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

Added in version 1.7.

get_role(role_id, /)

Returns a role with the given ID from roles which the member has.

Added in version 2.0.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found in the member’s roles.

Return type:

Optional[Role]

property global_name: str | None

The member’s global name, if applicable.

property guild_avatar: Asset | None

Returns an Asset for the guild avatar the member has. If unavailable, None is returned.

Added in version 2.0.

property guild_banner: Asset | None

Returns an Asset for the guild banner the member has. If unavailable, None is returned.

Added in version 2.7.

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.

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

property id

Equivalent to User.id

property is_migrated

Equivalent to User.is_migrated

is_on_mobile()

A helper function that determines if a member is active on a mobile device.

Return type:

bool

property jump_url

Equivalent to User.jump_url

await kick(*, reason=None)

This function is a coroutine.

Kicks this member. Equivalent to Guild.kick().

Parameters:

reason (str | None)

Return type:

None

property mention: str

Returns a string that allows you to mention the member.

mentioned_in(message)

Checks if the member is mentioned in the specified message.

Parameters:

message (Message) – The message to check if you’re mentioned in.

Returns:

Indicates if the member is mentioned in the message.

Return type:

bool

property mobile_status: Status

The member’s status on a mobile device, if applicable.

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_members permission to use this.

This raises the same exceptions as edit().

Changed in version 1.1: Can now pass None to kick a member from voice.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – The new voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Return type:

None

property name

Equivalent to User.name

property nameplate

Equivalent to User.nameplate

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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 primary_guild

Equivalent to User.primary_guild

property public_flags

Equivalent to User.public_flags

property raw_status: str

The member’s overall status as a string value.

Added in version 1.5.

await remove_roles(*roles, reason=None, atomic=True)

This function is a coroutine.

Removes Roles from this member.

You must have the manage_roles permission to use this, and the removed Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to remove from the member.

  • reason (Optional[str]) – 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.

Raises:
  • Forbidden – You do not have permissions to remove these roles.

  • HTTPException – Removing the roles failed.

Return type:

None

await remove_timeout(*, reason=None)

This function is a coroutine.

Removes the timeout from a member.

You must have the moderate_members permission to remove the timeout.

This is equivalent to calling timeout() and passing None to the until parameter.

Parameters:

reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to remove the timeout.

  • HTTPException – An error occurred doing the request.

Return type:

None

await request_to_speak()

This function is a coroutine.

Request to speak in the connected channel.

Only applies to stage channels. :rtype: None

Note

Requesting members that are not the client is equivalent to edit providing suppress as False.

Added in version 1.7.

Raises:
  • Forbidden – You do not have the proper permissions to the action requested.

  • HTTPException – The operation failed.

property roles: list[Role]

A list of Role that 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.

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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property status: Status

The member’s overall status. If the value is unknown, then it will be a str instead.

property system

Equivalent to User.system

property timed_out: bool

Returns whether the member is timed out.

Added in version 2.0.

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_members permission to timeout a member.

Parameters:
  • until (datetime.datetime) – The date and time to timeout the member for. If this is None then the member is removed from timeout.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

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 to timeout(until=datetime.utcnow() + duration, reason=reason).

You must have the moderate_members permission to timeout a member.

Parameters:
  • duration (datetime.timedelta) – The duration to timeout the member for.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

property top_role: Role

Returns the member’s highest role.

This is useful for figuring where a member stands in the role hierarchy chain.

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.

Return type:

None

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unban(*, reason=None)

This function is a coroutine.

Unbans this member. Equivalent to Guild.unban().

Parameters:

reason (str | None)

Return type:

None

property voice: VoiceState | None

Returns the member’s current voice state.

property web_status: Status

The member’s status on the web client, if applicable.

class discord.events.GuildBanRemove[source]

Called when a user gets unbanned from a guild.

This requires Intents.moderation to be enabled.

This event inherits from Member.

property accent_color

Equivalent to User.accent_color

property accent_colour

Equivalent to User.accent_colour

property activity: Activity | Game | CustomActivity | Streaming | Spotify | None

Returns the primary activity the user is currently doing. Could be None if no activity is being done.

Note

Due to a Discord API limitation, this may be None if the user is listening to a song on Spotify with a title longer than 128 characters.

Note

A user may have multiple activities, these can be accessed under activities.

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_roles permission to use this, and the added Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to give to the member.

  • reason (Optional[str]) – 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.

Raises:
Return type:

None

property avatar

Equivalent to User.avatar

property avatar_decoration

Equivalent to User.avatar_decoration

await ban(*, delete_message_seconds=None, reason=None)

This function is a coroutine.

Bans this member. Equivalent to Guild.ban().

Parameters:
Return type:

None

property banner

Equivalent to User.banner

property bot

Equivalent to User.bot

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property color: Colour

A property that returns a color denoting the rendered color for the member. If the default color is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named colour.

property colour: Colour

A property that returns a colour denoting the rendered colour for the member. If the default colour is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named color.

await create_dm() DMChannel

This function is a coroutine.

Creates a DMChannel with this user.

This should be rarely called, as this is done transparently for most people.

Returns:

The channel that was created.

Return type:

DMChannel

await create_test_entitlement(sku: discord.abc.Snowflake) Entitlement

This function is a coroutine.

Creates a test entitlement for the user.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

property created_at

Equivalent to User.created_at

property default_avatar

Equivalent to User.default_avatar

property desktop_status: Status

The member’s status on the desktop client, if applicable.

property discriminator

Equivalent to User.discriminator

property display_avatar: Asset

Returns the member’s display avatar.

For regular members this is just their avatar, but if they have a guild specific avatar then that is returned instead.

Added in version 2.0.

property display_banner: Asset | None

Returns the member’s display banner.

For regular members this is just their banner, but if they have a guild specific banner then that is returned instead.

Added in version 2.7.

property display_name: str

Returns the user’s display name. This will either be their guild specific nickname, global name or username.

await edit(*, nick=Undefined.MISSING, mute=Undefined.MISSING, deafen=Undefined.MISSING, suppress=Undefined.MISSING, roles=Undefined.MISSING, voice_channel=Undefined.MISSING, reason=None, communication_disabled_until=Undefined.MISSING, bypass_verification=Undefined.MISSING, banner=Undefined.MISSING, avatar=Undefined.MISSING, bio=Undefined.MISSING)

This function is a coroutine.

Edits the member’s data.

Depending on the parameter passed, this requires different permissions listed below:

Parameter

Permission

nick

Permissions.manage_nicknames

mute

Permissions.mute_members

deafen

Permissions.deafen_members

roles

Permissions.manage_roles

voice_channel

Permissions.move_members

communication_disabled_until

Permissions.moderate_members

bypass_verification

See note below

Note

bypass_verification may be edited under three scenarios:

  • Client has Permissions.manage_guild

  • Client has Permissions.manage_roles

  • Client has ALL THREE of Permissions.moderate_members, Permissions.kick_members, and Permissions.ban_members

Note

The following parameters are only available when editing the bot’s own member:

  • avatar

  • banner

  • bio

All parameters are optional.

Changed in version 1.1: Can now pass None to voice_channel to kick a member from voice.

Changed in version 2.0: The newly member is now optionally returned, if applicable.

Parameters:
  • nick (Optional[str]) – The member’s new nickname. Use None to 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[Role]) – The member’s new list of roles. This replaces the roles.

  • voice_channel (Optional[Union[VoiceChannel, StageChannel]]) – The voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for editing this member. Shows up on the audit log.

  • communication_disabled_until (Optional[datetime.datetime]) –

    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 (Optional[bool]) –

    Indicates if the member should bypass the guild’s verification requirements.

    Added in version 2.6.

  • banner (Optional[bytes]) –

    A bytes-like object representing the banner. Could be None to 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.

  • avatar (Optional[bytes]) –

    A bytes-like object representing the avatar. Could be None to 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.

  • bio (Optional[str]) –

    The new bio for the member. Could be None to 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.

Returns:

The newly updated member, if applicable. This is only returned when certain fields are updated.

Return type:

Optional[Member]

Raises:
  • 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.

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 AsyncIterator that enables fetching the user’s entitlements.

This is identical to Client.entitlements() with the user parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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 get_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 the create_dm() coroutine function.

await get_mutual_guilds() list[Guild]

The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

Added in version 1.7.

get_role(role_id, /)

Returns a role with the given ID from roles which the member has.

Added in version 2.0.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found in the member’s roles.

Return type:

Optional[Role]

property global_name: str | None

The member’s global name, if applicable.

property guild_avatar: Asset | None

Returns an Asset for the guild avatar the member has. If unavailable, None is returned.

Added in version 2.0.

property guild_banner: Asset | None

Returns an Asset for the guild banner the member has. If unavailable, None is returned.

Added in version 2.7.

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.

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

property id

Equivalent to User.id

property is_migrated

Equivalent to User.is_migrated

is_on_mobile()

A helper function that determines if a member is active on a mobile device.

Return type:

bool

property jump_url

Equivalent to User.jump_url

await kick(*, reason=None)

This function is a coroutine.

Kicks this member. Equivalent to Guild.kick().

Parameters:

reason (str | None)

Return type:

None

property mention: str

Returns a string that allows you to mention the member.

mentioned_in(message)

Checks if the member is mentioned in the specified message.

Parameters:

message (Message) – The message to check if you’re mentioned in.

Returns:

Indicates if the member is mentioned in the message.

Return type:

bool

property mobile_status: Status

The member’s status on a mobile device, if applicable.

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_members permission to use this.

This raises the same exceptions as edit().

Changed in version 1.1: Can now pass None to kick a member from voice.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – The new voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Return type:

None

property name

Equivalent to User.name

property nameplate

Equivalent to User.nameplate

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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 primary_guild

Equivalent to User.primary_guild

property public_flags

Equivalent to User.public_flags

property raw_status: str

The member’s overall status as a string value.

Added in version 1.5.

await remove_roles(*roles, reason=None, atomic=True)

This function is a coroutine.

Removes Roles from this member.

You must have the manage_roles permission to use this, and the removed Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to remove from the member.

  • reason (Optional[str]) – 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.

Raises:
  • Forbidden – You do not have permissions to remove these roles.

  • HTTPException – Removing the roles failed.

Return type:

None

await remove_timeout(*, reason=None)

This function is a coroutine.

Removes the timeout from a member.

You must have the moderate_members permission to remove the timeout.

This is equivalent to calling timeout() and passing None to the until parameter.

Parameters:

reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to remove the timeout.

  • HTTPException – An error occurred doing the request.

Return type:

None

await request_to_speak()

This function is a coroutine.

Request to speak in the connected channel.

Only applies to stage channels. :rtype: None

Note

Requesting members that are not the client is equivalent to edit providing suppress as False.

Added in version 1.7.

Raises:
  • Forbidden – You do not have the proper permissions to the action requested.

  • HTTPException – The operation failed.

property roles: list[Role]

A list of Role that 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.

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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property status: Status

The member’s overall status. If the value is unknown, then it will be a str instead.

property system

Equivalent to User.system

property timed_out: bool

Returns whether the member is timed out.

Added in version 2.0.

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_members permission to timeout a member.

Parameters:
  • until (datetime.datetime) – The date and time to timeout the member for. If this is None then the member is removed from timeout.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

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 to timeout(until=datetime.utcnow() + duration, reason=reason).

You must have the moderate_members permission to timeout a member.

Parameters:
  • duration (datetime.timedelta) – The duration to timeout the member for.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

property top_role: Role

Returns the member’s highest role.

This is useful for figuring where a member stands in the role hierarchy chain.

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.

Return type:

None

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unban(*, reason=None)

This function is a coroutine.

Unbans this member. Equivalent to Guild.unban().

Parameters:

reason (str | None)

Return type:

None

property voice: VoiceState | None

Returns the member’s current voice state.

property web_status: Status

The member’s status on the web client, if applicable.

class discord.events.GuildEmojisUpdate[source]

Called when a guild adds or removes emojis.

This requires Intents.emojis_and_stickers to be enabled.

guild

The guild who got their emojis updated.

Type:

Guild

emojis

The list of emojis after the update.

Type:

list[Emoji]

old_emojis

The list of emojis before the update.

Type:

list[Emoji]

class discord.events.GuildStickersUpdate[source]

Called when a guild adds or removes stickers.

This requires Intents.emojis_and_stickers to be enabled.

guild

The guild who got their stickers updated.

Type:

Guild

stickers

The list of stickers after the update.

Type:

list[GuildSticker]

old_stickers

The list of stickers before the update.

Type:

list[GuildSticker]

Roles

class discord.events.GuildRoleCreate[source]

Called when a guild creates a role.

To get the guild it belongs to, use Role.guild. This requires Intents.guilds to be enabled.

This event inherits from Role.

property color: Colour

Returns the role’s primary color. Equivalent to colors.primary. An alias exists under colour.

Changed in version 2.7.

property colors: RoleColours

Returns the role’s colours. Equivalent to colours.

Added in version 2.7.

property colour: Colour

Returns the role colour. Equivalent to colours.primary. An alias exists under color.

Changed in version 2.7.

property created_at: datetime

Returns the role’s creation time in UTC.

await delete(*, reason=None)

This function is a coroutine.

Deletes the role.

You must have the manage_roles permission to use this.

Parameters:

reason (Optional[str]) – The reason for deleting this role. Shows up on the audit log.

Raises:
Return type:

None

await edit(*, name=Undefined.MISSING, permissions=Undefined.MISSING, colour=Undefined.MISSING, color=Undefined.MISSING, colours=Undefined.MISSING, colors=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, position=Undefined.MISSING, reason=Undefined.MISSING, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Edits the role.

You must have the manage_roles permission to use this.

All fields are optional.

Changed in version 1.4: Can now pass int to colour keyword-only parameter.

Changed in version 2.0: Edits are no longer in-place, the newly edited role is returned instead. Added icon and unicode_emoji.

Parameters:
  • name (str) – The new role name to change to.

  • permissions (Permissions) – The new permissions to change to.

  • colour (Union[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 (Optional[str]) – The reason for editing this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features. Could be None to denote removal of the icon.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

Returns:

The newly edited role.

Return type:

Role

Raises:
  • 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.

property icon: Asset | None

Returns the role’s icon asset, if available.

Added in version 2.0.

is_assignable()

Whether the role is able to be assigned or removed by the bot. :rtype: bool

Added in version 2.0.

is_available_for_purchase()

Whether the role is available for purchase.

Returns True if the role is available for purchase, and False if it is not available for purchase or if the role is not linked to a guild subscription. :rtype: bool

Added in version 2.7.

is_bot_managed()

Whether the role is associated with a bot. :rtype: bool

Added in version 1.6.

is_default()

Checks if the role is the default role.

Return type:

bool

is_guild_connections_role()

Whether the role is a guild connections role. :rtype: bool

Added in version 2.7.

is_integration()

Whether the guild manages the role through some form of integrations such as Twitch or through guild subscriptions. :rtype: bool

Added in version 1.6.

is_premium_subscriber()

Whether the role is the premium subscriber, AKA “boost”, role for the guild. :rtype: bool

Added in version 1.6.

property members: list[Member]

Returns all the members with this role.

property mention: str

Returns a string that allows you to mention a role.

property permissions: Permissions

Returns the role’s permissions.

class discord.events.GuildRoleUpdate[source]

Called when a role is changed guild-wide.

This requires Intents.guilds to be enabled.

This event inherits from Role.

old

The updated role’s old info.

Type:

Role

property color: Colour

Returns the role’s primary color. Equivalent to colors.primary. An alias exists under colour.

Changed in version 2.7.

property colors: RoleColours

Returns the role’s colours. Equivalent to colours.

Added in version 2.7.

property colour: Colour

Returns the role colour. Equivalent to colours.primary. An alias exists under color.

Changed in version 2.7.

property created_at: datetime

Returns the role’s creation time in UTC.

await delete(*, reason=None)

This function is a coroutine.

Deletes the role.

You must have the manage_roles permission to use this.

Parameters:

reason (Optional[str]) – The reason for deleting this role. Shows up on the audit log.

Raises:
Return type:

None

await edit(*, name=Undefined.MISSING, permissions=Undefined.MISSING, colour=Undefined.MISSING, color=Undefined.MISSING, colours=Undefined.MISSING, colors=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, position=Undefined.MISSING, reason=Undefined.MISSING, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Edits the role.

You must have the manage_roles permission to use this.

All fields are optional.

Changed in version 1.4: Can now pass int to colour keyword-only parameter.

Changed in version 2.0: Edits are no longer in-place, the newly edited role is returned instead. Added icon and unicode_emoji.

Parameters:
  • name (str) – The new role name to change to.

  • permissions (Permissions) – The new permissions to change to.

  • colour (Union[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 (Optional[str]) – The reason for editing this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features. Could be None to denote removal of the icon.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

Returns:

The newly edited role.

Return type:

Role

Raises:
  • 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.

property icon: Asset | None

Returns the role’s icon asset, if available.

Added in version 2.0.

is_assignable()

Whether the role is able to be assigned or removed by the bot. :rtype: bool

Added in version 2.0.

is_available_for_purchase()

Whether the role is available for purchase.

Returns True if the role is available for purchase, and False if it is not available for purchase or if the role is not linked to a guild subscription. :rtype: bool

Added in version 2.7.

is_bot_managed()

Whether the role is associated with a bot. :rtype: bool

Added in version 1.6.

is_default()

Checks if the role is the default role.

Return type:

bool

is_guild_connections_role()

Whether the role is a guild connections role. :rtype: bool

Added in version 2.7.

is_integration()

Whether the guild manages the role through some form of integrations such as Twitch or through guild subscriptions. :rtype: bool

Added in version 1.6.

is_premium_subscriber()

Whether the role is the premium subscriber, AKA “boost”, role for the guild. :rtype: bool

Added in version 1.6.

property members: list[Member]

Returns all the members with this role.

property mention: str

Returns a string that allows you to mention a role.

property permissions: Permissions

Returns the role’s permissions.

class discord.events.GuildRoleDelete[source]

Called when a guild deletes a role.

To get the guild it belongs to, use Role.guild. This requires Intents.guilds to be enabled.

This event inherits from Role.

property color: Colour

Returns the role’s primary color. Equivalent to colors.primary. An alias exists under colour.

Changed in version 2.7.

property colors: RoleColours

Returns the role’s colours. Equivalent to colours.

Added in version 2.7.

property colour: Colour

Returns the role colour. Equivalent to colours.primary. An alias exists under color.

Changed in version 2.7.

property created_at: datetime

Returns the role’s creation time in UTC.

await delete(*, reason=None)

This function is a coroutine.

Deletes the role.

You must have the manage_roles permission to use this.

Parameters:

reason (Optional[str]) – The reason for deleting this role. Shows up on the audit log.

Raises:
Return type:

None

await edit(*, name=Undefined.MISSING, permissions=Undefined.MISSING, colour=Undefined.MISSING, color=Undefined.MISSING, colours=Undefined.MISSING, colors=Undefined.MISSING, holographic=Undefined.MISSING, hoist=Undefined.MISSING, mentionable=Undefined.MISSING, position=Undefined.MISSING, reason=Undefined.MISSING, icon=Undefined.MISSING, unicode_emoji=Undefined.MISSING)

This function is a coroutine.

Edits the role.

You must have the manage_roles permission to use this.

All fields are optional.

Changed in version 1.4: Can now pass int to colour keyword-only parameter.

Changed in version 2.0: Edits are no longer in-place, the newly edited role is returned instead. Added icon and unicode_emoji.

Parameters:
  • name (str) – The new role name to change to.

  • permissions (Permissions) – The new permissions to change to.

  • colour (Union[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 (Optional[str]) – The reason for editing this role. Shows up on the audit log.

  • icon (Optional[bytes]) – A bytes-like object representing the icon. Only PNG/JPEG/WebP is supported. If this argument is passed, unicode_emoji is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features. Could be None to denote removal of the icon.

  • unicode_emoji (Optional[str]) – The role’s unicode emoji. If this argument is passed, icon is set to None. Only available to guilds that contain ROLE_ICONS in Guild.features.

Returns:

The newly edited role.

Return type:

Role

Raises:
  • 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.

property icon: Asset | None

Returns the role’s icon asset, if available.

Added in version 2.0.

is_assignable()

Whether the role is able to be assigned or removed by the bot. :rtype: bool

Added in version 2.0.

is_available_for_purchase()

Whether the role is available for purchase.

Returns True if the role is available for purchase, and False if it is not available for purchase or if the role is not linked to a guild subscription. :rtype: bool

Added in version 2.7.

is_bot_managed()

Whether the role is associated with a bot. :rtype: bool

Added in version 1.6.

is_default()

Checks if the role is the default role.

Return type:

bool

is_guild_connections_role()

Whether the role is a guild connections role. :rtype: bool

Added in version 2.7.

is_integration()

Whether the guild manages the role through some form of integrations such as Twitch or through guild subscriptions. :rtype: bool

Added in version 1.6.

is_premium_subscriber()

Whether the role is the premium subscriber, AKA “boost”, role for the guild. :rtype: bool

Added in version 1.6.

property members: list[Member]

Returns all the members with this role.

property mention: str

Returns a string that allows you to mention a role.

property permissions: Permissions

Returns the role’s permissions.

Integrations

class discord.events.GuildIntegrationsUpdate[source]

Called whenever an integration is created, modified, or removed from a guild.

This requires Intents.integrations to be enabled.

guild

The guild that had its integrations updated.

Type:

Guild

class discord.events.IntegrationCreate[source]

Called when an integration is created.

This requires Intents.integrations to be enabled.

This event inherits from Integration.

await delete(*, reason=None)

This function is a coroutine.

Deletes the integration.

You must have the manage_guild permission to do this.

Parameters:

reason (str) –

The reason the integration was deleted. Shows up on the audit log.

Added in version 2.0.

Raises:
  • Forbidden – You do not have permission to delete the integration.

  • HTTPException – Deleting the integration failed.

Return type:

None

class discord.events.IntegrationUpdate[source]

Called when an integration is updated.

This requires Intents.integrations to be enabled.

This event inherits from Integration.

await delete(*, reason=None)

This function is a coroutine.

Deletes the integration.

You must have the manage_guild permission to do this.

Parameters:

reason (str) –

The reason the integration was deleted. Shows up on the audit log.

Added in version 2.0.

Raises:
  • Forbidden – You do not have permission to delete the integration.

  • HTTPException – Deleting the integration failed.

Return type:

None

class discord.events.IntegrationDelete[source]

Called when an integration is deleted.

This requires Intents.integrations to be enabled.

raw

The raw event payload data.

Type:

RawIntegrationDeleteEvent

Interactions

class discord.events.InteractionCreate[source]

Called when an interaction is created.

This currently happens due to application command invocations or components being used.

Warning

This is a low level event that is not generally meant to be used. If you are working with components, consider using the callbacks associated with the View instead as it provides a nicer user experience.

This event inherits from Interaction.

app_permissions

The resolved permissions of the application in the channel, including overwrites.

cached_channel

The cached channel from which the interaction was sent. DM channels are not resolved. These are PartialMessageable instead.

Deprecated since version 2.7.

property client: Client

Returns the client that sent the interaction.

property created_at: datetime

Returns the interaction’s creation time in UTC.

await delete_original_message(**kwargs)

An alias for delete_original_response().

Raises:
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.

Parameters:

delay (Optional[float]) – If provided, the number of seconds to wait before deleting the message. The waiting is done in the background and deletion failures are ignored.

Raises:
Return type:

None

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.

Returns:

The response, its type depending on whether it’s an interaction response or a followup.

Return type:

Union[discord.InteractionMessage, discord.WebhookMessage]

await edit_original_message(**kwargs)

An alias for edit_original_response().

Returns:

The newly edited message.

Return type:

InteractionMessage

Raises:
  • HTTPException – Editing the message failed.

  • Forbidden – Edited a message that is not yours.

  • TypeError – You specified both embed and embeds or file and files

  • ValueError – The length of embeds was invalid.

await edit_original_response(*, content=Undefined.MISSING, embeds=Undefined.MISSING, embed=Undefined.MISSING, file=Undefined.MISSING, files=Undefined.MISSING, attachments=Undefined.MISSING, view=Undefined.MISSING, allowed_mentions=None, delete_after=None, suppress=False)

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.

Parameters:
  • content (Optional[str]) – The content to edit the message with or None to clear it.

  • embeds (List[Embed]) – A list of embeds to edit the message with.

  • embed (Optional[Embed]) – The embed to edit the message with. None suppresses the embeds. This should not be mixed with the embeds parameter.

  • file (File) – The file to upload. This cannot be mixed with files parameter.

  • files (List[File]) – A list of files to send with the content. This cannot be mixed with the file parameter.

  • attachments (List[Attachment]) – A list of attachments to keep in the message. If [] is passed then all attachments are removed.

  • allowed_mentions (AllowedMentions) – Controls the mentions being processed in this message. See abc.Messageable.send() for more information.

  • view (Optional[View]) – The updated view to update this message with. If None is passed then the view is removed.

  • delete_after (Optional[float]) – 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) – Whether to suppress embeds for the message.

Returns:

The newly edited message.

Return type:

InteractionMessage

Raises:
  • HTTPException – Editing the message failed.

  • Forbidden – Edited a message that is not yours.

  • TypeError – You specified both embed and embeds or file and files

  • ValueError – The length of embeds was invalid.

followup

Returns the followup webhook for followup interactions.

await get_guild()

The guild the interaction was sent from.

Return type:

Guild | None

is_command()

Indicates whether the interaction is an application command.

Return type:

bool

is_component()

Indicates whether the interaction is a message component.

Return type:

bool

is_guild_authorised()

bool: Checks if the interaction is guild authorised.

There is an alias for this called is_guild_authorized(). :rtype: bool

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(). :rtype: bool

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(). :rtype: bool

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(). :rtype: bool

Added in version 2.7.

await original_message()

An alias for original_response().

Returns:

The original interaction response message.

Return type:

InteractionMessage

Raises:
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.

Returns:

The original interaction response message.

Return type:

InteractionMessage

Raises:
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.

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.

Returns:

The response, its type depending on whether it’s an interaction response or a followup.

Return type:

Union[discord.Interaction, discord.WebhookMessage]

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 followup instead.

to_dict()

Converts this interaction object into a dict.

Returns:

A dictionary of str interaction keys bound to the respective value.

Return type:

Dict[str, Any]

Invites

class discord.events.InviteCreate[source]

Called when an invite is created.

You must have manage_channels permission to receive this.

Note

There is a rare possibility that the Invite.guild and Invite.channel attributes will be of Object rather than the respective models.

This requires Intents.invites to be enabled.

This event inherits from Invite.

await delete(*, reason=None)

This function is a coroutine.

Revokes the instant invite.

You must have the manage_channels permission to do this.

Parameters:

reason (Optional[str]) – The reason for deleting this invite. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to revoke invites.

  • NotFound – The invite is invalid or expired.

  • HTTPException – Revoking the invite failed.

property id: str

Returns the proper code portion of the invite.

set_scheduled_event(event)

Links the given scheduled event to this invite.

Note

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.

Parameters:

event (ScheduledEvent) – The scheduled event object to link.

Return type:

None

property url: str

A property that retrieves the invite URL.

class discord.events.InviteDelete[source]

Called when an invite is deleted.

You must have manage_channels permission to receive this.

Note

There is a rare possibility that the Invite.guild and Invite.channel attributes will be of Object rather than the respective models.

Outside of those two attributes, the only other attribute guaranteed to be filled by the Discord gateway for this event is Invite.code.

This requires Intents.invites to be enabled.

This event inherits from Invite.

await delete(*, reason=None)

This function is a coroutine.

Revokes the instant invite.

You must have the manage_channels permission to do this.

Parameters:

reason (Optional[str]) – The reason for deleting this invite. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to revoke invites.

  • NotFound – The invite is invalid or expired.

  • HTTPException – Revoking the invite failed.

property id: str

Returns the proper code portion of the invite.

set_scheduled_event(event)

Links the given scheduled event to this invite.

Note

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.

Parameters:

event (ScheduledEvent) – The scheduled event object to link.

Return type:

None

property url: str

A property that retrieves the invite URL.

Members & Users

class discord.events.GuildMemberJoin[source]

Called when a member joins a guild.

This requires Intents.members to be enabled.

This event inherits from Member.

property accent_color

Equivalent to User.accent_color

property accent_colour

Equivalent to User.accent_colour

property activity: Activity | Game | CustomActivity | Streaming | Spotify | None

Returns the primary activity the user is currently doing. Could be None if no activity is being done.

Note

Due to a Discord API limitation, this may be None if the user is listening to a song on Spotify with a title longer than 128 characters.

Note

A user may have multiple activities, these can be accessed under activities.

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_roles permission to use this, and the added Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to give to the member.

  • reason (Optional[str]) – 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.

Raises:
Return type:

None

property avatar

Equivalent to User.avatar

property avatar_decoration

Equivalent to User.avatar_decoration

await ban(*, delete_message_seconds=None, reason=None)

This function is a coroutine.

Bans this member. Equivalent to Guild.ban().

Parameters:
Return type:

None

property banner

Equivalent to User.banner

property bot

Equivalent to User.bot

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property color: Colour

A property that returns a color denoting the rendered color for the member. If the default color is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named colour.

property colour: Colour

A property that returns a colour denoting the rendered colour for the member. If the default colour is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named color.

await create_dm() DMChannel

This function is a coroutine.

Creates a DMChannel with this user.

This should be rarely called, as this is done transparently for most people.

Returns:

The channel that was created.

Return type:

DMChannel

await create_test_entitlement(sku: discord.abc.Snowflake) Entitlement

This function is a coroutine.

Creates a test entitlement for the user.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

property created_at

Equivalent to User.created_at

property default_avatar

Equivalent to User.default_avatar

property desktop_status: Status

The member’s status on the desktop client, if applicable.

property discriminator

Equivalent to User.discriminator

property display_avatar: Asset

Returns the member’s display avatar.

For regular members this is just their avatar, but if they have a guild specific avatar then that is returned instead.

Added in version 2.0.

property display_banner: Asset | None

Returns the member’s display banner.

For regular members this is just their banner, but if they have a guild specific banner then that is returned instead.

Added in version 2.7.

property display_name: str

Returns the user’s display name. This will either be their guild specific nickname, global name or username.

await edit(*, nick=Undefined.MISSING, mute=Undefined.MISSING, deafen=Undefined.MISSING, suppress=Undefined.MISSING, roles=Undefined.MISSING, voice_channel=Undefined.MISSING, reason=None, communication_disabled_until=Undefined.MISSING, bypass_verification=Undefined.MISSING, banner=Undefined.MISSING, avatar=Undefined.MISSING, bio=Undefined.MISSING)

This function is a coroutine.

Edits the member’s data.

Depending on the parameter passed, this requires different permissions listed below:

Parameter

Permission

nick

Permissions.manage_nicknames

mute

Permissions.mute_members

deafen

Permissions.deafen_members

roles

Permissions.manage_roles

voice_channel

Permissions.move_members

communication_disabled_until

Permissions.moderate_members

bypass_verification

See note below

Note

bypass_verification may be edited under three scenarios:

  • Client has Permissions.manage_guild

  • Client has Permissions.manage_roles

  • Client has ALL THREE of Permissions.moderate_members, Permissions.kick_members, and Permissions.ban_members

Note

The following parameters are only available when editing the bot’s own member:

  • avatar

  • banner

  • bio

All parameters are optional.

Changed in version 1.1: Can now pass None to voice_channel to kick a member from voice.

Changed in version 2.0: The newly member is now optionally returned, if applicable.

Parameters:
  • nick (Optional[str]) – The member’s new nickname. Use None to 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[Role]) – The member’s new list of roles. This replaces the roles.

  • voice_channel (Optional[Union[VoiceChannel, StageChannel]]) – The voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for editing this member. Shows up on the audit log.

  • communication_disabled_until (Optional[datetime.datetime]) –

    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 (Optional[bool]) –

    Indicates if the member should bypass the guild’s verification requirements.

    Added in version 2.6.

  • banner (Optional[bytes]) –

    A bytes-like object representing the banner. Could be None to 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.

  • avatar (Optional[bytes]) –

    A bytes-like object representing the avatar. Could be None to 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.

  • bio (Optional[str]) –

    The new bio for the member. Could be None to 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.

Returns:

The newly updated member, if applicable. This is only returned when certain fields are updated.

Return type:

Optional[Member]

Raises:
  • 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.

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 AsyncIterator that enables fetching the user’s entitlements.

This is identical to Client.entitlements() with the user parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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 get_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 the create_dm() coroutine function.

await get_mutual_guilds() list[Guild]

The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

Added in version 1.7.

get_role(role_id, /)

Returns a role with the given ID from roles which the member has.

Added in version 2.0.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found in the member’s roles.

Return type:

Optional[Role]

property global_name: str | None

The member’s global name, if applicable.

property guild_avatar: Asset | None

Returns an Asset for the guild avatar the member has. If unavailable, None is returned.

Added in version 2.0.

property guild_banner: Asset | None

Returns an Asset for the guild banner the member has. If unavailable, None is returned.

Added in version 2.7.

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.

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

property id

Equivalent to User.id

property is_migrated

Equivalent to User.is_migrated

is_on_mobile()

A helper function that determines if a member is active on a mobile device.

Return type:

bool

property jump_url

Equivalent to User.jump_url

await kick(*, reason=None)

This function is a coroutine.

Kicks this member. Equivalent to Guild.kick().

Parameters:

reason (str | None)

Return type:

None

property mention: str

Returns a string that allows you to mention the member.

mentioned_in(message)

Checks if the member is mentioned in the specified message.

Parameters:

message (Message) – The message to check if you’re mentioned in.

Returns:

Indicates if the member is mentioned in the message.

Return type:

bool

property mobile_status: Status

The member’s status on a mobile device, if applicable.

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_members permission to use this.

This raises the same exceptions as edit().

Changed in version 1.1: Can now pass None to kick a member from voice.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – The new voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Return type:

None

property name

Equivalent to User.name

property nameplate

Equivalent to User.nameplate

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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 primary_guild

Equivalent to User.primary_guild

property public_flags

Equivalent to User.public_flags

property raw_status: str

The member’s overall status as a string value.

Added in version 1.5.

await remove_roles(*roles, reason=None, atomic=True)

This function is a coroutine.

Removes Roles from this member.

You must have the manage_roles permission to use this, and the removed Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to remove from the member.

  • reason (Optional[str]) – 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.

Raises:
  • Forbidden – You do not have permissions to remove these roles.

  • HTTPException – Removing the roles failed.

Return type:

None

await remove_timeout(*, reason=None)

This function is a coroutine.

Removes the timeout from a member.

You must have the moderate_members permission to remove the timeout.

This is equivalent to calling timeout() and passing None to the until parameter.

Parameters:

reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to remove the timeout.

  • HTTPException – An error occurred doing the request.

Return type:

None

await request_to_speak()

This function is a coroutine.

Request to speak in the connected channel.

Only applies to stage channels. :rtype: None

Note

Requesting members that are not the client is equivalent to edit providing suppress as False.

Added in version 1.7.

Raises:
  • Forbidden – You do not have the proper permissions to the action requested.

  • HTTPException – The operation failed.

property roles: list[Role]

A list of Role that 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.

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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property status: Status

The member’s overall status. If the value is unknown, then it will be a str instead.

property system

Equivalent to User.system

property timed_out: bool

Returns whether the member is timed out.

Added in version 2.0.

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_members permission to timeout a member.

Parameters:
  • until (datetime.datetime) – The date and time to timeout the member for. If this is None then the member is removed from timeout.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

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 to timeout(until=datetime.utcnow() + duration, reason=reason).

You must have the moderate_members permission to timeout a member.

Parameters:
  • duration (datetime.timedelta) – The duration to timeout the member for.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

property top_role: Role

Returns the member’s highest role.

This is useful for figuring where a member stands in the role hierarchy chain.

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.

Return type:

None

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unban(*, reason=None)

This function is a coroutine.

Unbans this member. Equivalent to Guild.unban().

Parameters:

reason (str | None)

Return type:

None

property voice: VoiceState | None

Returns the member’s current voice state.

property web_status: Status

The member’s status on the web client, if applicable.

class discord.events.GuildMemberRemove[source]

Called when a member leaves a guild.

This requires Intents.members to be enabled.

This event inherits from Member.

property accent_color

Equivalent to User.accent_color

property accent_colour

Equivalent to User.accent_colour

property activity: Activity | Game | CustomActivity | Streaming | Spotify | None

Returns the primary activity the user is currently doing. Could be None if no activity is being done.

Note

Due to a Discord API limitation, this may be None if the user is listening to a song on Spotify with a title longer than 128 characters.

Note

A user may have multiple activities, these can be accessed under activities.

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_roles permission to use this, and the added Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to give to the member.

  • reason (Optional[str]) – 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.

Raises:
Return type:

None

property avatar

Equivalent to User.avatar

property avatar_decoration

Equivalent to User.avatar_decoration

await ban(*, delete_message_seconds=None, reason=None)

This function is a coroutine.

Bans this member. Equivalent to Guild.ban().

Parameters:
Return type:

None

property banner

Equivalent to User.banner

property bot

Equivalent to User.bot

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property color: Colour

A property that returns a color denoting the rendered color for the member. If the default color is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named colour.

property colour: Colour

A property that returns a colour denoting the rendered colour for the member. If the default colour is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named color.

await create_dm() DMChannel

This function is a coroutine.

Creates a DMChannel with this user.

This should be rarely called, as this is done transparently for most people.

Returns:

The channel that was created.

Return type:

DMChannel

await create_test_entitlement(sku: discord.abc.Snowflake) Entitlement

This function is a coroutine.

Creates a test entitlement for the user.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

property created_at

Equivalent to User.created_at

property default_avatar

Equivalent to User.default_avatar

property desktop_status: Status

The member’s status on the desktop client, if applicable.

property discriminator

Equivalent to User.discriminator

property display_avatar: Asset

Returns the member’s display avatar.

For regular members this is just their avatar, but if they have a guild specific avatar then that is returned instead.

Added in version 2.0.

property display_banner: Asset | None

Returns the member’s display banner.

For regular members this is just their banner, but if they have a guild specific banner then that is returned instead.

Added in version 2.7.

property display_name: str

Returns the user’s display name. This will either be their guild specific nickname, global name or username.

await edit(*, nick=Undefined.MISSING, mute=Undefined.MISSING, deafen=Undefined.MISSING, suppress=Undefined.MISSING, roles=Undefined.MISSING, voice_channel=Undefined.MISSING, reason=None, communication_disabled_until=Undefined.MISSING, bypass_verification=Undefined.MISSING, banner=Undefined.MISSING, avatar=Undefined.MISSING, bio=Undefined.MISSING)

This function is a coroutine.

Edits the member’s data.

Depending on the parameter passed, this requires different permissions listed below:

Parameter

Permission

nick

Permissions.manage_nicknames

mute

Permissions.mute_members

deafen

Permissions.deafen_members

roles

Permissions.manage_roles

voice_channel

Permissions.move_members

communication_disabled_until

Permissions.moderate_members

bypass_verification

See note below

Note

bypass_verification may be edited under three scenarios:

  • Client has Permissions.manage_guild

  • Client has Permissions.manage_roles

  • Client has ALL THREE of Permissions.moderate_members, Permissions.kick_members, and Permissions.ban_members

Note

The following parameters are only available when editing the bot’s own member:

  • avatar

  • banner

  • bio

All parameters are optional.

Changed in version 1.1: Can now pass None to voice_channel to kick a member from voice.

Changed in version 2.0: The newly member is now optionally returned, if applicable.

Parameters:
  • nick (Optional[str]) – The member’s new nickname. Use None to 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[Role]) – The member’s new list of roles. This replaces the roles.

  • voice_channel (Optional[Union[VoiceChannel, StageChannel]]) – The voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for editing this member. Shows up on the audit log.

  • communication_disabled_until (Optional[datetime.datetime]) –

    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 (Optional[bool]) –

    Indicates if the member should bypass the guild’s verification requirements.

    Added in version 2.6.

  • banner (Optional[bytes]) –

    A bytes-like object representing the banner. Could be None to 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.

  • avatar (Optional[bytes]) –

    A bytes-like object representing the avatar. Could be None to 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.

  • bio (Optional[str]) –

    The new bio for the member. Could be None to 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.

Returns:

The newly updated member, if applicable. This is only returned when certain fields are updated.

Return type:

Optional[Member]

Raises:
  • 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.

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 AsyncIterator that enables fetching the user’s entitlements.

This is identical to Client.entitlements() with the user parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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 get_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 the create_dm() coroutine function.

await get_mutual_guilds() list[Guild]

The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

Added in version 1.7.

get_role(role_id, /)

Returns a role with the given ID from roles which the member has.

Added in version 2.0.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found in the member’s roles.

Return type:

Optional[Role]

property global_name: str | None

The member’s global name, if applicable.

property guild_avatar: Asset | None

Returns an Asset for the guild avatar the member has. If unavailable, None is returned.

Added in version 2.0.

property guild_banner: Asset | None

Returns an Asset for the guild banner the member has. If unavailable, None is returned.

Added in version 2.7.

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.

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

property id

Equivalent to User.id

property is_migrated

Equivalent to User.is_migrated

is_on_mobile()

A helper function that determines if a member is active on a mobile device.

Return type:

bool

property jump_url

Equivalent to User.jump_url

await kick(*, reason=None)

This function is a coroutine.

Kicks this member. Equivalent to Guild.kick().

Parameters:

reason (str | None)

Return type:

None

property mention: str

Returns a string that allows you to mention the member.

mentioned_in(message)

Checks if the member is mentioned in the specified message.

Parameters:

message (Message) – The message to check if you’re mentioned in.

Returns:

Indicates if the member is mentioned in the message.

Return type:

bool

property mobile_status: Status

The member’s status on a mobile device, if applicable.

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_members permission to use this.

This raises the same exceptions as edit().

Changed in version 1.1: Can now pass None to kick a member from voice.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – The new voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Return type:

None

property name

Equivalent to User.name

property nameplate

Equivalent to User.nameplate

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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 primary_guild

Equivalent to User.primary_guild

property public_flags

Equivalent to User.public_flags

property raw_status: str

The member’s overall status as a string value.

Added in version 1.5.

await remove_roles(*roles, reason=None, atomic=True)

This function is a coroutine.

Removes Roles from this member.

You must have the manage_roles permission to use this, and the removed Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to remove from the member.

  • reason (Optional[str]) – 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.

Raises:
  • Forbidden – You do not have permissions to remove these roles.

  • HTTPException – Removing the roles failed.

Return type:

None

await remove_timeout(*, reason=None)

This function is a coroutine.

Removes the timeout from a member.

You must have the moderate_members permission to remove the timeout.

This is equivalent to calling timeout() and passing None to the until parameter.

Parameters:

reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to remove the timeout.

  • HTTPException – An error occurred doing the request.

Return type:

None

await request_to_speak()

This function is a coroutine.

Request to speak in the connected channel.

Only applies to stage channels. :rtype: None

Note

Requesting members that are not the client is equivalent to edit providing suppress as False.

Added in version 1.7.

Raises:
  • Forbidden – You do not have the proper permissions to the action requested.

  • HTTPException – The operation failed.

property roles: list[Role]

A list of Role that 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.

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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property status: Status

The member’s overall status. If the value is unknown, then it will be a str instead.

property system

Equivalent to User.system

property timed_out: bool

Returns whether the member is timed out.

Added in version 2.0.

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_members permission to timeout a member.

Parameters:
  • until (datetime.datetime) – The date and time to timeout the member for. If this is None then the member is removed from timeout.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

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 to timeout(until=datetime.utcnow() + duration, reason=reason).

You must have the moderate_members permission to timeout a member.

Parameters:
  • duration (datetime.timedelta) – The duration to timeout the member for.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

property top_role: Role

Returns the member’s highest role.

This is useful for figuring where a member stands in the role hierarchy chain.

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.

Return type:

None

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unban(*, reason=None)

This function is a coroutine.

Unbans this member. Equivalent to Guild.unban().

Parameters:

reason (str | None)

Return type:

None

property voice: VoiceState | None

Returns the member’s current voice state.

property web_status: Status

The member’s status on the web client, if applicable.

class discord.events.GuildMemberUpdate[source]

Called when a member updates their profile.

This is called when one or more of the following things change: - nickname - roles - pending - communication_disabled_until - timed_out

This requires Intents.members to be enabled.

This event inherits from Member.

old

The member’s old info before the update.

Type:

Member

property accent_color

Equivalent to User.accent_color

property accent_colour

Equivalent to User.accent_colour

property activity: Activity | Game | CustomActivity | Streaming | Spotify | None

Returns the primary activity the user is currently doing. Could be None if no activity is being done.

Note

Due to a Discord API limitation, this may be None if the user is listening to a song on Spotify with a title longer than 128 characters.

Note

A user may have multiple activities, these can be accessed under activities.

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_roles permission to use this, and the added Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to give to the member.

  • reason (Optional[str]) – 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.

Raises:
Return type:

None

property avatar

Equivalent to User.avatar

property avatar_decoration

Equivalent to User.avatar_decoration

await ban(*, delete_message_seconds=None, reason=None)

This function is a coroutine.

Bans this member. Equivalent to Guild.ban().

Parameters:
Return type:

None

property banner

Equivalent to User.banner

property bot

Equivalent to User.bot

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property color: Colour

A property that returns a color denoting the rendered color for the member. If the default color is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named colour.

property colour: Colour

A property that returns a colour denoting the rendered colour for the member. If the default colour is the one rendered then an instance of Colour.default() is returned.

There is an alias for this named color.

await create_dm() DMChannel

This function is a coroutine.

Creates a DMChannel with this user.

This should be rarely called, as this is done transparently for most people.

Returns:

The channel that was created.

Return type:

DMChannel

await create_test_entitlement(sku: discord.abc.Snowflake) Entitlement

This function is a coroutine.

Creates a test entitlement for the user.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

property created_at

Equivalent to User.created_at

property default_avatar

Equivalent to User.default_avatar

property desktop_status: Status

The member’s status on the desktop client, if applicable.

property discriminator

Equivalent to User.discriminator

property display_avatar: Asset

Returns the member’s display avatar.

For regular members this is just their avatar, but if they have a guild specific avatar then that is returned instead.

Added in version 2.0.

property display_banner: Asset | None

Returns the member’s display banner.

For regular members this is just their banner, but if they have a guild specific banner then that is returned instead.

Added in version 2.7.

property display_name: str

Returns the user’s display name. This will either be their guild specific nickname, global name or username.

await edit(*, nick=Undefined.MISSING, mute=Undefined.MISSING, deafen=Undefined.MISSING, suppress=Undefined.MISSING, roles=Undefined.MISSING, voice_channel=Undefined.MISSING, reason=None, communication_disabled_until=Undefined.MISSING, bypass_verification=Undefined.MISSING, banner=Undefined.MISSING, avatar=Undefined.MISSING, bio=Undefined.MISSING)

This function is a coroutine.

Edits the member’s data.

Depending on the parameter passed, this requires different permissions listed below:

Parameter

Permission

nick

Permissions.manage_nicknames

mute

Permissions.mute_members

deafen

Permissions.deafen_members

roles

Permissions.manage_roles

voice_channel

Permissions.move_members

communication_disabled_until

Permissions.moderate_members

bypass_verification

See note below

Note

bypass_verification may be edited under three scenarios:

  • Client has Permissions.manage_guild

  • Client has Permissions.manage_roles

  • Client has ALL THREE of Permissions.moderate_members, Permissions.kick_members, and Permissions.ban_members

Note

The following parameters are only available when editing the bot’s own member:

  • avatar

  • banner

  • bio

All parameters are optional.

Changed in version 1.1: Can now pass None to voice_channel to kick a member from voice.

Changed in version 2.0: The newly member is now optionally returned, if applicable.

Parameters:
  • nick (Optional[str]) – The member’s new nickname. Use None to 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[Role]) – The member’s new list of roles. This replaces the roles.

  • voice_channel (Optional[Union[VoiceChannel, StageChannel]]) – The voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for editing this member. Shows up on the audit log.

  • communication_disabled_until (Optional[datetime.datetime]) –

    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 (Optional[bool]) –

    Indicates if the member should bypass the guild’s verification requirements.

    Added in version 2.6.

  • banner (Optional[bytes]) –

    A bytes-like object representing the banner. Could be None to 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.

  • avatar (Optional[bytes]) –

    A bytes-like object representing the avatar. Could be None to 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.

  • bio (Optional[str]) –

    The new bio for the member. Could be None to 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.

Returns:

The newly updated member, if applicable. This is only returned when certain fields are updated.

Return type:

Optional[Member]

Raises:
  • 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.

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 AsyncIterator that enables fetching the user’s entitlements.

This is identical to Client.entitlements() with the user parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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 get_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 the create_dm() coroutine function.

await get_mutual_guilds() list[Guild]

The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

Added in version 1.7.

get_role(role_id, /)

Returns a role with the given ID from roles which the member has.

Added in version 2.0.

Parameters:

role_id (int) – The ID to search for.

Returns:

The role or None if not found in the member’s roles.

Return type:

Optional[Role]

property global_name: str | None

The member’s global name, if applicable.

property guild_avatar: Asset | None

Returns an Asset for the guild avatar the member has. If unavailable, None is returned.

Added in version 2.0.

property guild_banner: Asset | None

Returns an Asset for the guild banner the member has. If unavailable, None is returned.

Added in version 2.7.

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.

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

property id

Equivalent to User.id

property is_migrated

Equivalent to User.is_migrated

is_on_mobile()

A helper function that determines if a member is active on a mobile device.

Return type:

bool

property jump_url

Equivalent to User.jump_url

await kick(*, reason=None)

This function is a coroutine.

Kicks this member. Equivalent to Guild.kick().

Parameters:

reason (str | None)

Return type:

None

property mention: str

Returns a string that allows you to mention the member.

mentioned_in(message)

Checks if the member is mentioned in the specified message.

Parameters:

message (Message) – The message to check if you’re mentioned in.

Returns:

Indicates if the member is mentioned in the message.

Return type:

bool

property mobile_status: Status

The member’s status on a mobile device, if applicable.

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_members permission to use this.

This raises the same exceptions as edit().

Changed in version 1.1: Can now pass None to kick a member from voice.

Parameters:
  • channel (Optional[Union[VoiceChannel, StageChannel]]) – The new voice channel to move the member to. Pass None to kick them from voice.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Return type:

None

property name

Equivalent to User.name

property nameplate

Equivalent to User.nameplate

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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 primary_guild

Equivalent to User.primary_guild

property public_flags

Equivalent to User.public_flags

property raw_status: str

The member’s overall status as a string value.

Added in version 1.5.

await remove_roles(*roles, reason=None, atomic=True)

This function is a coroutine.

Removes Roles from this member.

You must have the manage_roles permission to use this, and the removed Roles must appear lower in the list of roles than the highest role of the member.

Parameters:
  • *roles (abc.Snowflake) – An argument list of abc.Snowflake representing a Role to remove from the member.

  • reason (Optional[str]) – 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.

Raises:
  • Forbidden – You do not have permissions to remove these roles.

  • HTTPException – Removing the roles failed.

Return type:

None

await remove_timeout(*, reason=None)

This function is a coroutine.

Removes the timeout from a member.

You must have the moderate_members permission to remove the timeout.

This is equivalent to calling timeout() and passing None to the until parameter.

Parameters:

reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to remove the timeout.

  • HTTPException – An error occurred doing the request.

Return type:

None

await request_to_speak()

This function is a coroutine.

Request to speak in the connected channel.

Only applies to stage channels. :rtype: None

Note

Requesting members that are not the client is equivalent to edit providing suppress as False.

Added in version 1.7.

Raises:
  • Forbidden – You do not have the proper permissions to the action requested.

  • HTTPException – The operation failed.

property roles: list[Role]

A list of Role that 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.

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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property status: Status

The member’s overall status. If the value is unknown, then it will be a str instead.

property system

Equivalent to User.system

property timed_out: bool

Returns whether the member is timed out.

Added in version 2.0.

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_members permission to timeout a member.

Parameters:
  • until (datetime.datetime) – The date and time to timeout the member for. If this is None then the member is removed from timeout.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

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 to timeout(until=datetime.utcnow() + duration, reason=reason).

You must have the moderate_members permission to timeout a member.

Parameters:
  • duration (datetime.timedelta) – The duration to timeout the member for.

  • reason (Optional[str]) – The reason for doing this action. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to timeout members.

  • HTTPException – An error occurred doing the request.

Return type:

None

property top_role: Role

Returns the member’s highest role.

This is useful for figuring where a member stands in the role hierarchy chain.

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.

Return type:

None

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unban(*, reason=None)

This function is a coroutine.

Unbans this member. Equivalent to Guild.unban().

Parameters:

reason (str | None)

Return type:

None

property voice: VoiceState | None

Returns the member’s current voice state.

property web_status: Status

The member’s status on the web client, if applicable.

class discord.events.UserUpdate[source]

Called when a user updates their profile.

This is called when one or more of the following things change: - avatar - username - discriminator - global_name

This requires Intents.members to be enabled.

This event inherits from User.

old

The user’s old info before the update.

Type:

User

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.

Note

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.

Note

This information is only available via Client.fetch_user().

property avatar: Asset | None

Returns an Asset for the avatar the user has.

If the user does not have a traditional avatar, None is returned. If you want the avatar that a user has displayed, consider display_avatar.

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.

Note

This information is only available via Client.fetch_user().

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

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 DMChannel with this user.

This should be rarely called, as this is done transparently for most people.

Returns:

The channel that was created.

Return type:

DMChannel

await create_test_entitlement(sku)

This function is a coroutine.

Creates a test entitlement for the user.

Parameters:

sku (Snowflake) – The SKU to create a test entitlement for.

Returns:

The created entitlement.

Return type:

Entitlement

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.

For regular users this is just their default avatar or uploaded avatar.

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.

entitlements(skus=None, before=None, after=None, limit=100, exclude_ended=False)

Returns an AsyncIterator that enables fetching the user’s entitlements.

This is identical to Client.entitlements() with the user parameter.

Added in version 2.6.

Parameters:
  • 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. If None, retrieves every entitlement, which may be slow. Defaults to 100.

  • exclude_ended (bool) – Whether to limit the fetched entitlements to those that have not ended. Defaults to False.

Yields:

Entitlement – The application’s entitlements.

Raises:

HTTPException – Retrieving the entitlements failed.

Return type:

EntitlementIterator

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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 get_dm_channel()

Returns the channel associated with this user if it exists.

If this returns None, you can create a DM channel by calling the create_dm() coroutine function.

Return type:

DMChannel | None

await get_mutual_guilds()

The guilds that the user shares with the client. :rtype: list[Guild]

Note

This will only return mutual guilds within the client’s internal cache.

Added in version 1.7.

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

property is_migrated: bool

Checks whether the user is already migrated to global name.

property jump_url: str

Returns a URL that allows the client to jump to the user.

Added in version 2.0.

property mention: str

Returns a string that allows you to mention the given user.

mentioned_in(message)

Checks if the user is mentioned in the specified message.

Parameters:

message (Message) – The message to check if you’re mentioned in.

Returns:

Indicates if the user is mentioned in the message.

Return type:

bool

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
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.

Return type:

None

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
class discord.events.PresenceUpdate[source]

Called when a member updates their presence.

This is called when one or more of the following things change: - status - activity

This requires Intents.presences and Intents.members to be enabled.

old

The member’s old presence info.

Type:

Member

new

The member’s updated presence info.

Type:

Member

Messages

class discord.events.MessageCreate[source]

Called when a message is created and sent.

This requires Intents.messages to be enabled.

Warning

Your bot’s own messages and private messages are sent through this event. This can lead to cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking if author equals the bot user.

This event inherits from Message.

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 an AppEmoji.

You must have the read_message_history permission to use this. If nobody else has reacted to the message using this emoji, the add_reactions permission is required.

Parameters:

emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to react with.

Raises:
  • 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.

Return type:

None

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.

Note

This does not affect markdown. If you want to escape or remove markdown then use utils.escape_markdown() or utils.remove_markdown() respectively, along with this function.

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 an AppEmoji.

You need the manage_messages permission to use this.

Added in version 1.3.

Parameters:

emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to clear.

Raises:
  • 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.

Return type:

None

await clear_reactions()

This function is a coroutine.

Removes all the reactions from the message.

You need the manage_messages permission to use this.

Raises:
  • HTTPException – Removing the reactions failed.

  • Forbidden – You do not have the proper permissions to remove all the reactions.

Return type:

None

await create_thread(*, name, auto_archive_duration=Undefined.MISSING, slowmode_delay=Undefined.MISSING)

This function is a coroutine.

Creates a public thread from this message.

You must have create_public_threads in order to create a public thread from a message.

The channel this message belongs in must be a TextChannel.

Added in version 2.0.

Parameters:
  • name (str) – The name of the thread.

  • auto_archive_duration (Optional[int]) – 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 (Optional[int]) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

Returns:

The created thread.

Return type:

Thread

Raises:
property created_at: datetime

The message’s creation time in UTC.

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_messages permission.

Changed in version 1.1: Added the new delay keyword-only parameter.

Parameters:
  • delay (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the message. If the deletion fails then it is silently ignored.

  • reason (Optional[str]) – The reason for deleting the message. Shows up on the audit log.

Raises:
  • Forbidden – You do not have proper permissions to delete the message.

  • NotFound – The message was deleted already

  • HTTPException – Deleting the message failed.

Return type:

None

await edit(content=Undefined.MISSING, embed=Undefined.MISSING, embeds=Undefined.MISSING, file=Undefined.MISSING, files=Undefined.MISSING, attachments=Undefined.MISSING, suppress=Undefined.MISSING, delete_after=None, allowed_mentions=Undefined.MISSING, view=Undefined.MISSING)

This function is a coroutine.

Edits the message.

The content must be able to be transformed into a string via str(content).

Changed in version 1.3: The suppress keyword-only parameter was added.

Parameters:
  • content (Optional[str]) – The new content to replace the message with. Could be None to remove the content.

  • embed (Optional[Embed]) – The new embed to replace the original with. Could be None to remove the embed.

  • embeds (List[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.

  • file (Sequence[File]) – A new file to add to the message.

  • 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 to False this brings the embeds back if they were suppressed. Using this parameter requires manage_messages.

  • delete_after (Optional[float]) – 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 (Optional[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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • view (Optional[View]) – The updated view to update this message with. If None is passed then the view is removed.

Raises:
  • 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 embed and embeds, specified both file and files, or either``file`` or files were of the wrong type.

Return type:

Message

property edited_at: datetime | None

An aware UTC datetime object containing the edited time of the message.

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.

Returns:

The updated message.

Return type:

Message

Raises:
await forward_to(channel, **kwargs)

This function is a coroutine.

A shortcut method to abc.Messageable.send() to forward the Message to a channel.

Added in version 2.7.

Parameters:

channel (Union[TextChannel, Thread, DMChannel, GroupChannel, PartialMessageable]) – The channel to forward this to.

Returns:

The message that was sent.

Return type:

Message

Raises:
  • HTTPException – Sending the message failed.

  • Forbidden – You do not have the proper permissions to send the message.

  • InvalidArgument – The files list is not of the appropriate size, or you specified both file and files.

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. :rtype: bool

Added in version 1.3.

property jump_url: str

Returns a URL that allows the client to jump to this message.

await pin(*, reason=None)

This function is a coroutine.

Pins the message.

You must have the pin_messages permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) –

The reason for pinning the message. Shows up on the audit log.

Added in version 1.4.

Raises:
  • 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.

Return type:

None

await publish()

This function is a coroutine.

Publishes this message to your announcement channel.

You must have the send_messages permission to do this.

If the message is not your own then the manage_messages permission is also needed.

Raises:
  • Forbidden – You do not have the proper permissions to publish this message.

  • HTTPException – Publishing the message failed.

Return type:

None

raw_channel_mentions

A property that returns an array of channel IDs matched with the syntax of <#channel_id> in the message content.

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_role_mentions

A property that returns an array of role IDs matched with the syntax of <@&role_id> in the message content.

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 an AppEmoji.

If the reaction is not your own (i.e. member parameter is not you) then the manage_messages permission is needed.

The member parameter must represent a member and meet the abc.Snowflake abc.

Parameters:
  • emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to remove.

  • member (abc.Snowflake) – The member for which to remove the reaction.

Raises:
  • 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.

Return type:

None

await reply(content=None, **kwargs)

This function is a coroutine.

A shortcut method to abc.Messageable.send() to reply to the Message.

Added in version 1.6.

Returns:

The message that was sent.

Return type:

Message

Raises:
  • HTTPException – Sending the message failed.

  • Forbidden – You do not have the proper permissions to send the message.

  • InvalidArgument – The files list is not of the appropriate size, or you specified both file and files.

Parameters:

content (str | None)

system_content

A property that returns the content that is rendered regardless of the Message.type.

In the case of MessageType.default and MessageType.reply, this just returns the regular Message.content, and forwarded messages will display the original message’s content from Message.snapshots. Otherwise, this returns an English message denoting the contents of the system message.

to_reference(*, fail_if_not_exists=True, type=None)

Creates a MessageReference from the current message.

Added in version 1.6.

Parameters:
  • fail_if_not_exists (bool) –

    Whether replying using the message reference should raise HTTPException if the message no longer exists or Discord could not fetch the message.

    Added in version 1.7.

  • type (Optional[MessageReferenceType]) –

    The type of message reference. Defaults to a reply.

    Added in version 2.7.

Returns:

The reference to this message.

Return type:

MessageReference

await unpin(*, reason=None)

This function is a coroutine.

Unpins the message.

You must have the pin_messages permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) –

The reason for unpinning the message. Shows up on the audit log.

Added in version 1.4.

Raises:
  • 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.

Return type:

None

class discord.events.MessageUpdate[source]

Called when a message receives an update event.

This requires Intents.messages to be enabled.

The following non-exhaustive cases trigger this event: - A message has been pinned or unpinned. - The message content has been changed. - The message has received an embed. - The message’s embeds were suppressed or unsuppressed. - A call message has received an update to its participants or ending time. - A poll has ended and the results have been finalized.

This event inherits from Message.

raw

The raw event payload data.

Type:

RawMessageUpdateEvent

old

The previous version of the message (if it was cached).

Type:

Message | Undefined

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 an AppEmoji.

You must have the read_message_history permission to use this. If nobody else has reacted to the message using this emoji, the add_reactions permission is required.

Parameters:

emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to react with.

Raises:
  • 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.

Return type:

None

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.

Note

This does not affect markdown. If you want to escape or remove markdown then use utils.escape_markdown() or utils.remove_markdown() respectively, along with this function.

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 an AppEmoji.

You need the manage_messages permission to use this.

Added in version 1.3.

Parameters:

emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to clear.

Raises:
  • 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.

Return type:

None

await clear_reactions()

This function is a coroutine.

Removes all the reactions from the message.

You need the manage_messages permission to use this.

Raises:
  • HTTPException – Removing the reactions failed.

  • Forbidden – You do not have the proper permissions to remove all the reactions.

Return type:

None

await create_thread(*, name, auto_archive_duration=Undefined.MISSING, slowmode_delay=Undefined.MISSING)

This function is a coroutine.

Creates a public thread from this message.

You must have create_public_threads in order to create a public thread from a message.

The channel this message belongs in must be a TextChannel.

Added in version 2.0.

Parameters:
  • name (str) – The name of the thread.

  • auto_archive_duration (Optional[int]) – 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 (Optional[int]) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

Returns:

The created thread.

Return type:

Thread

Raises:
property created_at: datetime

The message’s creation time in UTC.

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_messages permission.

Changed in version 1.1: Added the new delay keyword-only parameter.

Parameters:
  • delay (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the message. If the deletion fails then it is silently ignored.

  • reason (Optional[str]) – The reason for deleting the message. Shows up on the audit log.

Raises:
  • Forbidden – You do not have proper permissions to delete the message.

  • NotFound – The message was deleted already

  • HTTPException – Deleting the message failed.

Return type:

None

await edit(content=Undefined.MISSING, embed=Undefined.MISSING, embeds=Undefined.MISSING, file=Undefined.MISSING, files=Undefined.MISSING, attachments=Undefined.MISSING, suppress=Undefined.MISSING, delete_after=None, allowed_mentions=Undefined.MISSING, view=Undefined.MISSING)

This function is a coroutine.

Edits the message.

The content must be able to be transformed into a string via str(content).

Changed in version 1.3: The suppress keyword-only parameter was added.

Parameters:
  • content (Optional[str]) – The new content to replace the message with. Could be None to remove the content.

  • embed (Optional[Embed]) – The new embed to replace the original with. Could be None to remove the embed.

  • embeds (List[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.

  • file (Sequence[File]) – A new file to add to the message.

  • 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 to False this brings the embeds back if they were suppressed. Using this parameter requires manage_messages.

  • delete_after (Optional[float]) – 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 (Optional[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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • view (Optional[View]) – The updated view to update this message with. If None is passed then the view is removed.

Raises:
  • 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 embed and embeds, specified both file and files, or either``file`` or files were of the wrong type.

Return type:

Message

property edited_at: datetime | None

An aware UTC datetime object containing the edited time of the message.

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.

Returns:

The updated message.

Return type:

Message

Raises:
await forward_to(channel, **kwargs)

This function is a coroutine.

A shortcut method to abc.Messageable.send() to forward the Message to a channel.

Added in version 2.7.

Parameters:

channel (Union[TextChannel, Thread, DMChannel, GroupChannel, PartialMessageable]) – The channel to forward this to.

Returns:

The message that was sent.

Return type:

Message

Raises:
  • HTTPException – Sending the message failed.

  • Forbidden – You do not have the proper permissions to send the message.

  • InvalidArgument – The files list is not of the appropriate size, or you specified both file and files.

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. :rtype: bool

Added in version 1.3.

property jump_url: str

Returns a URL that allows the client to jump to this message.

await pin(*, reason=None)

This function is a coroutine.

Pins the message.

You must have the pin_messages permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) –

The reason for pinning the message. Shows up on the audit log.

Added in version 1.4.

Raises:
  • 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.

Return type:

None

await publish()

This function is a coroutine.

Publishes this message to your announcement channel.

You must have the send_messages permission to do this.

If the message is not your own then the manage_messages permission is also needed.

Raises:
  • Forbidden – You do not have the proper permissions to publish this message.

  • HTTPException – Publishing the message failed.

Return type:

None

raw_channel_mentions

A property that returns an array of channel IDs matched with the syntax of <#channel_id> in the message content.

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_role_mentions

A property that returns an array of role IDs matched with the syntax of <@&role_id> in the message content.

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 an AppEmoji.

If the reaction is not your own (i.e. member parameter is not you) then the manage_messages permission is needed.

The member parameter must represent a member and meet the abc.Snowflake abc.

Parameters:
  • emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to remove.

  • member (abc.Snowflake) – The member for which to remove the reaction.

Raises:
  • 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.

Return type:

None

await reply(content=None, **kwargs)

This function is a coroutine.

A shortcut method to abc.Messageable.send() to reply to the Message.

Added in version 1.6.

Returns:

The message that was sent.

Return type:

Message

Raises:
  • HTTPException – Sending the message failed.

  • Forbidden – You do not have the proper permissions to send the message.

  • InvalidArgument – The files list is not of the appropriate size, or you specified both file and files.

Parameters:

content (str | None)

system_content

A property that returns the content that is rendered regardless of the Message.type.

In the case of MessageType.default and MessageType.reply, this just returns the regular Message.content, and forwarded messages will display the original message’s content from Message.snapshots. Otherwise, this returns an English message denoting the contents of the system message.

to_reference(*, fail_if_not_exists=True, type=None)

Creates a MessageReference from the current message.

Added in version 1.6.

Parameters:
  • fail_if_not_exists (bool) –

    Whether replying using the message reference should raise HTTPException if the message no longer exists or Discord could not fetch the message.

    Added in version 1.7.

  • type (Optional[MessageReferenceType]) –

    The type of message reference. Defaults to a reply.

    Added in version 2.7.

Returns:

The reference to this message.

Return type:

MessageReference

await unpin(*, reason=None)

This function is a coroutine.

Unpins the message.

You must have the pin_messages permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) –

The reason for unpinning the message. Shows up on the audit log.

Added in version 1.4.

Raises:
  • 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.

Return type:

None

class discord.events.MessageDelete[source]

Called when a message is deleted.

This requires Intents.messages to be enabled.

This event inherits from Message.

raw

The raw event payload data.

Type:

RawMessageDeleteEvent

is_cached

Whether the message was found in the internal cache.

Type:

bool

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 an AppEmoji.

You must have the read_message_history permission to use this. If nobody else has reacted to the message using this emoji, the add_reactions permission is required.

Parameters:

emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to react with.

Raises:
  • 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.

Return type:

None

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.

Note

This does not affect markdown. If you want to escape or remove markdown then use utils.escape_markdown() or utils.remove_markdown() respectively, along with this function.

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 an AppEmoji.

You need the manage_messages permission to use this.

Added in version 1.3.

Parameters:

emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to clear.

Raises:
  • 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.

Return type:

None

await clear_reactions()

This function is a coroutine.

Removes all the reactions from the message.

You need the manage_messages permission to use this.

Raises:
  • HTTPException – Removing the reactions failed.

  • Forbidden – You do not have the proper permissions to remove all the reactions.

Return type:

None

await create_thread(*, name, auto_archive_duration=Undefined.MISSING, slowmode_delay=Undefined.MISSING)

This function is a coroutine.

Creates a public thread from this message.

You must have create_public_threads in order to create a public thread from a message.

The channel this message belongs in must be a TextChannel.

Added in version 2.0.

Parameters:
  • name (str) – The name of the thread.

  • auto_archive_duration (Optional[int]) – 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 (Optional[int]) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

Returns:

The created thread.

Return type:

Thread

Raises:
property created_at: datetime

The message’s creation time in UTC.

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_messages permission.

Changed in version 1.1: Added the new delay keyword-only parameter.

Parameters:
  • delay (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the message. If the deletion fails then it is silently ignored.

  • reason (Optional[str]) – The reason for deleting the message. Shows up on the audit log.

Raises:
  • Forbidden – You do not have proper permissions to delete the message.

  • NotFound – The message was deleted already

  • HTTPException – Deleting the message failed.

Return type:

None

await edit(content=Undefined.MISSING, embed=Undefined.MISSING, embeds=Undefined.MISSING, file=Undefined.MISSING, files=Undefined.MISSING, attachments=Undefined.MISSING, suppress=Undefined.MISSING, delete_after=None, allowed_mentions=Undefined.MISSING, view=Undefined.MISSING)

This function is a coroutine.

Edits the message.

The content must be able to be transformed into a string via str(content).

Changed in version 1.3: The suppress keyword-only parameter was added.

Parameters:
  • content (Optional[str]) – The new content to replace the message with. Could be None to remove the content.

  • embed (Optional[Embed]) – The new embed to replace the original with. Could be None to remove the embed.

  • embeds (List[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.

  • file (Sequence[File]) – A new file to add to the message.

  • 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 to False this brings the embeds back if they were suppressed. Using this parameter requires manage_messages.

  • delete_after (Optional[float]) – 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 (Optional[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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • view (Optional[View]) – The updated view to update this message with. If None is passed then the view is removed.

Raises:
  • 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 embed and embeds, specified both file and files, or either``file`` or files were of the wrong type.

Return type:

Message

property edited_at: datetime | None

An aware UTC datetime object containing the edited time of the message.

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.

Returns:

The updated message.

Return type:

Message

Raises:
await forward_to(channel, **kwargs)

This function is a coroutine.

A shortcut method to abc.Messageable.send() to forward the Message to a channel.

Added in version 2.7.

Parameters:

channel (Union[TextChannel, Thread, DMChannel, GroupChannel, PartialMessageable]) – The channel to forward this to.

Returns:

The message that was sent.

Return type:

Message

Raises:
  • HTTPException – Sending the message failed.

  • Forbidden – You do not have the proper permissions to send the message.

  • InvalidArgument – The files list is not of the appropriate size, or you specified both file and files.

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. :rtype: bool

Added in version 1.3.

property jump_url: str

Returns a URL that allows the client to jump to this message.

await pin(*, reason=None)

This function is a coroutine.

Pins the message.

You must have the pin_messages permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) –

The reason for pinning the message. Shows up on the audit log.

Added in version 1.4.

Raises:
  • 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.

Return type:

None

await publish()

This function is a coroutine.

Publishes this message to your announcement channel.

You must have the send_messages permission to do this.

If the message is not your own then the manage_messages permission is also needed.

Raises:
  • Forbidden – You do not have the proper permissions to publish this message.

  • HTTPException – Publishing the message failed.

Return type:

None

raw_channel_mentions

A property that returns an array of channel IDs matched with the syntax of <#channel_id> in the message content.

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_role_mentions

A property that returns an array of role IDs matched with the syntax of <@&role_id> in the message content.

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 an AppEmoji.

If the reaction is not your own (i.e. member parameter is not you) then the manage_messages permission is needed.

The member parameter must represent a member and meet the abc.Snowflake abc.

Parameters:
  • emoji (Union[GuildEmoji, AppEmoji, Reaction, PartialEmoji, str]) – The emoji to remove.

  • member (abc.Snowflake) – The member for which to remove the reaction.

Raises:
  • 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.

Return type:

None

await reply(content=None, **kwargs)

This function is a coroutine.

A shortcut method to abc.Messageable.send() to reply to the Message.

Added in version 1.6.

Returns:

The message that was sent.

Return type:

Message

Raises:
  • HTTPException – Sending the message failed.

  • Forbidden – You do not have the proper permissions to send the message.

  • InvalidArgument – The files list is not of the appropriate size, or you specified both file and files.

Parameters:

content (str | None)

system_content

A property that returns the content that is rendered regardless of the Message.type.

In the case of MessageType.default and MessageType.reply, this just returns the regular Message.content, and forwarded messages will display the original message’s content from Message.snapshots. Otherwise, this returns an English message denoting the contents of the system message.

to_reference(*, fail_if_not_exists=True, type=None)

Creates a MessageReference from the current message.

Added in version 1.6.

Parameters:
  • fail_if_not_exists (bool) –

    Whether replying using the message reference should raise HTTPException if the message no longer exists or Discord could not fetch the message.

    Added in version 1.7.

  • type (Optional[MessageReferenceType]) –

    The type of message reference. Defaults to a reply.

    Added in version 2.7.

Returns:

The reference to this message.

Return type:

MessageReference

await unpin(*, reason=None)

This function is a coroutine.

Unpins the message.

You must have the pin_messages permission to do this in a non-private channel context.

Parameters:

reason (Optional[str]) –

The reason for unpinning the message. Shows up on the audit log.

Added in version 1.4.

Raises:
  • 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.

Return type:

None

class discord.events.MessageDeleteBulk[source]

Called when messages are bulk deleted.

This requires Intents.messages to be enabled.

raw

The raw event payload data.

Type:

RawBulkMessageDeleteEvent

messages

The messages that have been deleted (only includes cached messages).

Type:

list[Message]

Reactions

class discord.events.ReactionAdd[source]

Called when a message has a reaction added to it.

This requires Intents.reactions to be enabled.

Note

To get the Message being reacted to, access it via reaction.message.

raw

The raw event payload data.

Type:

RawReactionActionEvent

user

The user who added the reaction.

Type:

Member | User | Undefined

reaction

The current state of the reaction.

Type:

Reaction

class discord.events.ReactionRemove[source]

Called when a message has a reaction removed from it.

This requires Intents.reactions to be enabled.

Note

To get the Message being reacted to, access it via reaction.message.

raw

The raw event payload data.

Type:

RawReactionActionEvent

user

The user who removed the reaction.

Type:

Member | User | Undefined

reaction

The current state of the reaction.

Type:

Reaction

class discord.events.ReactionClear[source]

Called when a message has all its reactions removed from it.

This requires Intents.reactions to be enabled.

raw

The raw event payload data.

Type:

RawReactionClearEvent

message

The message that had its reactions cleared.

Type:

Message | Undefined

old_reactions

The reactions that were removed.

Type:

list[Reaction] | Undefined

class discord.events.ReactionRemoveEmoji[source]

Called when a message has a specific reaction removed from it.

This requires Intents.reactions to be enabled.

This event inherits from Reaction.

property burst_colors: list[Colour]

Returns a list possible Colour this super reaction can be.

There is an alias for this named burst_colours.

property burst_colours: list[Colour]

Returns a list possible Colour this super reaction can be.

There is an alias for this named burst_colors.

await clear()

This function is a coroutine.

Clears this reaction from the message.

You need the manage_messages permission to use this. :rtype: None

Added in version 1.3.

Raises:
  • 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.

property count_details

Returns ReactionCountDetails for the individual counts of normal and super reactions made.

is_custom_emoji()

If this is a custom emoji.

Return type:

bool

await remove(user)

This function is a coroutine.

Remove the reaction by the provided User from the message.

If the reaction is not your own (i.e. user parameter is not you) then the manage_messages permission is needed.

The user parameter must represent a user or member and meet the abc.Snowflake abc.

Parameters:

user (abc.Snowflake) – The user or member from which to remove the reaction.

Raises:
  • 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.

Return type:

None

users(*, limit=None, after=None, type=None)

Returns an AsyncIterator representing the users that have reacted to the message.

The after parameter must represent a member and meet the abc.Snowflake abc.

Parameters:
  • limit (Optional[int]) – The maximum number of results to return. If not provided, returns all the users who reacted to the message.

  • after (Optional[abc.Snowflake]) – For pagination, reactions are sorted by member.

  • type (Optional[ReactionType]) – The type of reaction to get users for. Defaults to normal.

Yields:

Union[User, Member] – The member (if retrievable) or the user that has reacted to this message. The case where it can be a Member is in a guild message context. Sometimes it can be a User if the member has left the guild.

Raises:

HTTPException – Getting the users for the reaction failed.

Return type:

ReactionIterator

Examples

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()

Polls

class discord.events.PollVoteAdd[source]

Called when a vote is cast on a poll.

This requires Intents.polls to be enabled.

raw

The raw event payload data.

Type:

RawMessagePollVoteEvent

guild

The guild where the poll vote occurred, if in a guild.

Type:

Guild | Undefined

user

The user who added the vote.

Type:

User | Member | None

poll

The current state of the poll.

Type:

Poll

answer

The answer that was voted for.

Type:

PollAnswer

class discord.events.PollVoteRemove[source]

Called when a vote is removed from a poll.

This requires Intents.polls to be enabled.

raw

The raw event payload data.

Type:

RawMessagePollVoteEvent

guild

The guild where the poll vote occurred, if in a guild.

Type:

Guild | Undefined

user

The user who removed the vote.

Type:

User | Member | None

poll

The current state of the poll.

Type:

Poll

answer

The answer that had its vote removed.

Type:

PollAnswer

Scheduled Events

class discord.events.GuildScheduledEventCreate[source]

Called when a scheduled event is created.

This requires Intents.scheduled_events to be enabled.

This event inherits from ScheduledEvent.

await cancel(*, reason=None)

This function is a coroutine.

Cancels the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.scheduled.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
await complete(*, reason=None)

This function is a coroutine.

Ends/completes the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.active.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
property cover: Asset | None

Returns the scheduled event cover image asset, if available.

Deprecated since version 2.7: Use the image property instead.

property created_at: datetime

Returns the scheduled event’s creation time in UTC.

await delete()

This function is a coroutine.

Deletes the scheduled event.

Raises:
Return type:

None

await edit(*, reason=None, name=Undefined.MISSING, description=Undefined.MISSING, status=Undefined.MISSING, location=Undefined.MISSING, start_time=Undefined.MISSING, end_time=Undefined.MISSING, cover=Undefined.MISSING, image=Undefined.MISSING, privacy_level=ScheduledEventPrivacyLevel.guild_only)

This function is a coroutine.

Edits the Scheduled Event’s data

All parameters are optional unless location.type is ScheduledEventLocationType.external, then end_time is required.

Will return a new ScheduledEvent object if applicable.

Parameters:
  • name (str) – The new name of the event.

  • description (str) – The new description of the event.

  • location (ScheduledEventLocation) – The location of the event.

  • status (ScheduledEventStatus) – The status of the event. It is recommended, however, to use start(), complete(), and cancel() to edit statuses instead.

  • start_time (datetime.datetime) – The new starting time for the event.

  • end_time (datetime.datetime) – The new ending time of the event.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event.

  • cover (Optional[bytes]) –

    The cover image of the scheduled event.

    Deprecated since version 2.7: Use the image argument instead.

Returns:

The newly updated scheduled event object. This is only returned when certain fields are updated.

Return type:

Optional[ScheduledEvent]

Raises:
property image: Asset | None

Returns the scheduled event cover image asset, if available.

property interested: int | None

An alias to subscriber_count

await start(*, reason=None)

This function is a coroutine.

Starts the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.scheduled.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
subscribers(*, limit=100, as_member=False, before=None, after=None)

Returns an AsyncIterator representing the users or members subscribed to the event.

The after and before parameters must represent member or user objects and meet the abc.Snowflake abc.

Note

Even is as_member is set to True, if the user is outside the guild, it will be a User object.

Parameters:
  • limit (Optional[int]) – The maximum number of results to return.

  • as_member (Optional[bool]) – Whether to fetch Member objects instead of user objects. There may still be User objects if the user is outside the guild.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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 (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Union[User, Member] – The subscribed Member. If as_member is set to False or the user is outside the guild, it will be a User object.

Raises:

HTTPException – Fetching the subscribed users failed.

Return type:

ScheduledEventSubscribersIterator

Examples

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)
property url: str

The url to reference the scheduled event.

class discord.events.GuildScheduledEventUpdate[source]

Called when a scheduled event is updated.

This requires Intents.scheduled_events to be enabled.

This event inherits from ScheduledEvent.

old

The old scheduled event before the update.

Type:

ScheduledEvent

await cancel(*, reason=None)

This function is a coroutine.

Cancels the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.scheduled.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
await complete(*, reason=None)

This function is a coroutine.

Ends/completes the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.active.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
property cover: Asset | None

Returns the scheduled event cover image asset, if available.

Deprecated since version 2.7: Use the image property instead.

property created_at: datetime

Returns the scheduled event’s creation time in UTC.

await delete()

This function is a coroutine.

Deletes the scheduled event.

Raises:
Return type:

None

await edit(*, reason=None, name=Undefined.MISSING, description=Undefined.MISSING, status=Undefined.MISSING, location=Undefined.MISSING, start_time=Undefined.MISSING, end_time=Undefined.MISSING, cover=Undefined.MISSING, image=Undefined.MISSING, privacy_level=ScheduledEventPrivacyLevel.guild_only)

This function is a coroutine.

Edits the Scheduled Event’s data

All parameters are optional unless location.type is ScheduledEventLocationType.external, then end_time is required.

Will return a new ScheduledEvent object if applicable.

Parameters:
  • name (str) – The new name of the event.

  • description (str) – The new description of the event.

  • location (ScheduledEventLocation) – The location of the event.

  • status (ScheduledEventStatus) – The status of the event. It is recommended, however, to use start(), complete(), and cancel() to edit statuses instead.

  • start_time (datetime.datetime) – The new starting time for the event.

  • end_time (datetime.datetime) – The new ending time of the event.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event.

  • cover (Optional[bytes]) –

    The cover image of the scheduled event.

    Deprecated since version 2.7: Use the image argument instead.

Returns:

The newly updated scheduled event object. This is only returned when certain fields are updated.

Return type:

Optional[ScheduledEvent]

Raises:
property image: Asset | None

Returns the scheduled event cover image asset, if available.

property interested: int | None

An alias to subscriber_count

await start(*, reason=None)

This function is a coroutine.

Starts the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.scheduled.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
subscribers(*, limit=100, as_member=False, before=None, after=None)

Returns an AsyncIterator representing the users or members subscribed to the event.

The after and before parameters must represent member or user objects and meet the abc.Snowflake abc.

Note

Even is as_member is set to True, if the user is outside the guild, it will be a User object.

Parameters:
  • limit (Optional[int]) – The maximum number of results to return.

  • as_member (Optional[bool]) – Whether to fetch Member objects instead of user objects. There may still be User objects if the user is outside the guild.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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 (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Union[User, Member] – The subscribed Member. If as_member is set to False or the user is outside the guild, it will be a User object.

Raises:

HTTPException – Fetching the subscribed users failed.

Return type:

ScheduledEventSubscribersIterator

Examples

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)
property url: str

The url to reference the scheduled event.

class discord.events.GuildScheduledEventDelete[source]

Called when a scheduled event is deleted.

This requires Intents.scheduled_events to be enabled.

This event inherits from ScheduledEvent.

await cancel(*, reason=None)

This function is a coroutine.

Cancels the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.scheduled.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
await complete(*, reason=None)

This function is a coroutine.

Ends/completes the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.active.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
property cover: Asset | None

Returns the scheduled event cover image asset, if available.

Deprecated since version 2.7: Use the image property instead.

property created_at: datetime

Returns the scheduled event’s creation time in UTC.

await delete()

This function is a coroutine.

Deletes the scheduled event.

Raises:
Return type:

None

await edit(*, reason=None, name=Undefined.MISSING, description=Undefined.MISSING, status=Undefined.MISSING, location=Undefined.MISSING, start_time=Undefined.MISSING, end_time=Undefined.MISSING, cover=Undefined.MISSING, image=Undefined.MISSING, privacy_level=ScheduledEventPrivacyLevel.guild_only)

This function is a coroutine.

Edits the Scheduled Event’s data

All parameters are optional unless location.type is ScheduledEventLocationType.external, then end_time is required.

Will return a new ScheduledEvent object if applicable.

Parameters:
  • name (str) – The new name of the event.

  • description (str) – The new description of the event.

  • location (ScheduledEventLocation) – The location of the event.

  • status (ScheduledEventStatus) – The status of the event. It is recommended, however, to use start(), complete(), and cancel() to edit statuses instead.

  • start_time (datetime.datetime) – The new starting time for the event.

  • end_time (datetime.datetime) – The new ending time of the event.

  • privacy_level (ScheduledEventPrivacyLevel) – The privacy level of the event. Currently, the only possible value is ScheduledEventPrivacyLevel.guild_only, which is default, so there is no need to change this parameter.

  • reason (Optional[str]) – The reason to show in the audit log.

  • image (Optional[bytes]) – The cover image of the scheduled event.

  • cover (Optional[bytes]) –

    The cover image of the scheduled event.

    Deprecated since version 2.7: Use the image argument instead.

Returns:

The newly updated scheduled event object. This is only returned when certain fields are updated.

Return type:

Optional[ScheduledEvent]

Raises:
property image: Asset | None

Returns the scheduled event cover image asset, if available.

property interested: int | None

An alias to subscriber_count

await start(*, reason=None)

This function is a coroutine.

Starts the scheduled event. Shortcut from edit().

Note

This method can only be used if status is ScheduledEventStatus.scheduled.

Parameters:

reason (Optional[str]) – The reason to show in the audit log.

Returns:

The newly updated scheduled event object.

Return type:

Optional[ScheduledEvent]

Raises:
subscribers(*, limit=100, as_member=False, before=None, after=None)

Returns an AsyncIterator representing the users or members subscribed to the event.

The after and before parameters must represent member or user objects and meet the abc.Snowflake abc.

Note

Even is as_member is set to True, if the user is outside the guild, it will be a User object.

Parameters:
  • limit (Optional[int]) – The maximum number of results to return.

  • as_member (Optional[bool]) – Whether to fetch Member objects instead of user objects. There may still be User objects if the user is outside the guild.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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 (Optional[Union[abc.Snowflake, datetime.datetime]]) – 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.

Yields:

Union[User, Member] – The subscribed Member. If as_member is set to False or the user is outside the guild, it will be a User object.

Raises:

HTTPException – Fetching the subscribed users failed.

Return type:

ScheduledEventSubscribersIterator

Examples

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)
property url: str

The url to reference the scheduled event.

class discord.events.GuildScheduledEventUserAdd[source]

Called when a user subscribes to a scheduled event.

This requires Intents.scheduled_events to be enabled.

event

The scheduled event subscribed to.

Type:

ScheduledEvent

member

The member who subscribed.

Type:

Member

raw

The raw event payload data.

Type:

RawScheduledEventSubscription

class discord.events.GuildScheduledEventUserRemove[source]

Called when a user unsubscribes from a scheduled event.

This requires Intents.scheduled_events to be enabled.

event

The scheduled event unsubscribed from.

Type:

ScheduledEvent

member

The member who unsubscribed.

Type:

Member

raw

The raw event payload data.

Type:

RawScheduledEventSubscription

Soundboard

class discord.events.GuildSoundboardSoundCreate(sound)[source]

Called when a soundboard sound is created.

This event inherits from SoundboardSound.

Parameters:

sound (SoundboardSound)

class discord.events.GuildSoundboardSoundUpdate(before, after)[source]

Called when a soundboard sound is updated.

old

The soundboard sound prior to being updated (if it was cached).

Type:

SoundboardSound | None

new

The soundboard sound after being updated.

Type:

SoundboardSound

Parameters:
class discord.events.GuildSoundboardSoundDelete(sound, raw)[source]

Called when a soundboard sound is deleted.

raw

The raw event payload data.

Type:

RawSoundboardSoundDeleteEvent

sound

The deleted sound (if it was cached).

Type:

SoundboardSound | None

Parameters:
class discord.events.GuildSoundboardSoundsUpdate(before_sounds, after_sounds)[source]

Called when multiple guild soundboard sounds are updated at once.

This is called, for example, when a guild loses a boost level and some sounds become unavailable.

old_sounds

The soundboard sounds prior to being updated (only if all were cached).

Type:

list[SoundboardSound] | None

new_sounds

The soundboard sounds after being updated.

Type:

list[SoundboardSound]

Parameters:

Stage Instances

class discord.events.StageInstanceCreate[source]

Called when a stage instance is created for a stage channel.

This event inherits from StageInstance.

await delete(*, reason=None)

This function is a coroutine.

Deletes the stage instance.

You must have the manage_channels permission to use this.

Parameters:

reason (str) – The reason the stage instance was deleted. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to delete the stage instance.

  • HTTPException – Deleting the stage instance failed.

Return type:

None

await edit(*, topic=Undefined.MISSING, privacy_level=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the stage instance.

You must have the manage_channels permission to use this.

Parameters:
  • topic (str) – The stage instance’s new topic.

  • privacy_level (StagePrivacyLevel) – The stage instance’s new privacy level.

  • reason (str) – The reason the stage instance was edited. Shows up on the audit log.

Raises:
  • InvalidArgument – If the privacy_level parameter is not the proper type.

  • Forbidden – You do not have permissions to edit the stage instance.

  • HTTPException – Editing a stage instance failed.

Return type:

None

await get_channel()

The channel that stage instance is running in.

Return type:

StageChannel | None

class discord.events.StageInstanceUpdate[source]

Called when a stage instance is updated.

The following, but not limited to, examples illustrate when this event is called: - The topic is changed. - The privacy level is changed.

This event inherits from StageInstance.

old

The stage instance before the update.

Type:

StageInstance

await delete(*, reason=None)

This function is a coroutine.

Deletes the stage instance.

You must have the manage_channels permission to use this.

Parameters:

reason (str) – The reason the stage instance was deleted. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to delete the stage instance.

  • HTTPException – Deleting the stage instance failed.

Return type:

None

await edit(*, topic=Undefined.MISSING, privacy_level=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the stage instance.

You must have the manage_channels permission to use this.

Parameters:
  • topic (str) – The stage instance’s new topic.

  • privacy_level (StagePrivacyLevel) – The stage instance’s new privacy level.

  • reason (str) – The reason the stage instance was edited. Shows up on the audit log.

Raises:
  • InvalidArgument – If the privacy_level parameter is not the proper type.

  • Forbidden – You do not have permissions to edit the stage instance.

  • HTTPException – Editing a stage instance failed.

Return type:

None

await get_channel()

The channel that stage instance is running in.

Return type:

StageChannel | None

class discord.events.StageInstanceDelete[source]

Called when a stage instance is deleted for a stage channel.

This event inherits from StageInstance.

await delete(*, reason=None)

This function is a coroutine.

Deletes the stage instance.

You must have the manage_channels permission to use this.

Parameters:

reason (str) – The reason the stage instance was deleted. Shows up on the audit log.

Raises:
  • Forbidden – You do not have permissions to delete the stage instance.

  • HTTPException – Deleting the stage instance failed.

Return type:

None

await edit(*, topic=Undefined.MISSING, privacy_level=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the stage instance.

You must have the manage_channels permission to use this.

Parameters:
  • topic (str) – The stage instance’s new topic.

  • privacy_level (StagePrivacyLevel) – The stage instance’s new privacy level.

  • reason (str) – The reason the stage instance was edited. Shows up on the audit log.

Raises:
  • InvalidArgument – If the privacy_level parameter is not the proper type.

  • Forbidden – You do not have permissions to edit the stage instance.

  • HTTPException – Editing a stage instance failed.

Return type:

None

await get_channel()

The channel that stage instance is running in.

Return type:

StageChannel | None

Threads

class discord.events.ThreadCreate[source]

Called whenever a thread is created.

Note that you can get the guild from Thread.guild.

This requires Intents.guilds to be enabled.

This event inherits from Thread.

just_joined

Whether the bot just joined the thread.

Type:

bool

await add_user(user)

This function is a coroutine.

Adds a user to this thread.

You must have send_messages_in_threads to add a user to a public thread. If the thread is private and invitable is False, then manage_threads is required.

Parameters:

user (abc.Snowflake) – The user to add to the thread.

Raises:
  • Forbidden – You do not have permissions to add the user to the thread.

  • HTTPException – Adding the user to the thread failed.

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]

await archive(locked=Undefined.MISSING)

This function is a coroutine.

Archives the thread. This is a shorthand of edit().

Parameters:

locked (bool) – Whether to lock the thread on archive, Defaults to False.

Returns:

The updated thread.

Return type:

Thread

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property category: CategoryChannel | None

The category channel the parent channel belongs to, if applicable.

Returns:

The parent channel’s category.

Return type:

Optional[CategoryChannel]

Raises:

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.

Returns:

The parent channel’s category ID.

Return type:

Optional[int]

Raises:

ClientException – The parent channel was not cached and returned None.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • Forbidden – You do not have the proper permissions to create this channel.

  • HTTPException – Creating the channel failed.

await create_webhook(*, name, avatar=None, reason=None)

This function is a coroutine.

Creates a webhook for this channel.

Requires manage_webhooks permissions.

Changed in version 1.1: Added the reason keyword-only parameter.

Parameters:
  • name (str) – The webhook’s name.

  • avatar (Optional[bytes]) – A bytes-like object representing the webhook’s default avatar. This operates similarly to edit().

  • reason (Optional[str]) – The reason for creating this webhook. Shows up in the audit logs.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Creating the webhook failed.

  • Forbidden – You do not have permissions to create a webhook.

created_at
await delete()

This function is a coroutine.

Deletes this thread.

You must have manage_threads to delete threads.

Raises:
  • Forbidden – You do not have permissions to delete this thread.

  • HTTPException – Deleting the thread failed.

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_messages permission to use this.

Usable only by bot accounts.

Parameters:
  • messages (Iterable[abc.Snowflake]) – An iterable of messages denoting which ones to bulk delete.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Raises:
  • 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.

Return type:

None

await edit(*, name=Undefined.MISSING, archived=Undefined.MISSING, locked=Undefined.MISSING, invitable=Undefined.MISSING, slowmode_delay=Undefined.MISSING, auto_archive_duration=Undefined.MISSING, pinned=Undefined.MISSING, applied_tags=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the thread.

Editing the thread requires Permissions.manage_threads. The thread creator can also edit name, archived or auto_archive_duration. Note that if the thread is locked then only those with Permissions.manage_threads can send messages in it or unarchive a thread.

The thread must be unarchived to be edited.

Parameters:
  • 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 (int) – The new duration in minutes before a thread is automatically archived for inactivity. Must be one of 60, 1440, 4320, or 10080. ThreadArchiveDuration can be used alternatively.

  • slowmode_delay (int) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

  • reason (Optional[str]) – 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.

Returns:

The newly edited thread.

Return type:

Thread

Raises:
await fetch_members()

This function is a coroutine.

Retrieves all ThreadMember that are in this thread.

This requires Intents.members to get information about members other than yourself.

Returns:

All thread members in the thread.

Return type:

List[ThreadMember]

Raises:

HTTPException – Retrieving the members failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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.

Note

The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.

Added in version 1.3.

Parameters:
  • destination (TextChannel) – The channel you would like to follow from.

  • reason (Optional[str]) –

    The reason for following the channel. Shows up on the destination guild’s audit log.

    Added in version 1.4.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Following the channel failed.

  • Forbidden – You do not have the permissions to create a webhook.

await get_last_message()

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() or fetch_message() with the last_message_id attribute.

Returns:

The last message in this channel or None if not found.

Return type:

Optional[Message]

await get_members()

Returns all members that can see this channel.

Return type:

list[Member]

await get_owner()

The member this thread belongs to.

Return type:

Member | None

get_partial_message(message_id, /)

Creates a PartialMessage from 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.

Parameters:

message_id (int) – The message ID to create a partial message for.

Returns:

The partial message.

Return type:

PartialMessage

await get_starting_message()

Returns the message that started this thread.

The message might not be valid or point to an existing message.

Note

The ID for this message is the same as the thread ID.

Returns:

The message that started this thread or None if not found in the cache.

Return type:

Optional[Message]

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

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() is True.

Return type:

bool

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() is True.

Return type:

bool

is_pinned()

Whether the thread is pinned to the top of its parent forum or media channel. :rtype: bool

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.

Return type:

bool

await join()

This function is a coroutine.

Joins this thread.

You must have send_messages_in_threads to join a thread. If the thread is private, manage_threads is also needed.

Raises:
property jump_url: str

Returns a URL that allows the client to jump to the thread.

Added in version 2.0.

await leave()

This function is a coroutine.

Leaves this thread.

Raises:

HTTPException – Leaving the thread failed.

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.members to be properly filled. Most of the time however, this data is not provided by the gateway and a call to fetch_members() is needed.

property mention: str

The string that allows you to mention the thread.

property nsfw: bool

Whether the thread is NSFW. Inherited from parent channel.

property parent: TextChannel | ForumChannel | None

The parent channel this thread belongs to.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

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.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

Raises:

ClientException – The parent channel was not cached and returned None

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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=Undefined.MISSING, 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 a check is not provided then all messages are deleted without discrimination.

You must have the manage_messages permission to delete messages even if they are your own (unless you are a user account). The read_message_history permission is also needed to retrieve message history.

Parameters:
  • limit (Optional[int]) – 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 a Message as its sole parameter.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as before in history().

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as after in history().

  • around (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as around in history().

  • oldest_first (Optional[bool]) – Same as oldest_first in history().

  • bulk (bool) – If True, use bulk delete. Setting this to False is useful for mass-deleting a bot’s own messages without Permissions.manage_messages. When True, will fall back to single delete if messages are older than two weeks.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Returns:

The list of messages that were deleted.

Return type:

List[Message]

Raises:
  • Forbidden – You do not have proper permissions to do the actions required.

  • HTTPException – Purging the messages failed.

Examples

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 remove_user(user)

This function is a coroutine.

Removes a user from this thread.

You must have manage_threads or be the creator of the thread to remove a user.

Parameters:

user (abc.Snowflake) – The user to remove from the thread.

Raises:
  • Forbidden – You do not have permissions to remove the user from the thread.

  • HTTPException – Removing the user from the thread 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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property topic: None

Threads don’t have topics. Always returns None.

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.

Return type:

None

property type: ChannelType

The channel’s Discord type.

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unarchive()

This function is a coroutine.

Unarchives the thread. This is a shorthand of edit().

Returns:

The updated thread.

Return type:

Thread

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this channel.

Requires manage_webhooks permissions.

Returns:

The webhooks for this channel.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

class discord.events.ThreadUpdate[source]

Called whenever a thread is updated.

This requires Intents.guilds to be enabled.

This event inherits from Thread.

old

The thread’s old info before the update.

Type:

Thread

await add_user(user)

This function is a coroutine.

Adds a user to this thread.

You must have send_messages_in_threads to add a user to a public thread. If the thread is private and invitable is False, then manage_threads is required.

Parameters:

user (abc.Snowflake) – The user to add to the thread.

Raises:
  • Forbidden – You do not have permissions to add the user to the thread.

  • HTTPException – Adding the user to the thread failed.

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]

await archive(locked=Undefined.MISSING)

This function is a coroutine.

Archives the thread. This is a shorthand of edit().

Parameters:

locked (bool) – Whether to lock the thread on archive, Defaults to False.

Returns:

The updated thread.

Return type:

Thread

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property category: CategoryChannel | None

The category channel the parent channel belongs to, if applicable.

Returns:

The parent channel’s category.

Return type:

Optional[CategoryChannel]

Raises:

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.

Returns:

The parent channel’s category ID.

Return type:

Optional[int]

Raises:

ClientException – The parent channel was not cached and returned None.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • Forbidden – You do not have the proper permissions to create this channel.

  • HTTPException – Creating the channel failed.

await create_webhook(*, name, avatar=None, reason=None)

This function is a coroutine.

Creates a webhook for this channel.

Requires manage_webhooks permissions.

Changed in version 1.1: Added the reason keyword-only parameter.

Parameters:
  • name (str) – The webhook’s name.

  • avatar (Optional[bytes]) – A bytes-like object representing the webhook’s default avatar. This operates similarly to edit().

  • reason (Optional[str]) – The reason for creating this webhook. Shows up in the audit logs.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Creating the webhook failed.

  • Forbidden – You do not have permissions to create a webhook.

await delete()

This function is a coroutine.

Deletes this thread.

You must have manage_threads to delete threads.

Raises:
  • Forbidden – You do not have permissions to delete this thread.

  • HTTPException – Deleting the thread failed.

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_messages permission to use this.

Usable only by bot accounts.

Parameters:
  • messages (Iterable[abc.Snowflake]) – An iterable of messages denoting which ones to bulk delete.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Raises:
  • 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.

Return type:

None

await edit(*, name=Undefined.MISSING, archived=Undefined.MISSING, locked=Undefined.MISSING, invitable=Undefined.MISSING, slowmode_delay=Undefined.MISSING, auto_archive_duration=Undefined.MISSING, pinned=Undefined.MISSING, applied_tags=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the thread.

Editing the thread requires Permissions.manage_threads. The thread creator can also edit name, archived or auto_archive_duration. Note that if the thread is locked then only those with Permissions.manage_threads can send messages in it or unarchive a thread.

The thread must be unarchived to be edited.

Parameters:
  • 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 (int) – The new duration in minutes before a thread is automatically archived for inactivity. Must be one of 60, 1440, 4320, or 10080. ThreadArchiveDuration can be used alternatively.

  • slowmode_delay (int) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

  • reason (Optional[str]) – 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.

Returns:

The newly edited thread.

Return type:

Thread

Raises:
await fetch_members()

This function is a coroutine.

Retrieves all ThreadMember that are in this thread.

This requires Intents.members to get information about members other than yourself.

Returns:

All thread members in the thread.

Return type:

List[ThreadMember]

Raises:

HTTPException – Retrieving the members failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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.

Note

The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.

Added in version 1.3.

Parameters:
  • destination (TextChannel) – The channel you would like to follow from.

  • reason (Optional[str]) –

    The reason for following the channel. Shows up on the destination guild’s audit log.

    Added in version 1.4.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Following the channel failed.

  • Forbidden – You do not have the permissions to create a webhook.

await get_last_message()

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() or fetch_message() with the last_message_id attribute.

Returns:

The last message in this channel or None if not found.

Return type:

Optional[Message]

await get_members()

Returns all members that can see this channel.

Return type:

list[Member]

await get_owner()

The member this thread belongs to.

Return type:

Member | None

get_partial_message(message_id, /)

Creates a PartialMessage from 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.

Parameters:

message_id (int) – The message ID to create a partial message for.

Returns:

The partial message.

Return type:

PartialMessage

await get_starting_message()

Returns the message that started this thread.

The message might not be valid or point to an existing message.

Note

The ID for this message is the same as the thread ID.

Returns:

The message that started this thread or None if not found in the cache.

Return type:

Optional[Message]

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

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() is True.

Return type:

bool

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() is True.

Return type:

bool

is_pinned()

Whether the thread is pinned to the top of its parent forum or media channel. :rtype: bool

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.

Return type:

bool

await join()

This function is a coroutine.

Joins this thread.

You must have send_messages_in_threads to join a thread. If the thread is private, manage_threads is also needed.

Raises:
property jump_url: str

Returns a URL that allows the client to jump to the thread.

Added in version 2.0.

await leave()

This function is a coroutine.

Leaves this thread.

Raises:

HTTPException – Leaving the thread failed.

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.members to be properly filled. Most of the time however, this data is not provided by the gateway and a call to fetch_members() is needed.

property mention: str

The string that allows you to mention the thread.

property nsfw: bool

Whether the thread is NSFW. Inherited from parent channel.

property parent: TextChannel | ForumChannel | None

The parent channel this thread belongs to.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

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.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

Raises:

ClientException – The parent channel was not cached and returned None

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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=Undefined.MISSING, 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 a check is not provided then all messages are deleted without discrimination.

You must have the manage_messages permission to delete messages even if they are your own (unless you are a user account). The read_message_history permission is also needed to retrieve message history.

Parameters:
  • limit (Optional[int]) – 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 a Message as its sole parameter.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as before in history().

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as after in history().

  • around (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as around in history().

  • oldest_first (Optional[bool]) – Same as oldest_first in history().

  • bulk (bool) – If True, use bulk delete. Setting this to False is useful for mass-deleting a bot’s own messages without Permissions.manage_messages. When True, will fall back to single delete if messages are older than two weeks.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Returns:

The list of messages that were deleted.

Return type:

List[Message]

Raises:
  • Forbidden – You do not have proper permissions to do the actions required.

  • HTTPException – Purging the messages failed.

Examples

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 remove_user(user)

This function is a coroutine.

Removes a user from this thread.

You must have manage_threads or be the creator of the thread to remove a user.

Parameters:

user (abc.Snowflake) – The user to remove from the thread.

Raises:
  • Forbidden – You do not have permissions to remove the user from the thread.

  • HTTPException – Removing the user from the thread 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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property topic: None

Threads don’t have topics. Always returns None.

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.

Return type:

None

property type: ChannelType

The channel’s Discord type.

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unarchive()

This function is a coroutine.

Unarchives the thread. This is a shorthand of edit().

Returns:

The updated thread.

Return type:

Thread

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this channel.

Requires manage_webhooks permissions.

Returns:

The webhooks for this channel.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

class discord.events.ThreadDelete[source]

Called whenever a thread is deleted.

Note that you can get the guild from Thread.guild.

This requires Intents.guilds to be enabled.

This event inherits from Thread.

await add_user(user)

This function is a coroutine.

Adds a user to this thread.

You must have send_messages_in_threads to add a user to a public thread. If the thread is private and invitable is False, then manage_threads is required.

Parameters:

user (abc.Snowflake) – The user to add to the thread.

Raises:
  • Forbidden – You do not have permissions to add the user to the thread.

  • HTTPException – Adding the user to the thread failed.

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]

await archive(locked=Undefined.MISSING)

This function is a coroutine.

Archives the thread. This is a shorthand of edit().

Parameters:

locked (bool) – Whether to lock the thread on archive, Defaults to False.

Returns:

The updated thread.

Return type:

Thread

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property category: CategoryChannel | None

The category channel the parent channel belongs to, if applicable.

Returns:

The parent channel’s category.

Return type:

Optional[CategoryChannel]

Raises:

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.

Returns:

The parent channel’s category ID.

Return type:

Optional[int]

Raises:

ClientException – The parent channel was not cached and returned None.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • Forbidden – You do not have the proper permissions to create this channel.

  • HTTPException – Creating the channel failed.

await create_webhook(*, name, avatar=None, reason=None)

This function is a coroutine.

Creates a webhook for this channel.

Requires manage_webhooks permissions.

Changed in version 1.1: Added the reason keyword-only parameter.

Parameters:
  • name (str) – The webhook’s name.

  • avatar (Optional[bytes]) – A bytes-like object representing the webhook’s default avatar. This operates similarly to edit().

  • reason (Optional[str]) – The reason for creating this webhook. Shows up in the audit logs.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Creating the webhook failed.

  • Forbidden – You do not have permissions to create a webhook.

await delete()

This function is a coroutine.

Deletes this thread.

You must have manage_threads to delete threads.

Raises:
  • Forbidden – You do not have permissions to delete this thread.

  • HTTPException – Deleting the thread failed.

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_messages permission to use this.

Usable only by bot accounts.

Parameters:
  • messages (Iterable[abc.Snowflake]) – An iterable of messages denoting which ones to bulk delete.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Raises:
  • 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.

Return type:

None

await edit(*, name=Undefined.MISSING, archived=Undefined.MISSING, locked=Undefined.MISSING, invitable=Undefined.MISSING, slowmode_delay=Undefined.MISSING, auto_archive_duration=Undefined.MISSING, pinned=Undefined.MISSING, applied_tags=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the thread.

Editing the thread requires Permissions.manage_threads. The thread creator can also edit name, archived or auto_archive_duration. Note that if the thread is locked then only those with Permissions.manage_threads can send messages in it or unarchive a thread.

The thread must be unarchived to be edited.

Parameters:
  • 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 (int) – The new duration in minutes before a thread is automatically archived for inactivity. Must be one of 60, 1440, 4320, or 10080. ThreadArchiveDuration can be used alternatively.

  • slowmode_delay (int) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

  • reason (Optional[str]) – 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.

Returns:

The newly edited thread.

Return type:

Thread

Raises:
await fetch_members()

This function is a coroutine.

Retrieves all ThreadMember that are in this thread.

This requires Intents.members to get information about members other than yourself.

Returns:

All thread members in the thread.

Return type:

List[ThreadMember]

Raises:

HTTPException – Retrieving the members failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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.

Note

The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.

Added in version 1.3.

Parameters:
  • destination (TextChannel) – The channel you would like to follow from.

  • reason (Optional[str]) –

    The reason for following the channel. Shows up on the destination guild’s audit log.

    Added in version 1.4.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Following the channel failed.

  • Forbidden – You do not have the permissions to create a webhook.

await get_last_message()

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() or fetch_message() with the last_message_id attribute.

Returns:

The last message in this channel or None if not found.

Return type:

Optional[Message]

await get_members()

Returns all members that can see this channel.

Return type:

list[Member]

await get_owner()

The member this thread belongs to.

Return type:

Member | None

get_partial_message(message_id, /)

Creates a PartialMessage from 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.

Parameters:

message_id (int) – The message ID to create a partial message for.

Returns:

The partial message.

Return type:

PartialMessage

await get_starting_message()

Returns the message that started this thread.

The message might not be valid or point to an existing message.

Note

The ID for this message is the same as the thread ID.

Returns:

The message that started this thread or None if not found in the cache.

Return type:

Optional[Message]

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

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() is True.

Return type:

bool

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() is True.

Return type:

bool

is_pinned()

Whether the thread is pinned to the top of its parent forum or media channel. :rtype: bool

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.

Return type:

bool

await join()

This function is a coroutine.

Joins this thread.

You must have send_messages_in_threads to join a thread. If the thread is private, manage_threads is also needed.

Raises:
property jump_url: str

Returns a URL that allows the client to jump to the thread.

Added in version 2.0.

await leave()

This function is a coroutine.

Leaves this thread.

Raises:

HTTPException – Leaving the thread failed.

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.members to be properly filled. Most of the time however, this data is not provided by the gateway and a call to fetch_members() is needed.

property mention: str

The string that allows you to mention the thread.

property nsfw: bool

Whether the thread is NSFW. Inherited from parent channel.

property parent: TextChannel | ForumChannel | None

The parent channel this thread belongs to.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

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.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

Raises:

ClientException – The parent channel was not cached and returned None

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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=Undefined.MISSING, 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 a check is not provided then all messages are deleted without discrimination.

You must have the manage_messages permission to delete messages even if they are your own (unless you are a user account). The read_message_history permission is also needed to retrieve message history.

Parameters:
  • limit (Optional[int]) – 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 a Message as its sole parameter.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as before in history().

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as after in history().

  • around (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as around in history().

  • oldest_first (Optional[bool]) – Same as oldest_first in history().

  • bulk (bool) – If True, use bulk delete. Setting this to False is useful for mass-deleting a bot’s own messages without Permissions.manage_messages. When True, will fall back to single delete if messages are older than two weeks.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Returns:

The list of messages that were deleted.

Return type:

List[Message]

Raises:
  • Forbidden – You do not have proper permissions to do the actions required.

  • HTTPException – Purging the messages failed.

Examples

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 remove_user(user)

This function is a coroutine.

Removes a user from this thread.

You must have manage_threads or be the creator of the thread to remove a user.

Parameters:

user (abc.Snowflake) – The user to remove from the thread.

Raises:
  • Forbidden – You do not have permissions to remove the user from the thread.

  • HTTPException – Removing the user from the thread 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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property topic: None

Threads don’t have topics. Always returns None.

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.

Return type:

None

property type: ChannelType

The channel’s Discord type.

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unarchive()

This function is a coroutine.

Unarchives the thread. This is a shorthand of edit().

Returns:

The updated thread.

Return type:

Thread

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this channel.

Requires manage_webhooks permissions.

Returns:

The webhooks for this channel.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

class discord.events.ThreadJoin[source]

Called whenever the bot joins a thread.

Note that you can get the guild from Thread.guild.

This requires Intents.guilds to be enabled.

This event inherits from Thread.

await add_user(user)

This function is a coroutine.

Adds a user to this thread.

You must have send_messages_in_threads to add a user to a public thread. If the thread is private and invitable is False, then manage_threads is required.

Parameters:

user (abc.Snowflake) – The user to add to the thread.

Raises:
  • Forbidden – You do not have permissions to add the user to the thread.

  • HTTPException – Adding the user to the thread failed.

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]

await archive(locked=Undefined.MISSING)

This function is a coroutine.

Archives the thread. This is a shorthand of edit().

Parameters:

locked (bool) – Whether to lock the thread on archive, Defaults to False.

Returns:

The updated thread.

Return type:

Thread

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property category: CategoryChannel | None

The category channel the parent channel belongs to, if applicable.

Returns:

The parent channel’s category.

Return type:

Optional[CategoryChannel]

Raises:

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.

Returns:

The parent channel’s category ID.

Return type:

Optional[int]

Raises:

ClientException – The parent channel was not cached and returned None.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • Forbidden – You do not have the proper permissions to create this channel.

  • HTTPException – Creating the channel failed.

await create_webhook(*, name, avatar=None, reason=None)

This function is a coroutine.

Creates a webhook for this channel.

Requires manage_webhooks permissions.

Changed in version 1.1: Added the reason keyword-only parameter.

Parameters:
  • name (str) – The webhook’s name.

  • avatar (Optional[bytes]) – A bytes-like object representing the webhook’s default avatar. This operates similarly to edit().

  • reason (Optional[str]) – The reason for creating this webhook. Shows up in the audit logs.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Creating the webhook failed.

  • Forbidden – You do not have permissions to create a webhook.

await delete()

This function is a coroutine.

Deletes this thread.

You must have manage_threads to delete threads.

Raises:
  • Forbidden – You do not have permissions to delete this thread.

  • HTTPException – Deleting the thread failed.

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_messages permission to use this.

Usable only by bot accounts.

Parameters:
  • messages (Iterable[abc.Snowflake]) – An iterable of messages denoting which ones to bulk delete.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Raises:
  • 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.

Return type:

None

await edit(*, name=Undefined.MISSING, archived=Undefined.MISSING, locked=Undefined.MISSING, invitable=Undefined.MISSING, slowmode_delay=Undefined.MISSING, auto_archive_duration=Undefined.MISSING, pinned=Undefined.MISSING, applied_tags=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the thread.

Editing the thread requires Permissions.manage_threads. The thread creator can also edit name, archived or auto_archive_duration. Note that if the thread is locked then only those with Permissions.manage_threads can send messages in it or unarchive a thread.

The thread must be unarchived to be edited.

Parameters:
  • 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 (int) – The new duration in minutes before a thread is automatically archived for inactivity. Must be one of 60, 1440, 4320, or 10080. ThreadArchiveDuration can be used alternatively.

  • slowmode_delay (int) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

  • reason (Optional[str]) – 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.

Returns:

The newly edited thread.

Return type:

Thread

Raises:
await fetch_members()

This function is a coroutine.

Retrieves all ThreadMember that are in this thread.

This requires Intents.members to get information about members other than yourself.

Returns:

All thread members in the thread.

Return type:

List[ThreadMember]

Raises:

HTTPException – Retrieving the members failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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.

Note

The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.

Added in version 1.3.

Parameters:
  • destination (TextChannel) – The channel you would like to follow from.

  • reason (Optional[str]) –

    The reason for following the channel. Shows up on the destination guild’s audit log.

    Added in version 1.4.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Following the channel failed.

  • Forbidden – You do not have the permissions to create a webhook.

await get_last_message()

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() or fetch_message() with the last_message_id attribute.

Returns:

The last message in this channel or None if not found.

Return type:

Optional[Message]

await get_members()

Returns all members that can see this channel.

Return type:

list[Member]

await get_owner()

The member this thread belongs to.

Return type:

Member | None

get_partial_message(message_id, /)

Creates a PartialMessage from 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.

Parameters:

message_id (int) – The message ID to create a partial message for.

Returns:

The partial message.

Return type:

PartialMessage

await get_starting_message()

Returns the message that started this thread.

The message might not be valid or point to an existing message.

Note

The ID for this message is the same as the thread ID.

Returns:

The message that started this thread or None if not found in the cache.

Return type:

Optional[Message]

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

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() is True.

Return type:

bool

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() is True.

Return type:

bool

is_pinned()

Whether the thread is pinned to the top of its parent forum or media channel. :rtype: bool

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.

Return type:

bool

await join()

This function is a coroutine.

Joins this thread.

You must have send_messages_in_threads to join a thread. If the thread is private, manage_threads is also needed.

Raises:
property jump_url: str

Returns a URL that allows the client to jump to the thread.

Added in version 2.0.

await leave()

This function is a coroutine.

Leaves this thread.

Raises:

HTTPException – Leaving the thread failed.

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.members to be properly filled. Most of the time however, this data is not provided by the gateway and a call to fetch_members() is needed.

property mention: str

The string that allows you to mention the thread.

property nsfw: bool

Whether the thread is NSFW. Inherited from parent channel.

property parent: TextChannel | ForumChannel | None

The parent channel this thread belongs to.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

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.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

Raises:

ClientException – The parent channel was not cached and returned None

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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=Undefined.MISSING, 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 a check is not provided then all messages are deleted without discrimination.

You must have the manage_messages permission to delete messages even if they are your own (unless you are a user account). The read_message_history permission is also needed to retrieve message history.

Parameters:
  • limit (Optional[int]) – 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 a Message as its sole parameter.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as before in history().

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as after in history().

  • around (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as around in history().

  • oldest_first (Optional[bool]) – Same as oldest_first in history().

  • bulk (bool) – If True, use bulk delete. Setting this to False is useful for mass-deleting a bot’s own messages without Permissions.manage_messages. When True, will fall back to single delete if messages are older than two weeks.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Returns:

The list of messages that were deleted.

Return type:

List[Message]

Raises:
  • Forbidden – You do not have proper permissions to do the actions required.

  • HTTPException – Purging the messages failed.

Examples

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 remove_user(user)

This function is a coroutine.

Removes a user from this thread.

You must have manage_threads or be the creator of the thread to remove a user.

Parameters:

user (abc.Snowflake) – The user to remove from the thread.

Raises:
  • Forbidden – You do not have permissions to remove the user from the thread.

  • HTTPException – Removing the user from the thread 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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property topic: None

Threads don’t have topics. Always returns None.

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.

Return type:

None

property type: ChannelType

The channel’s Discord type.

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unarchive()

This function is a coroutine.

Unarchives the thread. This is a shorthand of edit().

Returns:

The updated thread.

Return type:

Thread

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this channel.

Requires manage_webhooks permissions.

Returns:

The webhooks for this channel.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

class discord.events.ThreadRemove[source]

Called whenever a thread is removed.

This is different from a thread being deleted.

Note that you can get the guild from Thread.guild.

This requires Intents.guilds to be enabled.

Warning

Due to technical limitations, this event might not be called as soon as one expects. Since the library tracks thread membership locally, the API only sends updated thread membership status upon being synced by joining a thread.

This event inherits from Thread.

await add_user(user)

This function is a coroutine.

Adds a user to this thread.

You must have send_messages_in_threads to add a user to a public thread. If the thread is private and invitable is False, then manage_threads is required.

Parameters:

user (abc.Snowflake) – The user to add to the thread.

Raises:
  • Forbidden – You do not have permissions to add the user to the thread.

  • HTTPException – Adding the user to the thread failed.

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]

await archive(locked=Undefined.MISSING)

This function is a coroutine.

Archives the thread. This is a shorthand of edit().

Parameters:

locked (bool) – Whether to lock the thread on archive, Defaults to False.

Returns:

The updated thread.

Return type:

Thread

can_send(*objects)

Returns a bool indicating whether you have the permissions to send the object(s).

Returns:

Indicates whether you have the permissions to send the object(s).

Return type:

bool

Raises:

TypeError – An invalid type has been passed.

property category: CategoryChannel | None

The category channel the parent channel belongs to, if applicable.

Returns:

The parent channel’s category.

Return type:

Optional[CategoryChannel]

Raises:

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.

Returns:

The parent channel’s category ID.

Return type:

Optional[int]

Raises:

ClientException – The parent channel was not cached and returned None.

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_channels permission to do this.

Added in version 1.1.

Parameters:
  • name (Optional[str]) – The name of the new channel. If not provided, defaults to this channel name.

  • reason (Optional[str]) – The reason for cloning this channel. Shows up on the audit log.

Returns:

The channel that was created.

Return type:

abc.GuildChannel

Raises:
  • Forbidden – You do not have the proper permissions to create this channel.

  • HTTPException – Creating the channel failed.

await create_webhook(*, name, avatar=None, reason=None)

This function is a coroutine.

Creates a webhook for this channel.

Requires manage_webhooks permissions.

Changed in version 1.1: Added the reason keyword-only parameter.

Parameters:
  • name (str) – The webhook’s name.

  • avatar (Optional[bytes]) – A bytes-like object representing the webhook’s default avatar. This operates similarly to edit().

  • reason (Optional[str]) – The reason for creating this webhook. Shows up in the audit logs.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Creating the webhook failed.

  • Forbidden – You do not have permissions to create a webhook.

await delete()

This function is a coroutine.

Deletes this thread.

You must have manage_threads to delete threads.

Raises:
  • Forbidden – You do not have permissions to delete this thread.

  • HTTPException – Deleting the thread failed.

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_messages permission to use this.

Usable only by bot accounts.

Parameters:
  • messages (Iterable[abc.Snowflake]) – An iterable of messages denoting which ones to bulk delete.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Raises:
  • 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.

Return type:

None

await edit(*, name=Undefined.MISSING, archived=Undefined.MISSING, locked=Undefined.MISSING, invitable=Undefined.MISSING, slowmode_delay=Undefined.MISSING, auto_archive_duration=Undefined.MISSING, pinned=Undefined.MISSING, applied_tags=Undefined.MISSING, reason=None)

This function is a coroutine.

Edits the thread.

Editing the thread requires Permissions.manage_threads. The thread creator can also edit name, archived or auto_archive_duration. Note that if the thread is locked then only those with Permissions.manage_threads can send messages in it or unarchive a thread.

The thread must be unarchived to be edited.

Parameters:
  • 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 (int) – The new duration in minutes before a thread is automatically archived for inactivity. Must be one of 60, 1440, 4320, or 10080. ThreadArchiveDuration can be used alternatively.

  • slowmode_delay (int) – Specifies the slowmode rate limit for user in this thread, in seconds. A value of 0 disables slowmode. The maximum value possible is 21600.

  • reason (Optional[str]) – 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.

Returns:

The newly edited thread.

Return type:

Thread

Raises:
await fetch_members()

This function is a coroutine.

Retrieves all ThreadMember that are in this thread.

This requires Intents.members to get information about members other than yourself.

Returns:

All thread members in the thread.

Return type:

List[ThreadMember]

Raises:

HTTPException – Retrieving the members failed.

await fetch_message(id, /)

This function is a coroutine.

Retrieves a single Message from the destination.

Parameters:

id (int) – The message ID to look for.

Returns:

The message asked for.

Return type:

Message

Raises:
  • 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.

Note

The webhook returned will not provide a token to do webhook actions, as Discord does not provide it.

Added in version 1.3.

Parameters:
  • destination (TextChannel) – The channel you would like to follow from.

  • reason (Optional[str]) –

    The reason for following the channel. Shows up on the destination guild’s audit log.

    Added in version 1.4.

Returns:

The created webhook.

Return type:

Webhook

Raises:
  • HTTPException – Following the channel failed.

  • Forbidden – You do not have the permissions to create a webhook.

await get_last_message()

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() or fetch_message() with the last_message_id attribute.

Returns:

The last message in this channel or None if not found.

Return type:

Optional[Message]

await get_members()

Returns all members that can see this channel.

Return type:

list[Member]

await get_owner()

The member this thread belongs to.

Return type:

Member | None

get_partial_message(message_id, /)

Creates a PartialMessage from 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.

Parameters:

message_id (int) – The message ID to create a partial message for.

Returns:

The partial message.

Return type:

PartialMessage

await get_starting_message()

Returns the message that started this thread.

The message might not be valid or point to an existing message.

Note

The ID for this message is the same as the thread ID.

Returns:

The message that started this thread or None if not found in the cache.

Return type:

Optional[Message]

history(*, limit=100, before=None, after=None, around=None, oldest_first=None)

Returns an AsyncIterator that enables receiving the destination’s message history.

You must have read_message_history permissions to use this.

Parameters:
  • limit (Optional[int]) – The number of messages to retrieve. If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages before this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • after (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages after this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time.

  • around (Optional[Union[Snowflake, datetime.datetime]]) – Retrieve messages around this date or message. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. When using this argument, the maximum limit is 101. Note that if the limit is an even number, then this will return at most limit + 1 messages.

  • oldest_first (Optional[bool]) – If set to True, return messages in oldest->newest order. Defaults to True if after is specified, otherwise False.

Yields:

Message – The message with the message data parsed.

Raises:
  • Forbidden – You do not have permissions to get channel message history.

  • HTTPException – The request to get message history failed.

Return type:

HistoryIterator

Examples

Usage

counter = 0
async for message in channel.history(limit=200):
    if message.author == client.user:
        counter += 1

Flattening into a list:

messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...

All parameters are optional.

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() is True.

Return type:

bool

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() is True.

Return type:

bool

is_pinned()

Whether the thread is pinned to the top of its parent forum or media channel. :rtype: bool

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.

Return type:

bool

await join()

This function is a coroutine.

Joins this thread.

You must have send_messages_in_threads to join a thread. If the thread is private, manage_threads is also needed.

Raises:
property jump_url: str

Returns a URL that allows the client to jump to the thread.

Added in version 2.0.

await leave()

This function is a coroutine.

Leaves this thread.

Raises:

HTTPException – Leaving the thread failed.

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.members to be properly filled. Most of the time however, this data is not provided by the gateway and a call to fetch_members() is needed.

property mention: str

The string that allows you to mention the thread.

property nsfw: bool

Whether the thread is NSFW. Inherited from parent channel.

property parent: TextChannel | ForumChannel | None

The parent channel this thread belongs to.

permissions_for(obj, /)

Handles permission resolution for the Member or Role.

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.

Parameters:

obj (Union[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.

Returns:

The resolved permissions for the member or role.

Return type:

Permissions

Raises:

ClientException – The parent channel was not cached and returned None

pins(*, limit=50, before=None)

Returns a MessagePinIterator that enables receiving the destination’s pinned messages.

You must have read_message_history permissions to use this.

Warning

Starting from version 3.0, await channel.pins() will no longer return a list of Message. See examples below for new usage instead.

Parameters:
  • limit (Optional[int]) – The number of pinned messages to retrieve. If None, retrieves every pinned message in the channel.

  • before (Optional[Union[Snowflake, datetime.datetime]]) – 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.

Yields:

MessagePin – The pinned message.

Raises:
  • Forbidden – You do not have permissions to get pinned messages.

  • HTTPException – The request to get pinned messages failed.

Return type:

MessagePinIterator

Examples

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=Undefined.MISSING, 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 a check is not provided then all messages are deleted without discrimination.

You must have the manage_messages permission to delete messages even if they are your own (unless you are a user account). The read_message_history permission is also needed to retrieve message history.

Parameters:
  • limit (Optional[int]) – 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 a Message as its sole parameter.

  • before (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as before in history().

  • after (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as after in history().

  • around (Optional[Union[abc.Snowflake, datetime.datetime]]) – Same as around in history().

  • oldest_first (Optional[bool]) – Same as oldest_first in history().

  • bulk (bool) – If True, use bulk delete. Setting this to False is useful for mass-deleting a bot’s own messages without Permissions.manage_messages. When True, will fall back to single delete if messages are older than two weeks.

  • reason (Optional[str]) – The reason for deleting the messages. Shows up on the audit log.

Returns:

The list of messages that were deleted.

Return type:

List[Message]

Raises:
  • Forbidden – You do not have proper permissions to do the actions required.

  • HTTPException – Purging the messages failed.

Examples

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 remove_user(user)

This function is a coroutine.

Removes a user from this thread.

You must have manage_threads or be the creator of the thread to remove a user.

Parameters:

user (abc.Snowflake) – The user to remove from the thread.

Raises:
  • Forbidden – You do not have permissions to remove the user from the thread.

  • HTTPException – Removing the user from the thread 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, 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 to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

To upload a single embed, the embed parameter should be used with a single Embed object. To upload multiple embeds, the embeds parameter should be used with a list of Embed objects. Specifying both parameters will lead to an exception.

Parameters:
  • 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 nonce is 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 in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    Added in version 1.4.

  • reference (Union[Message, MessageReference, PartialMessage]) –

    A reference to the Message being replied to or forwarded. This can be created using to_reference(). When replying, you can control whether this mentions the author of the referenced message using the replied_user attribute of allowed_mentions or by setting mention_author.

    Added in version 1.6.

  • mention_author (Optional[bool]) –

    If set, overrides the replied_user attribute of allowed_mentions.

    Added in version 1.6.

  • view (discord.ui.View) – 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.

  • 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.

Returns:

The message that was sent.

Return type:

Message

Raises:
property topic: None

Threads don’t have topics. Always returns None.

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.

Return type:

None

property type: ChannelType

The channel’s Discord type.

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. :rtype: Typing

Note

This is both a regular context manager and an async context manager. This means that both with and async with work with this.

Example Usage:

async with channel.typing():
    # simulate something heavy
    await asyncio.sleep(10)

await channel.send("done!")
await unarchive()

This function is a coroutine.

Unarchives the thread. This is a shorthand of edit().

Returns:

The updated thread.

Return type:

Thread

await webhooks()

This function is a coroutine.

Gets the list of webhooks from this channel.

Requires manage_webhooks permissions.

Returns:

The webhooks for this channel.

Return type:

List[Webhook]

Raises:

Forbidden – You don’t have permissions to get the webhooks.

class discord.events.ThreadMemberJoin[source]

Called when a thread member joins a thread.

You can get the thread a member belongs in by accessing ThreadMember.thread.

This requires Intents.members to be enabled.

This event inherits from ThreadMember.

property thread: Thread

The thread this member belongs to.

class discord.events.ThreadMemberRemove[source]

Called when a thread member leaves a thread.

You can get the thread a member belongs in by accessing ThreadMember.thread.

This requires Intents.members to be enabled.

This event inherits from ThreadMember.

property thread: Thread

The thread this member belongs to.

Typing

class discord.events.TypingStart[source]

Called when someone begins typing a message.

The channel can be a abc.Messageable instance, which could be TextChannel, GroupChannel, or DMChannel.

If the channel is a TextChannel then the user is a Member, otherwise it is a User.

This requires Intents.typing to be enabled.

raw

The raw event payload data.

Type:

RawTypingEvent

channel

The location where the typing originated from.

Type:

abc.Messageable

user

The user that started typing.

Type:

User | Member

when

When the typing started as an aware datetime in UTC.

Type:

datetime.datetime

Voice

class discord.events.VoiceStateUpdate[source]

Called when a member changes their voice state.

The following, but not limited to, examples illustrate when this event is called: - A member joins a voice or stage channel. - A member leaves a voice or stage channel. - A member is muted or deafened by their own accord. - A member is muted or deafened by a guild administrator.

This requires Intents.voice_states to be enabled.

member

The member whose voice states changed.

Type:

Member

before

The voice state prior to the changes.

Type:

VoiceState

after

The voice state after the changes.

Type:

VoiceState

class discord.events.VoiceServerUpdate[source]

Called when the voice server is updated.

Note

This is an internal event used by the voice protocol. It is not dispatched to user code.

class discord.events.VoiceChannelStatusUpdate[source]

Called when someone updates a voice channel status.

raw

The raw voice channel status update payload.

Type:

RawVoiceChannelStatusUpdateEvent

channel

The channel where the voice channel status update originated from.

Type:

VoiceChannel | StageChannel

old_status

The old voice channel status.

Type:

str | None

new_status

The new voice channel status.

Type:

str | None

class discord.events.VoiceChannelEffectSend(*, animation_type, animation_id, sound, guild, user, channel, emoji)[source]

Called when a voice channel effect is sent.

animation_type

The type of animation that is being sent.

Type:

VoiceChannelEffectAnimationType

animation_id

The ID of the animation that is being sent.

Type:

int

sound

The sound that is being sent, could be None if the effect is not a sound effect.

Type:

SoundboardSound | PartialSoundboardSound | None

guild

The guild in which the sound is being sent.

Type:

Guild

user

The member that sent the sound.

Type:

Member

channel

The voice channel in which the sound is being sent.

Type:

VoiceChannel | StageChannel

emoji

The emoji associated with the effect, if any.

Type:

PartialEmoji | None

Parameters:
  • animation_type (VoiceChannelEffectAnimationType)

  • animation_id (int)

  • sound (SoundboardSound | PartialSoundboardSound | None)

  • guild (Guild)

  • user (Member)

  • channel (VocalGuildChannel)

  • emoji (PartialEmoji | None)

Webhooks

class discord.events.WebhooksUpdate[source]

Called whenever a webhook is created, modified, or removed from a guild channel.

This requires Intents.webhooks to be enabled.

channel

The channel that had its webhooks updated.

Type:

TextChannel | VoiceChannel | ForumChannel | StageChannel