This commit is contained in:
iDutchy 2020-10-17 18:42:19 -05:00
parent a09e096d42
commit d75cd66b90
14 changed files with 128 additions and 5 deletions

View File

@ -20,6 +20,9 @@ labels: bug
<!-- What actually happened. If there is a traceback, please show the entire thing. -->
## Intents
<!-- What intents are you using for your bot? This is the `discord.Intents` class you pass to the client -->
## Checklist
@ -28,6 +31,7 @@ labels: bug
- [ ] I have searched the open issues for duplicates.
- [ ] I have shown the entire traceback, if possible.
- [ ] I have removed my token from display, if visible.
- [ ] I have provided the intents that my bot is using.
## System Information

View File

@ -206,6 +206,9 @@ class GuildChannel:
def __str__(self):
return self.name
def __int__(self):
return self.id
@property
def _sorting_bucket(self):
raise NotImplementedError

View File

@ -239,7 +239,7 @@ class Client:
self._listeners = {}
self.shard_id = options.get('shard_id')
self.shard_count = options.get('shard_count')
colour = options.get('embed_color')
colour = options.get('embed_color', Color.default())
if isinstance(colour, (Color, Colour)):
os.environ['DEFAULT_EMBED_COLOR'] = str(hex(colour))
else:

View File

@ -112,6 +112,9 @@ class Emoji(_EmojiTag):
return '<a:{0.name}:{0.id}>'.format(self)
return "<:{0.name}:{0.id}>".format(self)
def __int__(self):
return self.id
def __repr__(self):
return '<Emoji id={0.id} name={0.name!r} animated={0.animated} managed={0.managed}>'.format(self)

View File

