text
stringlengths
81
112k
A helper utility to send the page output from :attr:`paginator` to the destination. async def send_pages(self): """A helper utility to send the page output from :attr:`paginator` to the destination.""" destination = self.get_destination() for page in self.paginator.pages: await dest...
Adds the minified bot heading with commands to the output. The formatting should be added to the :attr:`paginator`. The default implementation is a bold underline heading followed by commands separated by an EN SPACE (U+2002) in the next line. Parameters ----------- co...
Adds formatting information on a subcommand. The formatting should be added to the :attr:`paginator`. The default implementation is the prefix and the :attr:`Command.qualified_name` optionally followed by an En dash and the command's :attr:`Command.short_doc`. Parameters -----...
Adds the formatting information on a command's aliases. The formatting should be added to the :attr:`paginator`. The default implementation is the :attr:`aliases_heading` bolded followed by a comma separated list of aliases. This is not called if there are no aliases to format. ...
A utility function to format commands and groups. Parameters ------------ command: :class:`Command` The command to format. def add_command_formatting(self, command): """A utility function to format commands and groups. Parameters ------------ comman...
|coro| Disconnects this voice client from voice. async def disconnect(self, *, force=False): """|coro| Disconnects this voice client from voice. """ if not force and not self.is_connected(): return self.stop() self._connected.clear() try: ...
|coro| Moves you to a different voice channel. Parameters ----------- channel: :class:`abc.Snowflake` The channel to move to. Must be a voice channel. async def move_to(self, channel): """|coro| Moves you to a different voice channel. Parameters ...
Plays an :class:`AudioSource`. The finalizer, ``after`` is called after the source has been exhausted or an error occurred. If an error happens while the audio player is running, the exception is caught and the audio player is then stopped. Parameters ----------- ...
Sends an audio packet composed of the data. You must be connected to play audio. Parameters ---------- data: bytes The :term:`py:bytes-like object` denoting PCM or Opus voice data. encode: bool Indicates if ``data`` should be encoded into Opus. ...
|coro| The default error handler provided by the client. By default this prints to :data:`sys.stderr` however it could be overridden to have a different implementation. Check :func:`discord.on_error` for more details. async def on_error(self, event_method, *args, **kwargs): ""...
r"""|coro| Requests previously offline members from the guild to be filled up into the :attr:`.Guild.members` cache. This function is usually not called. It should only be used if you have the ``fetch_offline_members`` parameter set to ``False``. When the client logs on and con...
|coro| Logs in the client with the specified credentials. This function can be used in two different ways. .. warning:: Logging on with a user token is against the Discord `Terms of Service <https://support.discordapp.com/hc/en-us/articles/115002192352>`_ ...
|coro| Creates a websocket connection and lets the websocket listen to messages from discord. This is a loop that runs the entire event system and miscellaneous aspects of the library. Control is not resumed until the WebSocket connection is terminated. Parameters -----...
|coro| Closes the connection to discord. async def close(self): """|coro| Closes the connection to discord. """ if self._closed: return await self.http.close() self._closed = True for voice in self.voice_clients: try: ...
Clears the internal state of the bot. After this, the bot can be considered "re-opened", i.e. :meth:`.is_closed` and :meth:`.is_ready` both return ``False`` along with the bot's internal cache cleared. def clear(self): """Clears the internal state of the bot. After this, the b...
|coro| A shorthand coroutine for :meth:`login` + :meth:`connect`. async def start(self, *args, **kwargs): """|coro| A shorthand coroutine for :meth:`login` + :meth:`connect`. """ bot = kwargs.pop('bot', True) reconnect = kwargs.pop('reconnect', True) await sel...
A blocking call that abstracts away the event loop initialisation from you. If you want more control over the event loop then this function should not be used. Use :meth:`start` coroutine or :meth:`connect` + :meth:`login`. Roughly Equivalent to: :: try: ...
|coro| Waits for a WebSocket event to be dispatched. This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way. The ``timeout`` parameter is passed onto :func:`asyncio.wait_for`. By default, it d...
A decorator that registers an event to listen to. You can find more info about the events on the :ref:`documentation below <discord-api-events>`. The events must be a |corourl|_, if not, :exc:`TypeError` is raised. Example --------- .. code-block:: python3 @clien...
|coro| Changes the client's presence. The activity parameter is a :class:`.Activity` object (not a string) that represents the activity being done currently. This could also be the slimmed down versions, :class:`.Game` and :class:`.Streaming`. Example --------- ...
|coro| Retrieves an :class:`.AsyncIterator` that enables receiving your guilds. .. note:: Using this, you will only receive :attr:`.Guild.owner`, :attr:`.Guild.icon`, :attr:`.Guild.id`, and :attr:`.Guild.name` per :class:`.Guild`. .. note:: This method is...
|coro| Retrieves a :class:`.Guild` from an ID. .. note:: Using this, you will not receive :attr:`.Guild.channels`, :class:`.Guild.members`, :attr:`.Member.activity` and :attr:`.Member.voice` per :class:`.Member`. .. note:: This method is an API call. For ...
|coro| Creates a :class:`.Guild`. Bot accounts in more than 10 guilds are not allowed to create guilds. Parameters ---------- name: :class:`str` The name of the guild. region: :class:`VoiceRegion` The region for the voice communication server. ...
|coro| Gets an :class:`.Invite` from a discord.gg URL or ID. .. note:: If the invite is for a guild you have not joined, the guild and channel attributes of the returned :class:`.Invite` will be :class:`.PartialInviteGuild` and :class:`PartialInviteChannel` respect...
|coro| Revokes an :class:`.Invite`, URL, or ID to an invite. You must have the :attr:`~.Permissions.manage_channels` permission in the associated guild to do this. Parameters ---------- invite: Union[:class:`.Invite`, :class:`str`] The invite to revoke. ...
|coro| Gets a :class:`.Widget` from a guild ID. .. note:: The guild must have the widget enabled to get this information. Parameters ----------- guild_id: :class:`int` The ID of the guild. Raises ------- Forbidden T...
|coro| Retrieve's the bot's application information. Raises ------- HTTPException Retrieving the information failed somehow. Returns -------- :class:`.AppInfo` A namedtuple representing the application info. async def application_info(s...
|coro| Retrieves a :class:`~discord.User` based on their ID. This can only be used by bot accounts. You do not have to share any guilds with the user to get this information, however many operations do require that you do. .. note:: This method is an API call. For ...
|coro| Gets an arbitrary user's profile. This can only be used by non-bot accounts. Parameters ------------ user_id: :class:`int` The ID of the user to fetch their profile for. Raises ------- Forbidden Not allowed to fetch profiles. ...
|coro| Retrieves a :class:`.Webhook` with the specified ID. Raises -------- HTTPException Retrieving the webhook failed. NotFound Invalid webhook ID. Forbidden You do not have permission to fetch this webhook. Returns ...
:class:`Asset`: The same operation as :meth:`Guild.icon_url_as`. def icon_url_as(self, *, format='webp', size=1024): """:class:`Asset`: The same operation as :meth:`Guild.icon_url_as`.""" return Asset._from_guild_image(self._state, self.id, self.icon, 'icons', format=format, size=size)
:class:`Asset`: The same operation as :meth:`Guild.banner_url_as`. def banner_url_as(self, *, format='webp', size=2048): """:class:`Asset`: The same operation as :meth:`Guild.banner_url_as`.""" return Asset._from_guild_image(self._state, self.id, self.banner, 'banners', format=format, size=size)
:class:`Asset`: The same operation as :meth:`Guild.splash_url_as`. def splash_url_as(self, *, format='webp', size=2048): """:class:`Asset`: The same operation as :meth:`Guild.splash_url_as`.""" return Asset._from_guild_image(self._state, self.id, self.splash, 'splashes', format=format, size=size)
|coro| Revokes the instant invite. You must have the :attr:`~Permissions.manage_channels` permission to do this. Parameters ----------- reason: Optional[:class:`str`] The reason for deleting this invite. Shows up on the audit log. Raises ------- ...
|coro| Saves this attachment into a file-like object. Parameters ----------- fp: Union[BinaryIO, :class:`os.PathLike`] The file-like object to save this attachment to or the filename to use. If a filename is passed then a file is created with that fi...
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. def raw_mentions(self): """A property that returns an array of user IDs matched with ...
A property that returns an array of channel IDs matched with the syntax of <#channel_id> in the message content. def raw_channel_mentions(self): """A property that returns an array of channel IDs matched with the syntax of <#channel_id> in the message content. """ return [int(x)...
A property that returns an array of role IDs matched with the syntax of <@&role_id> in the message content. def raw_role_mentions(self): """A property that returns an array of role IDs matched with the syntax of <@&role_id> in the message content. """ return [int(x) for x in re....
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. .. n...
r"""A property that returns the content that is rendered regardless of the :attr:`Message.type`. In the case of :attr:`MessageType.default`\, this just returns the regular :attr:`Message.content`. Otherwise this returns an English message denoting the contents of the system message. de...
|coro| Deletes the message. Your own messages could be deleted without any proper permissions. However to delete other people's messages, you need the :attr:`~Permissions.manage_messages` permission. .. versionchanged:: 1.1.0 Added the new ``delay`` keyword-only pa...
|coro| Edits the message. The content must be able to be transformed into a string via ``str(content)``. Parameters ----------- content: Optional[:class:`str`] The new content to replace the message with. Could be ``None`` to remove the content. ...
|coro| Pins the message. You must have the :attr:`~Permissions.manage_messages` permission to do this in a non-private channel context. Raises ------- Forbidden You do not have permissions to pin the message. NotFound The message or chan...
|coro| Unpins the message. You must have the :attr:`~Permissions.manage_messages` permission to do this in a non-private channel context. Raises ------- Forbidden You do not have permissions to unpin the message. NotFound The message or ...
|coro| Add a reaction to the message. The emoji may be a unicode emoji or a custom guild :class:`Emoji`. You must have the :attr:`~Permissions.read_message_history` permission to use this. If nobody else has reacted to the message using this emoji, the :attr:`~Permissions.add_...
|coro| Remove a reaction by the member from the message. The emoji may be a unicode emoji or a custom guild :class:`Emoji`. If the reaction is not your own (i.e. ``member`` parameter is not you) then the :attr:`~Permissions.manage_messages` permission is needed. The ``member`...
|coro| Removes all the reactions from the message. You need the :attr:`~Permissions.manage_messages` permission to use this. Raises -------- HTTPException Removing the reactions failed. Forbidden You do not have the proper permissions to remove ...
|coro| Marks this message as read. The user must not be a bot user. Raises ------- HTTPException Acking failed. ClientException You must not be a bot user. async def ack(self): """|coro| Marks this message as read. The...
Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity if applicable. def large_image_url(self): """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity if applicable.""" if self.application_id is None: return None ...
Optional[:class:`str`]: Returns a URL pointing to the small image asset of this activity if applicable. def small_image_url(self): """Optional[:class:`str`]: Returns a URL pointing to the small image asset of this activity if applicable.""" if self.application_id is None: return None ...
:class:`str`: The album cover image URL from Spotify's CDN. def album_cover_url(self): """:class:`str`: The album cover image URL from Spotify's CDN.""" large_image = self._assets.get('large_image', '') if large_image[:8] != 'spotify:': return '' album_image_id = large_image...
A callable that implements when mentioned or other prefixes provided. These are meant to be passed into the :attr:`.Bot.command_prefix` attribute. Example -------- .. code-block:: python3 bot = commands.Bot(command_prefix=commands.when_mentioned_or('!')) .. note:: This callabl...
|coro| The default command error handler provided by the bot. By default this prints to ``sys.stderr`` however it could be overridden to have a different implementation. This only fires if you do not specify any listeners for command error. async def on_command_error(self, context, e...
Adds a global check to the bot. This is the non-decorator interface to :meth:`.check` and :meth:`.check_once`. Parameters ----------- func The function that was used as a global check. call_once: :class:`bool` If the function should only be calle...
Removes a global check from the bot. This function is idempotent and will not raise an exception if the function is not in the global checks. Parameters ----------- func The function to remove from the global checks. call_once: :class:`bool` If t...
Checks if a :class:`~discord.User` or :class:`~discord.Member` is the owner of this bot. If an :attr:`owner_id` is not set, it is fetched automatically through the use of :meth:`~.Bot.application_info`. Parameters ----------- user: :class:`.abc.User` The use...
The non decorator alternative to :meth:`.listen`. Parameters ----------- func: :ref:`coroutine <coroutine>` The function to call. name: Optional[:class:`str`] The name of the event to listen for. Defaults to ``func.__name__``. Example -------- ...
Removes a listener from the pool of listeners. Parameters ----------- func The function that was used as a listener to remove. name: :class:`str` The name of the event we want to remove. Defaults to ``func.__name__``. def remove_listener(self, func, ...
A decorator that registers another function as an external event listener. Basically this allows you to listen to multiple events from different places e.g. such as :func:`.on_ready` The functions being listened to must be a coroutine. Example -------- .. code-block:: ...
Adds a "cog" to the bot. A cog is a class that has its own event listeners and commands. Parameters ----------- cog: :class:`.Cog` The cog to register to the bot. Raises ------- TypeError The cog does not inherit from :class:`.Cog`. ...
Removes a cog from the bot. All registered commands and event listeners that the cog has registered will be removed as well. If no cog is found then this method has no effect. Parameters ----------- name: :class:`str` The name of the cog to remove. def rem...
Loads an extension. An extension is a python module that contains commands, cogs, or listeners. An extension must have a global function, ``setup`` defined as the entry point on what to do when the extension is loaded. This entry point must have a single argument, the ``bot``. ...
Unloads an extension. When the extension is unloaded, all commands, listeners, and cogs are removed from the bot and the module is un-imported. The extension can provide an optional global function, ``teardown``, to do miscellaneous clean-up if necessary. This function takes a single ...
Atomically reloads an extension. This replaces the extension with the same extension, only refreshed. This is equivalent to a :meth:`unload_extension` followed by a :meth:`load_extension` except done in an atomic way. That is, if an operation fails mid-reload then the bot will roll-back...
|coro| Retrieves the prefix the bot is listening to with the message as a context. Parameters ----------- message: :class:`discord.Message` The message context to get the prefix of. Returns -------- Union[List[:class:`str`], :class:`str`] ...
r"""|coro| Returns the invocation context from the message. This is a more low-level counter-part for :meth:`.process_commands` to allow users more fine grained control over the processing. The returned context is not guaranteed to be a valid invocation context, :attr:`.Contex...
|coro| Invokes the command given under the invocation context and handles all the internal event dispatch mechanisms. Parameters ----------- ctx: :class:`.Context` The invocation context to invoke. async def invoke(self, ctx): """|coro| Invokes the...
|coro| This function processes the commands that have been registered to the bot and other groups. Without this coroutine, none of the commands will be triggered. By default, this coroutine is called inside the :func:`.on_message` event. If you choose to override the :func:`.on...
:class:`bool`: 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. def large(self): """:class:`bool`: Indicates if the guild is a 'large' guild. A large guild is...
List[:class:`VoiceChannel`]: A list of voice channels that belongs to this guild. This is sorted by the position and are in UI order from top to bottom. def voice_channels(self): """List[:class:`VoiceChannel`]: A list of voice channels that belongs to this guild. This is sorted by the positio...
Similar to :attr:`Client.user` except an instance of :class:`Member`. This is essentially used to get the member version of yourself. def me(self): """Similar to :attr:`Client.user` except an instance of :class:`Member`. This is essentially used to get the member version of yourself. ""...
List[:class:`TextChannel`]: A list of text channels that belongs to this guild. This is sorted by the position and are in UI order from top to bottom. def text_channels(self): """List[:class:`TextChannel`]: A list of text channels that belongs to this guild. This is sorted by the position and...
List[:class:`CategoryChannel`]: A list of categories that belongs to this guild. This is sorted by the position and are in UI order from top to bottom. def categories(self): """List[:class:`CategoryChannel`]: A list of categories that belongs to this guild. This is sorted by the position and ...
Returns every :class:`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 -------- List[Tuple[Optiona...
Optional[:class:`TextChannel`]: Returns the guild's channel used for system messages. Currently this is only for new member joins. If no channel is set, then this returns ``None``. def system_channel(self): """Optional[:class:`TextChannel`]: Returns the guild's channel used for system messages. ...
Gets the @everyone role that all members have by default. def default_role(self): """Gets the @everyone role that all members have by default.""" return utils.find(lambda r: r.is_default(), self._roles.values())
Returns a boolean indicating if the guild is "chunked". A chunked guild means that :attr:`member_count` is equal to the number of members stored in the internal :attr:`members` cache. If this value returns ``False``, then you should request for offline members. def chunked(self): ...
Returns the shard ID for this guild if applicable. def shard_id(self): """Returns the shard ID for this guild if applicable.""" count = self._state.shard_count if count is None: return None return (self.id >> 22) % count
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 wor...
|coro| Creates a :class:`TextChannel` for the guild. Note that you need the :attr:`~Permissions.manage_channels` permission to create the channel. The ``overwrites`` parameter can be used to create a 'secret' channel upon creation. This parameter expects a :class:`dict` of ...
|coro| This is similar to :meth:`create_text_channel` except makes a :class:`VoiceChannel` instead, in addition to having the following new parameters. Parameters ----------- bitrate: :class:`int` The channel's preferred audio bitrate in bits per second. use...
|coro| Same as :meth:`create_text_channel` except makes a :class:`CategoryChannel` instead. .. note:: The ``category`` parameter is not supported in this function since categories cannot have categories. async def create_category(self, name, *, overwrites=None, reason=None): ...
|coro| Edits the guild. You must have the :attr:`~Permissions.manage_guild` permission to edit the guild. Parameters ---------- name: :class:`str` The new name of the guild. description: :class:`str` The new description of the guild. Thi...
|coro| Retreives a :class:`Member` from a guild ID, and a member ID. .. note:: This method is an API call. For general usage, consider :meth:`get_member` instead. Parameters ----------- member_id: :class:`int` The member's ID to fetch from. Ra...
|coro| Retrieves the :class:`BanEntry` for a user, which is a namedtuple with a ``user`` and ``reason`` field. See :meth:`bans` for more information. You must have the :attr:`~Permissions.ban_members` permission to get this information. Parameters ----------- ...
|coro| Retrieves all the users that are banned from the guild. This coroutine returns a :class:`list` of BanEntry objects, which is a namedtuple with a ``user`` field to denote the :class:`User` that got banned along with a ``reason`` field specifying why the user was banned th...
r"""|coro| Prunes the guild from its inactive members. The inactive members are denoted if they have not logged on in ``days`` number of days and they have no roles. You must have the :attr:`~Permissions.kick_members` permission to use this. To check how many members ...
|coro| Similar to :meth:`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: :class:`int` The number of days before counting as inactive. ...
|coro| Returns a list of all active instant invites from the guild. You must have the :attr:`~Permissions.manage_guild` permission to get this information. Raises ------- Forbidden You do not have proper permissions to get the information. HTTPExcep...
r"""|coro| Retrieves all custom :class:`Emoji`\s from the guild. .. note:: This method is an API call. For general usage, consider :attr:`emojis` instead. Raises --------- HTTPException An error occurred fetching the emojis. Returns --...
|coro| Retrieves a custom :class:`Emoji` from the guild. .. note:: This method is an API call. For general usage, consider iterating over :attr:`emojis` instead. Parameters ------------- emoji_id: :class:`int` The emoji's ID. Raise...
r"""|coro| Creates a custom :class:`Emoji` 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 :attr:`~Permissions.manage_emojis` permission...
|coro| Creates a :class:`Role` for the guild. All fields are optional. You must have the :attr:`~Permissions.manage_roles` permission to do this. Parameters ----------- name: :class:`str` The role name. Defaults to 'new role'. permissions: ...
|coro| Kicks a user from the guild. The user must meet the :class:`abc.Snowflake` abc. You must have the :attr:`~Permissions.kick_members` permission to do this. Parameters ----------- user: :class:`abc.Snowflake` The user to kick from their guild....
|coro| Bans a user from the guild. The user must meet the :class:`abc.Snowflake` abc. You must have the :attr:`~Permissions.ban_members` permission to do this. Parameters ----------- user: :class:`abc.Snowflake` The user to ban from their guild. ...
|coro| Unbans a user from the guild. The user must meet the :class:`abc.Snowflake` abc. You must have the :attr:`~Permissions.ban_members` permission to do this. Parameters ----------- user: :class:`abc.Snowflake` The user to unban. reason:...
|coro| Returns the guild's special vanity invite. The guild must be partnered, i.e. have 'VANITY_URL' in :attr:`~Guild.features`. You must have the :attr:`~Permissions.manage_guild` permission to use this as well. Raises ------- Forbidden Y...
|coro| Marks every message in this guild as read. The user must not be a bot user. Raises ------- HTTPException Acking failed. ClientException You must not be a bot user. def ack(self): """|coro| Marks every message in this gui...
Return an :class:`AsyncIterator` that enables receiving the guild's audit logs. You must have the :attr:`~Permissions.view_audit_log` permission to use this. Examples ---------- Getting the first 100 entries: :: async for entry in guild.audit_logs(limit=100): ...
|coro| Returns the widget of the guild. .. note:: The guild must have the widget enabled to get this information. Raises ------- Forbidden The widget for this guild is disabled. HTTPException Retrieving the widget failed. R...