@ -207,6 +207,9 @@ class Guild(Hashable):
def __str__(self):
return self.name
def __int__(self):
return self.id
def __repr__(self):
attrs = (
'id', 'name', 'shard_id', 'chunked'

View File

@ -84,6 +84,9 @@ class Attachment:
""":class:`bool`: Whether this attachment contains a spoiler."""
return self.filename.startswith('SPOILER_')
def __int__(self):
return self.id
def __repr__(self):
return '<Attachment id={0.id} filename={0.filename!r} url={0.url!r}>'.format(self)
@ -385,6 +388,12 @@ class Message:
except KeyError:
continue
def __str__(self):
return self.content
def __int__(self):
return self.id
def __repr__(self):
return '<Message id={0.id} channel={0.channel!r} type={0.type!r} author={0.author!r} flags={0.flags!r}>'.format(self)

View File

@ -99,6 +99,9 @@ class Role(Hashable):
def __str__(self):
return self.name
def __int__(self):
return self.id
def __repr__(self):
return '<Role id={0.id} name={0.name!r}>'.format(self)

View File

@ -92,6 +92,9 @@ class BaseUser(_BaseUser):
def __str__(self):
return '{0.name}#{0.discriminator}'.format(self)
def __int__(self):
return self.id
def __eq__(self, other):
return isinstance(other, _BaseUser) and other.id == self.id

View File

@ -533,6 +533,12 @@ def escape_mentions(text):
This does not include channel mentions.
.. note::
For more granular control over what mentions should be escaped
within messages, refer to the :class:`~discord.AllowedMentions`
class.
Parameters
-----------
text: :class:`str`

View File

@ -322,6 +322,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
If the ``channel`` is a :class:`TextChannel` then the ``user`` parameter
is a :class:`Member`, otherwise it is a :class:`User`.
This requires :attr:`Intents.typing` to be enabled.
:param channel: The location where the typing originated from.
:type channel: :class:`abc.Messageable`
:param user: The user that started typing.
@ -333,6 +335,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a :class:`Message` is created and sent.
This requires :attr:`Intents.messages` to be enabled.
.. warning::
Your bot's own messages and private messages are sent through this
@ -354,6 +358,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
If this occurs increase the :attr:`Client.max_messages` attribute
or use the :func:`on_raw_message_delete` event instead.
This requires :attr:`Intents.messages` to be enabled.
:param message: The deleted message.
:type message: :class:`Message`
@ -369,6 +375,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
If this occurs increase the :attr:`Client.max_messages` attribute
or use the :func:`on_raw_bulk_message_delete` event instead.
This requires :attr:`Intents.messages` to be enabled.
:param messages: The messages that have been deleted.
:type messages: List[:class:`Message`]
@ -380,6 +388,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
If the message is found in the message cache,
it can be accessed via :attr:`RawMessageDeleteEvent.cached_message`
This requires :attr:`Intents.messages` to be enabled.
:param payload: The raw event payload data.
:type payload: :class:`RawMessageDeleteEvent`
@ -391,6 +401,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
If the messages are found in the message cache,
they can be accessed via :attr:`RawBulkMessageDeleteEvent.cached_messages`
This requires :attr:`Intents.messages` to be enabled.
:param payload: The raw event payload data.
:type payload: :class:`RawBulkMessageDeleteEvent`
@ -415,6 +427,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
- The message's embeds were suppressed or unsuppressed.
- A call message has received an update to its participants or ending time.
This requires :attr:`Intents.messages` to be enabled.
:param before: The previous version of the message.
:type before: :class:`Message`
:param after: The current version of the message.
@ -436,6 +450,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
denotes an "embed" only edit, which is an edit in which only the embeds are updated by the Discord
embed server.
This requires :attr:`Intents.messages` to be enabled.
:param payload: The raw event payload data.
:type payload: :class:`RawMessageUpdateEvent`
@ -449,6 +465,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
To get the :class:`Message` being reacted, access it via :attr:`Reaction.message`.
This requires :attr:`Intents.reactions` to be enabled.
:param reaction: The current state of the reaction.
:type reaction: :class:`Reaction`
:param user: The user who added the reaction.
@ -459,6 +477,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a message has a reaction added. Unlike :func:`on_reaction_add`, this is
called regardless of the state of the internal message cache.
This requires :attr:`Intents.reactions` to be enabled.
:param payload: The raw event payload data.
:type payload: :class:`RawReactionActionEvent`
@ -472,6 +492,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
To get the message being reacted, access it via :attr:`Reaction.message`.
This requires :attr:`Intents.reactions` to be enabled.
:param reaction: The current state of the reaction.
:type reaction: :class:`Reaction`
:param user: The user who added the reaction.
@ -482,6 +504,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a message has a reaction removed. Unlike :func:`on_reaction_remove`, this is
called regardless of the state of the internal message cache.
This requires :attr:`Intents.reactions` to be enabled.
:param payload: The raw event payload data.
:type payload: :class:`RawReactionActionEvent`
@ -491,6 +515,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
if the message is not found in the internal message cache, then this event
will not be called. Consider using :func:`on_raw_reaction_clear` instead.
This requires :attr:`Intents.reactions` to be enabled.
:param message: The message that had its reactions cleared.
:type message: :class:`Message`
:param reactions: The reactions that were removed.
@ -501,6 +527,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a message has all its reactions removed. Unlike :func:`on_reaction_clear`,
this is called regardless of the state of the internal message cache.
This requires :attr:`Intents.reactions` to be enabled.
:param payload: The raw event payload data.
:type payload: :class:`RawReactionClearEvent`
@ -510,6 +538,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
if the message is not found in the internal message cache, then this event
will not be called. Consider using :func:`on_raw_reaction_clear_emoji` instead.
This requires :attr:`Intents.reactions` to be enabled.
.. versionadded:: 1.3
:param reaction: The reaction that got cleared.
@ -520,6 +550,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a message has a specific reaction removed from it. Unlike :func:`on_reaction_clear_emoji` this is called
regardless of the state of the internal message cache.
This requires :attr:`Intents.reactions` to be enabled.
.. versionadded:: 1.3
:param payload: The raw event payload data.
@ -530,6 +562,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called whenever a private channel is deleted or created.
This requires :attr:`Intents.messages` to be enabled.
:param channel: The private channel that got created or deleted.
:type channel: :class:`abc.PrivateChannel`
@ -537,6 +571,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called whenever a private group DM is updated. e.g. changed name or topic.
This requires :attr:`Intents.messages` to be enabled.
:param before: The updated group channel's old info.
:type before: :class:`GroupChannel`
:param after: The updated group channel's new info.
@ -558,6 +594,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Note that you can get the guild from :attr:`~abc.GuildChannel.guild`.
This requires :attr:`Intents.guilds` to be enabled.
:param channel: The guild channel that got created or deleted.
:type channel: :class:`abc.GuildChannel`
@ -565,6 +603,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called whenever a guild channel is updated. e.g. changed name, topic, permissions.
This requires :attr:`Intents.guilds` to be enabled.
:param before: The updated guild channel's old info.
:type before: :class:`abc.GuildChannel`
:param after: The updated guild channel's new info.
@ -574,6 +614,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called whenever a message is pinned or unpinned from a guild channel.
This requires :attr:`Intents.guilds` to be enabled.
:param channel: The guild channel that had its pins updated.
:type channel: :class:`abc.GuildChannel`
:param last_pin: The latest message that was pinned as a naive datetime in UTC. Could be ``None``.
@ -585,6 +627,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called whenever an integration is created, modified, or removed from a guild.
This requires :attr:`Intents.integrations` to be enabled.
:param guild: The guild that had its integrations updated.
:type guild: :class:`Guild`
@ -592,6 +636,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called whenever a webhook is created, modified, or removed from a guild channel.
This requires :attr:`Intents.webhooks` to be enabled.
:param channel: The channel that had its webhooks updated.
:type channel: :class:`abc.GuildChannel`
@ -600,6 +646,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a :class:`Member` leaves or joins a :class:`Guild`.
This requires :attr:`Intents.members` to be enabled.
:param member: The member who joined or left.
:type member: :class:`Member`
@ -614,6 +662,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
- nickname
- roles
This requires :attr:`Intents.members` to be enabled.
:param before: The updated member's old info.
:type before: :class:`Member`
:param after: The updated member's updated info.
@ -629,6 +679,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
- username
- discriminator
This requires :attr:`Intents.members` to be enabled.
:param before: The updated user's old info.
:type before: :class:`User`
:param after: The updated user's updated info.
@ -639,6 +691,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a :class:`Guild` is either created by the :class:`Client` or when the
:class:`Client` joins a guild.
This requires :attr:`Intents.guilds` to be enabled.
:param guild: The guild that was joined.
:type guild: :class:`Guild`
@ -656,6 +710,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
In order for this event to be invoked then the :class:`Client` must have
been part of the guild to begin with. (i.e. it is part of :attr:`Client.guilds`)
This requires :attr:`Intents.guilds` to be enabled.
:param guild: The guild that got removed.
:type guild: :class:`Guild`
@ -668,6 +724,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
- Changed AFK timeout
- etc
This requires :attr:`Intents.guilds` to be enabled.
:param before: The guild prior to being updated.
:type before: :class:`Guild`
:param after: The guild after being updated.
@ -680,6 +738,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
To get the guild it belongs to, use :attr:`Role.guild`.
This requires :attr:`Intents.guilds` to be enabled.
:param role: The role that was created or deleted.
:type role: :class:`Role`
@ -687,6 +747,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a :class:`Role` is changed guild-wide.
This requires :attr:`Intents.guilds` to be enabled.
:param before: The updated role's old info.
:type before: :class:`Role`
:param after: The updated role's updated info.
@ -696,6 +758,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a :class:`Guild` adds or removes :class:`Emoji`.
This requires :attr:`Intents.emojis` to be enabled.
:param guild: The guild who got their emojis updated.
:type guild: :class:`Guild`
:param before: A list of emojis before the update.
@ -709,6 +773,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a guild becomes available or unavailable. The guild must have
existed in the :attr:`Client.guilds` cache.
This requires :attr:`Intents.emojis` to be enabled.
:param guild: The :class:`Guild` that has changed availability.
.. function:: on_voice_state_update(member, before, after)
@ -722,6 +788,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
- A member is muted or deafened by their own accord.
- A member is muted or deafened by a guild administrator.
This requires :attr:`Intents.voice_states` to be enabled.
:param member: The member whose voice states changed.
:type member: :class:`Member`
:param before: The voice state prior to the changes.
@ -733,6 +801,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when user gets banned from a :class:`Guild`.
This requires :attr:`Intents.bans` to be enabled.
:param guild: The guild the user got banned from.
:type guild: :class:`Guild`
:param user: The user that got banned.
@ -744,6 +814,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a :class:`User` gets unbanned from a :class:`Guild`.
This requires :attr:`Intents.bans` to be enabled.
:param guild: The guild the user got unbanned from.
:type guild: :class:`Guild`
:param user: The user that got unbanned.
@ -761,6 +833,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
There is a rare possibility that the :attr:`Invite.guild` and :attr:`Invite.channel`
attributes will be of :class:`Object` rather than the respective models.
This requires :attr:`Intents.invites` to be enabled.
:param invite: The invite that was created.
:type invite: :class:`Invite`
@ -779,6 +853,8 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Outside of those two attributes, the only other attribute guaranteed to be
filled by the Discord gateway for this event is :attr:`Invite.code`.
This requires :attr:`Intents.invites` to be enabled.
:param invite: The invite that was deleted.
:type invite: :class:`Invite`

View File

@ -25,11 +25,13 @@ Custom Features
- ``Guild.icon_url`` and ``User.avatar_url`` return the string in stead of Asset. use icon/avatar url_as to get the Asset
- Merged in ext-colors (https://github.com/MGardne8/DiscordPyColours)
- Using Rapptz/discord.py/tree/neo-docs for documentation
- Adding support for ``hex()`` to ``discord.Color``
- Added support for ``hex()`` to ``discord.Color``
- Added ``Client.embed_color`` / ``Bot.embed_color``
- Added ``Client.set_embed_color`` / ``Bot.set_embed_color``
- Added ``TextChannel.can_send``
- Added ``Intents.from_list``
- Added support for ``int()`` to ``discord.User``, ``discord.Member``, ``discord.Role``, ``discord.Guild``, ``discord.Message``, ``discord.TextChannel``, ``discord.VoiceChannel``, ``discord.CategoryChannel``, ``discord.Attachment`` and ``discord.Message``. This will return their id
- Added support for ``str()`` to ``discord.Message``. This will return the message content
Features
--------

View File

@ -157,7 +157,7 @@ For example:
.. code-block:: python3
import discord
intents = discord.Intents()
intents = discord.Intents.default()
intents.members = True
# Somewhere else:

View File

@ -1,3 +1,5 @@
# This example requires the 'members' privileged intents
import discord
from discord.ext import commands
import random
@ -6,7 +8,11 @@ description = '''An example bot to showcase the discord.ext.commands extension
module.
There are a number of utility commands being showcased here.'''
bot = commands.Bot(command_prefix='?', description=description)
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='?', description=description, intents=intents)
@bot.event
async def on_ready():

View File

@ -1,3 +1,5 @@
# This example requires the 'members' privileged intents
import discord
class MyClient(discord.Client):
@ -14,5 +16,8 @@ class MyClient(discord.Client):
await guild.system_channel.send(to_send)
client = MyClient()
intents = discord.Intents.default()
intents.members = True
client = MyClient(intents=intents)
client.run('token')