Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in cog_unload stops module cleanup #6113

Closed
4 tasks done
SebbyLaw opened this issue Dec 2, 2020 · 1 comment
Closed
4 tasks done

Exception in cog_unload stops module cleanup #6113

SebbyLaw opened this issue Dec 2, 2020 · 1 comment
Labels
bug This is a bug with the library.
Milestone

Comments

@SebbyLaw
Copy link
Contributor

SebbyLaw commented Dec 2, 2020

Summary

Throwing an error in a cog's cog_unload method leaves the cog's module to stay in sys.modules and the internal Bot.__extensions list. This means that the cog is stuck in a state where it can't be loaded (since the module it resides in is "still loaded") until the unload_extension is called for a second time to clean up. (For n cogs in an extension raising errors, the extension must be unloaded n + 1 times for the module to be fully unloaded.)

Reproduction Steps

in cogs/BadCog.py:

from discord.ext import commands

class BadCog(commands.Cog):
    def cog_unload(self):
        raise Exception()

    @commands.command()
    async def foo(self, ctx):
        await ctx.send("still loaded!")

def setup(bot):
    bot.add_cog(BadCog())

Using jishaku:

?jsk load cogs.BadCog
📥 cogs.BadCog

?foo
still loaded!

?jsk unload cogs.BadCog
📤⚠️ cogs.BadCog`

?foo << this message receives no response

?jsk unload cogs.BadCog
📤 cogs.BadCog

Expected Results

One of the following:

  • Proper cleanup ignoring exceptions in either Cog._eject, Bot.remove_cog, Bot._remove_module_references, or Bot.unload_extension
  • Atomic unloading, meaning that Cogs are re-loaded to the bot if unloading the extension fails.

Actual Results

I am sad.

Intents

N/A.

Checklist

  • 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

N/A.

@SebbyLaw SebbyLaw added the bug This is a bug with the library. label Dec 2, 2020
@Rapptz
Copy link
Owner

Rapptz commented Dec 3, 2020

So I'm of the opinion that unload callers shouldn't error and if they do then they should get ignored. This is also what happens with e.g. teardown in extensions.

@Rapptz Rapptz closed this as completed in 6ea7fce Dec 4, 2020
@Rapptz Rapptz added this to the v1.6 milestone Dec 4, 2020
diceroll123 added a commit to diceroll123/discord.py that referenced this issue Dec 5, 2020
* Fix incorrect class reference in documentation

* Fix minor markdown typo in migrating.rst

* Support discord.com/invite URL in resolve_invite

* Fix TypeError on missing shard_id kwarg

* Escape masked URLs; Support quotes for as_needed

* Fix reconnecting loop due to failed handshake on region change

* Change PartialInviteGuild.icon_url_as to mimic Guild.icon_url_as

* Fix error raised when using the roles parameter.

* Add versionadded to VoiceClient latency and average_latency

* Update Message.system_content join strings to be up to date.

Fixes Rapptz#4211

* Fix Guild.by_category not showing empty categories.

* Fix a KeyError for channels with no category in Guild.by_category

* Fix various inconsistencies within the documentation (Rapptz#5067)

* [commands] Add a new exception class for command registration errors

* [tasks] Fix issue with default error handler in class context

* [commands] Raise TypeError when Optional is used with Greedy converter

* Add support for Discord templates

* Add support for integrations

* Add support for bulk editing role positions

* [bugs] stop resolving Object for template/invite; remove dupe methods

* Fix typo with voice_client documentation

* Documentation formatting

* Allow Webhook to be hashable and comparable

* Allow more methods to set an audit log reason

* Add a licence and encoding declaration to missing files

* Document raises for Converter.convert

* [docs] fix reference to `Guild` and document `utils.resolve_template`

* Fix TypeError when not specifying roles.

* Don't use a namedtuple for _Overwrites

Fix Rapptz#5109

* Fix detection of some JPEG images without JFIF or Exif info

Closes Rapptz#5143

* Add Guild.change_voice_state to control our voice state.

* Add double backticks for some parameter mentions in the documentation.

* Added exception documentation for Guild.create_voice_channel

* [commands] GroupView.get_command shouldn't raise errors for empty names

* Add gray alias for discord.Colour

* [commands] Add documentation for exceptions in Context.(re)invoke

* Fix typo in on_socket_raw_send documentation

* Add a changelog entry for v1.3.4

* Add documentation on bot_check_once

* Add revisions to check_once docs

* Rewrite of AutoShardedClient to prevent overlapping identify

This is experimental and I'm unsure if it actually works

* Add shard ID to keep alive logger messages

* Can't use %d in here

* Fix AttributeError on reconnection

* Rewrite gateway to use aiohttp instead of websockets

* Use a proper type for the event queue

* Fix voice websocket connections

* Fix READY not firing for multi-processed AutoShardedClient clusters

* Add before_identify_hook to have finer control over IDENTIFY syncing

* Make every shard maintain its own reconnect loop

Previously if a disconnect happened the client would get in a bad state
and certain shards would be double sending due to unhandled exceptions
raising back to Client.connect and causing all shards to be reconnected
again.

This new code overrides Client.connect to have more finer control and
allow each individual shard to maintain its own reconnect loop and then
serially request reconnection to ensure that IDENTIFYs are not
overlapping.

* Handle connection errors during reidentify flow.

* Add shard related connection and resume events.

These include:
* on_shard_resumed
* on_shard_connect
* on_shard_disconnect

* Handle Connection Reset by Peer connection errors.

This should work both on Windows and on Linux.

Apparently these types of blips are considered normal for Discord. So
rather than letting the reconnect logic handler expect these to be
catastrophic, it should handle it specially so it doesn't waste an
IDENTIFY for what ultimately should just be a small networking blip.

This also makes it less noisy for the end-user as these complaints
happen from time to time.

* If we're out of retries just raise the OSError

* Add a timeout for receiving websocket messages.

* Add guild_ready_timeout to control the timeout of GUILD_CREATE stream

This also fixes a timing issue where READY would take far too long to
load for big bot authors.

Closes Rapptz#4112

* Update message references in AutoShardedConnectionState

Fixes Rapptz#5133

* Use a subclass rather than monkey-patching for the websocket

* Propagate exceptions when an unhandled error happens

* Add an exposed way to extract shard-specific information.

Closes Rapptz#2654

* Fix AttributeError from internal queue being double underscore.

* Fix NameError with resolving codes with Template

* Specify where to get max_members in documentation

* Fix typo when creating a guild via template

* Terminate shard processing queue when a clean close is encountered.

Fix Rapptz#5180

* Optimize Channel.permissions_for by not creating temporary objects

This seemed to have shaved a few microseconds:
10.8 µs ± 79.6 ns per loop → 8.53 µs ± 48.1 ns per loop
12 µs ± 613 ns per loop → 8.72 µs ± 30.2 ns per loop

With 100K loops each

* Fix AttributeError when fetching reactions without cache

* Fix gramatical error in Client guild_subscriptions docs

* [tasks] Remove HTTPException as an exception to silently continue for

* Fix endpoint strings with :443 instead of :80

Fix Rapptz#5191
Close Rapptz#5188

* Propagate manual close codes to socket subclass

aiohttp seems to not set it during its state machine flow

* Require people to use templates when making an issue

* Fix NameError and AttributeError in Template and Integrations

* Be defensive in case Discord breaks something with WS URLs again

* [commands] Restart subcommand_passed chain on invoke

Fix Rapptz#5198

* [commands] Provide a way to retrieve time left for a cooldown

* [commands] implement HelpCommand.add/remove_check

* Add missing comma in template.py

* Fix a typo with webhook documentation

* Fixed a typo in message unpinning docs

* Add remaining user flags

* Add changelog for 1.4

* Version bump to 1.4

* Terminate connection if a close code couldn't be handled

* Fix error when trying to clear empty image/thumbnail in embeds

* Extend __path__ with pkgutil to allow editable extensions

* Add changelog for 1.4.1

* Version bump to 1.4.1

* Document on_error "special" behavior

* Add South Korea VoiceRegion

* update the docs on RawReactionActionEvent.member

* Fix letter to be consistent with the rest of the docs

* Fix hyperlink reference to PartialInviteChannel in Client

* Document merging behaviour of AllowedMentions in Messageable.send

* Fix bug with Guild.by_category not showing some channels

If categories come after a child channel in the dictionary mapping for
whatever reason, then the previous code would remove it from the
mapping and set it to []. This commit aims to fix this.

* Version bump for development purposes

* Fix issue with empty overwrites

Fixes Rapptz#5756.

* [commands] Use edited timestamp if provided for cooldown timing

* [tasks] Don't update _next_iteration on retry

* [commands] Added ColorConverter alias

* Don't call close() if we've already been closed in Client.run

* Added __eq__ to Message

* Add COMMUNITY to Guild.features

* Classmethods all and none for AllowedMentions

* [commands] Add subclasses of BadArgument for converters

* [commands] BadBooleanArgument -> BadBoolArgument

* [commands] add require_var_positional

* [docs] remove unresolved doc refs, fix attribute ref

* [commands] Update Bot.command() decorator docs

* Add fetch_message_fast using history endpoint

* Add discord.Colour classmethod dark_theme

* Fix Member.joined_at documentation

* [commands] Fix exception raised in Command invoke hooks.

* [commands] Correct command removing during cog injecting

* Fix comparison for overwrites when checking if a channel is synced

* Add logging to webhooks

Fixes Rapptz#5798

* Handle cloudflare bans on webhook requests

Fixes Rapptz#5221

* Guard uses of the keep alive thread in case they're None

Fixes Rapptz#5800

* Add a more concrete exception for 500 status codes.

Fixes Rapptz#5797

* [tasks] Lazily fetch event loop if one isn't provided

Fixes Rapptz#5808

* Remove caching from AutoShardedClient.shards

* Add missing permission in clone documentation

* Revert "Add fetch_message_fast using history endpoint"

This reverts commit a309088.

A rate limited was added to this method after 5 years defeating the
purpose of it.

* Completely update member references from message inner members.

Fixes Rapptz#5819

* Add labels to the issue templates

* Update issue template to redirect to discussions

* issue/PR templates: use h2 instead of h3

`h2` is the semantically correct heading here, as `h1` is for 
document titles and `h2` is for the top level headings within
a document. `h3` should be used for subheadings of `h2` headings.

* Add competing activity type

* Fix allowed_mentions when sending files

* Add bot.listen() suggestion to on_message faq

* Remove namedtuples to better future guard the library

* Use quotes when installing in the README

Other shells have a hard time with square brackets.

Closes Rapptz#5821

* Add support for message_reference on Message object

* Fix and add documentation

* Implement VoiceProtocol lower level hooks.

This allows changing the connect flow and taking control of it without
relying on internal events or tricks.

* Correct some protocol errors in v4 of voice gateway

* Fix issues with VoiceProtocol docstrsings.

* Properly handle disconnects in voice when force disconnected

* Add support for guild intents

* Handle gateway rate limits by using a rate limiter.

With the new chunking changes this will become necessary and we don't
want to disconnect from having too many outwards requests.

* Change unknown cache log warnings from WARNING -> DEBUG

* Add more close codes that can't be handled for reconnecting.

* Rewrite chunking to work with intents.

This slows down chunking significantly for bots in a large number of
guilds since it goes down from 75 guilds/request to 1 guild/request.
However the logic was rewritten to fire the chunking request
immediately after receiving the GUILD_CREATE rather than waiting for
all the guilds in the ready stream before doing it.

* Handle user updates within GUILD_MEMBER_UPDATE

* All guilds require chunking if opting into it

* Heartbeats bypass the rate limits for gateway

* Use a lock for the gateway rate limiter.

This will allow for higher concurrency in AutoSharded situations where
I can mostly "fire and forget" the chunk requests.

* Maximize concurrency when chunking on AutoSharded clients

* Speed up chunking for guilds with presence intent enabled

* Check for zombie connections through last received payload

The previous code would check zombie connections depending on whether
HEARTBEAT_ACK was received. Unfortunately when there's exceeding
backpressure the connection can terminate since the HEARTBEAT_ACK is
buffered very far away despite it being there, just not received yet.

* Maximize the amount of concurrency while chunking.

In order to reduce our amount of backpressure we need to limit the
amount of concurrent chunk requests we can have so the gateway buffer
has some time to breathe.

* Fix timeouts due to hitting the gateway rate limit

* Explicitly disable the members presence by default

* Add versionadded for intents enum

* Fix Client.request_offline_members no longer working

* Add Guild.chunk and deprecated Client.request_offline_members

* Don't cache members during guild start up if cache is disabled.

This is mainly a half-implemented commit. There are a few more places
where cache consistency is necessary. In the future there will
probably be a member cache policy enum that will be used and cache
consistency will be tackled in part of that larger refactoring.

* Raise if member intent is not enabled

* Allow finer grained control over the member cache.

* Intern status and overwrite strings

* Pass default intents if not explicitly given

* Add a special exception for required privileged intents

* Default MemberCacheFlags based on intents

* Some documentation fixes for MemberCacheFlags and Intents

* Fix up wording in MemberCacheFlags exception

* Disable voice cache in weird intent configurations.

* Fix presence intent docstring

* Mention potential Guild.member_count accuracy issues

* Add documentation for gateway intents

* Use /invites/ instead of /invite/

* Use delete_message_days instead of delete-message-days

* Add support for flag alias

* Fix typos in Intents documentation

* Add chunk_guilds_at_startup and deprecate fetch_offline_members

* More intent related documentation

* More intent documentation.

Mention that you can downgrade the library to revert. Also mention
that intents need to be updated in the code as well as the developer
portal.

* Fix typo in ValueError message

* Make Intent class creation more intuitive

* Fixed incorrectly named 'Intent' class in doc.

`Intent.members` -> `Intents.members`.

* Add Client.intents to query the current intents

Closes Rapptz#5854

* Update intents with small typo fixes

* Guard GUILD_MEMBER_ADD/GUILD_MEMBER_REMOVE from errors

If the guilds intent is disabled all guilds are unavailable. This means
we don't receive a member_count attribute and cannot update it.

* Add warning if guilds intent is disabled.

* Add changelog for v1.5.0

* Add changelog for v1.4.2

* Version bump to v1.5.0

* Some minor documentation fixes.

Make examples all mention where to put it for the unaware.

* Add intents to examples

* Add intents to event reference

* Update intent documentation to use defaults

* Add intents to the issue template

* Add note pointing to discord.AllowedMentions

* Fix typo in event reference

* Use Hashable mixin for Message

* logging.rst: Fix some typos and grammar errors

* Fix Colour.dark_theme docstring.

* Escape multi-line quotes properly

Fix Rapptz#5897

* Properly insert at the end if position is not found when moving.

Fixes Rapptz#5923

* Evict keys when they're set to None in PermissionOverwrite

Fixes Rapptz#5929

* Mark intent alias flags as actual aliases to skip them in __iter__

Fix Rapptz#5945

* Fix disconnect when trying to move to another voice channel.

Not overly proud of this implementation but this allows the library
to differentiate between a 4014 that means "move to another channel" or
"move nowhere". Sometimes the VOICE_STATE_UPDATE comes before the
actual websocket disconnect so special care had to be taken in that
case.

Fix Rapptz#5904

* Fix attribute errors when timing out during chunking start-up

* Add internal method to check if the websocket is currently ratelimited

* Ensure our own member is never evicted from the cache in any policy.

* [commands] Lazily fetch members in discord.Member converters

This makes commands taking members mostly work transparently without
much effort from the user.

* Load member from guild_member_update dispatch

* Allow concurrent calls to guild.chunk()

This allows people who write guild.chunk() calls in highly concurrent
places such as on_message or checks to not spam the gateway with an
actual request and instead waits for the pre-existing request to finish

* Fix error when querying members from the gateway.

I accidentally made this return True instead of the actual member list

* Add changelog for v1.5.1

* Version bump to v1.5.1

* Translation sync with crowdin

* Implement icon_rl_as and cover_image_url_as for AppInfo

* Raise ClientException when members intent is not enabled on guild.fetch_members

* [commands] Update MessageConverter link regex

Remove redundant parts of the MessageConverter regexes and support www

* Emphasize intents in the constructors of the examples

* Raise DiscordServerError for 503 Service Unavailable errors

* Properly document that categories throw 404's on create_invite.

* Add Colour.random factory method

* Clarify Colour.random RNG

* Bump version for development purposes

* Fix error with templates not having access to member cache flags.

This also changes the attribute from having an underscore

Fix Rapptz#5986

* Fix attribute error during rapid disconnects in VoiceClient.

Fix Rapptz#6039

* Clear the connected flag when potentially reconnecting the player

Fix Rapptz#5953

* Bump dependencies for 3.9 to work without build tools

Fix Rapptz#5984, Rapptz#5970

* Suppress the creation of a command window from ffmpeg on Windows

Fix Rapptz#6038

* Add sticker support

* Don't store a user cache if there's no member intent or cache is off

Without a cache or member intent the user cache can get out of date
with no events to update the underlying user in the member object.

Ref: Rapptz#6034

* Ensure member key is not overwritten by author key in MESSAGE_UPDATE

This also coerces the older message to take the member data from the
newer message so the types are not incompatible.

Fix Rapptz#5999

* Sticker implementation cleanup

* [commands] Fetch user if an ID is passed and cache lookup fails.

* Fix preview_asset key name in Sticker

* [commands] Allow setting description of cogs

* Implement role tags.

This comes with:

* The RoleTags class
* Role.is_premium_subscriber()
* Role.is_bot_managed()
* Role.is_integration()
* Guild.self_role
* Guild.premium_subscriber_role

* Add a way to check if the websocket is rate limited.

This is mainly for low level decision making for utilities that need
to know whether to fetch a member by HTTP or to query through the
websocket.

The library already does this trick in some places so it's only fair
that end users possess the same ability as well.

* Fix `discord.RoleTags` resolution

* Implement discord.Message.reply

* Code cleanup involving enums and message replies

* Allow MessageReference to be constructible by users

* Added MessageReference.resolved attribute to get replied to message

* Correct docstring missing ]

* Fix Message.to_reference from the MessageReference changes

* Change reply example to use replies

* Fix `UnboundLocalError` for editing `public_updates_channel`

* [chore] Remove redundant imports

This also removes the historical patch for NullHandler implemented in bbf1c54, as it has been available since Python 3.1.

* [bug] call super constructor for `CustomActivity` to fix `created_at`

* Fix Team.icon_url_as format argument default value

* Add reaction roles example

* Update documentation for rules/updates channels

* Add support for chunking AsyncIterator objects

* [commands] Cog unload failures are swallowed.

Fix Rapptz#6113

Co-authored-by: JohnyTheCarrot <tuurmartens4@gmail.com>
Co-authored-by: Tarek <13603398+Taarek@users.noreply.github.com>
Co-authored-by: apple502j <33279053+apple502j@users.noreply.github.com>
Co-authored-by: Anurag <30367300+anurag-7@users.noreply.github.com>
Co-authored-by: NCPlayz <chowdhurynadir0@outlook.com>
Co-authored-by: Jeffrey <22608443+Jefffrey@users.noreply.github.com>
Co-authored-by: Tsumiki <mirkoiz@hotmail.de>
Co-authored-by: Rapptz <rapptz@gmail.com>
Co-authored-by: Sebastian Law <44045823+SebbyLaw@users.noreply.github.com>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Josh <josh.ja.butt@gmail.com>
Co-authored-by: Skezza <36114463+SkezzaB@users.noreply.github.com>
Co-authored-by: Znunu <61394004+Znunu@users.noreply.github.com>
Co-authored-by: James <gobot1234yt@gmail.com>
Co-authored-by: James <50501825+Gobot1234@users.noreply.github.com>
Co-authored-by: AXVin <35896758+AXVin@users.noreply.github.com>
Co-authored-by: Jaime Garcia Jr <jjgarcia2725@gmail.com>
Co-authored-by: Jaime Garcia Jr <40704782+JJgar2725@users.noreply.github.com>
Co-authored-by: Riley S <30989490+ShineyDev@users.noreply.github.com>
Co-authored-by: Tyler North <1326564+tnoff@users.noreply.github.com>
Co-authored-by: Dan Hess <danielman0@yahoo.com>
Co-authored-by: Xua <17090652+XuaTheGrate@users.noreply.github.com>
Co-authored-by: ELginas <42967362+ELginas@users.noreply.github.com>
Co-authored-by: Bryan Forbes <bryan@reigndropsfall.net>
Co-authored-by: Vexs <mxgifford@gmail.com>
Co-authored-by: Patrick <jehyeokchoe@gmail.com>
Co-authored-by: Zomatree <39768508+Zomatree@users.noreply.github.com>
Co-authored-by: sinus-x <14353790+sinus-x@users.noreply.github.com>
Co-authored-by: Nanofaux <62013808+Nanofaux@users.noreply.github.com>
Co-authored-by: parafoxia <43846948+parafoxia@users.noreply.github.com>
Co-authored-by: alkatar21 <61387986+alkatar21@users.noreply.github.com>
Co-authored-by: Andres Torres <34612646+TurretAA12@users.noreply.github.com>
Co-authored-by: Alex Nørgaard <Umbra@AbstractUmbra.xyz>
Co-authored-by: Saphielle Akiyama <64285270+Saphielle-Akiyama@users.noreply.github.com>
Co-authored-by: Simon Beal <5381483+muddyfish@users.noreply.github.com>
Co-authored-by: khazhyk <khazhy@gmail.com>
Co-authored-by: Skye Im <fluffyterran@gmail.com>
Co-authored-by: BluePhoenixGame <38372706+BluePhoenixGame@users.noreply.github.com>
Co-authored-by: rodovia <64744799+rodovia@users.noreply.github.com>
Co-authored-by: Duck <43281440+CrunchyDuck@users.noreply.github.com>
Co-authored-by: iomintz <io@mintz.cc>
Co-authored-by: iDutchy <42503862+iDutchy@users.noreply.github.com>
Co-authored-by: PikalaxALT <PikalaxALT@users.noreply.github.com>
Co-authored-by: Michael <8661717+sgtlaggy@users.noreply.github.com>
Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>
Co-authored-by: Nekokatt <nekoka.tt@outlook.com>
Co-authored-by: ChristopherJHart <christopherjhart95@gmail.com>
Co-authored-by: Eric Chan <67029526+Fresh-Mouse@users.noreply.github.com>
Co-authored-by: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com>
Co-authored-by: numbermaniac <5206120+numbermaniac@users.noreply.github.com>
Co-authored-by: Florian Spieß <business@minnced.club>
Co-authored-by: Lukas <lukas@localhost.localdomain>
Co-authored-by: Jonathan Feenstra <jonathan.feenstra@upcmail.nl>
Co-authored-by: Harmon <Harmon758@gmail.com>
Co-authored-by: webtax-gh <72332327+webtax-gh@users.noreply.github.com>
Co-authored-by: Caio Alexandre <contato.kaiyo@gmail.com>
Co-authored-by: SNVMK <sidzahroman@gmail.com>
Co-authored-by: Kippiii <ianorzel@gmail.com>
Co-authored-by: RocketRace <35444188+RocketRace@users.noreply.github.com>
diceroll123 added a commit to diceroll123/discord.py that referenced this issue Dec 7, 2020
* Fix minor markdown typo in migrating.rst

* Support discord.com/invite URL in resolve_invite

* Fix TypeError on missing shard_id kwarg

* Escape masked URLs; Support quotes for as_needed

* Fix reconnecting loop due to failed handshake on region change

* Change PartialInviteGuild.icon_url_as to mimic Guild.icon_url_as

* Fix error raised when using the roles parameter.

* Add versionadded to VoiceClient latency and average_latency

* Update Message.system_content join strings to be up to date.

Fixes Rapptz#4211

* Fix Guild.by_category not showing empty categories.

* Fix a KeyError for channels with no category in Guild.by_category

* Fix various inconsistencies within the documentation (Rapptz#5067)

* [commands] Add a new exception class for command registration errors

* [tasks] Fix issue with default error handler in class context

* [commands] Raise TypeError when Optional is used with Greedy converter

* Add support for Discord templates

* Add support for integrations

* Add support for bulk editing role positions

* [bugs] stop resolving Object for template/invite; remove dupe methods

* Fix typo with voice_client documentation

* Documentation formatting

* Allow Webhook to be hashable and comparable

* Allow more methods to set an audit log reason

* Add a licence and encoding declaration to missing files

* Document raises for Converter.convert

* [docs] fix reference to `Guild` and document `utils.resolve_template`

* Fix TypeError when not specifying roles.

* Don't use a namedtuple for _Overwrites

Fix Rapptz#5109

* Fix detection of some JPEG images without JFIF or Exif info

Closes Rapptz#5143

* Add Guild.change_voice_state to control our voice state.

* Add double backticks for some parameter mentions in the documentation.

* Added exception documentation for Guild.create_voice_channel

* [commands] GroupView.get_command shouldn't raise errors for empty names

* Add gray alias for discord.Colour

* [commands] Add documentation for exceptions in Context.(re)invoke

* Fix typo in on_socket_raw_send documentation

* Add a changelog entry for v1.3.4

* Add documentation on bot_check_once

* Add revisions to check_once docs

* Rewrite of AutoShardedClient to prevent overlapping identify

This is experimental and I'm unsure if it actually works

* Add shard ID to keep alive logger messages

* Can't use %d in here

* Fix AttributeError on reconnection

* Rewrite gateway to use aiohttp instead of websockets

* Use a proper type for the event queue

* Fix voice websocket connections

* Fix READY not firing for multi-processed AutoShardedClient clusters

* Add before_identify_hook to have finer control over IDENTIFY syncing

* Make every shard maintain its own reconnect loop

Previously if a disconnect happened the client would get in a bad state
and certain shards would be double sending due to unhandled exceptions
raising back to Client.connect and causing all shards to be reconnected
again.

This new code overrides Client.connect to have more finer control and
allow each individual shard to maintain its own reconnect loop and then
serially request reconnection to ensure that IDENTIFYs are not
overlapping.

* Handle connection errors during reidentify flow.

* Add shard related connection and resume events.

These include:
* on_shard_resumed
* on_shard_connect
* on_shard_disconnect

* Handle Connection Reset by Peer connection errors.

This should work both on Windows and on Linux.

Apparently these types of blips are considered normal for Discord. So
rather than letting the reconnect logic handler expect these to be
catastrophic, it should handle it specially so it doesn't waste an
IDENTIFY for what ultimately should just be a small networking blip.

This also makes it less noisy for the end-user as these complaints
happen from time to time.

* If we're out of retries just raise the OSError

* Add a timeout for receiving websocket messages.

* Add guild_ready_timeout to control the timeout of GUILD_CREATE stream

This also fixes a timing issue where READY would take far too long to
load for big bot authors.

Closes Rapptz#4112

* Update message references in AutoShardedConnectionState

Fixes Rapptz#5133

* Use a subclass rather than monkey-patching for the websocket

* Propagate exceptions when an unhandled error happens

* Add an exposed way to extract shard-specific information.

Closes Rapptz#2654

* Fix AttributeError from internal queue being double underscore.

* Fix NameError with resolving codes with Template

* Specify where to get max_members in documentation

* Fix typo when creating a guild via template

* Terminate shard processing queue when a clean close is encountered.

Fix Rapptz#5180

* Optimize Channel.permissions_for by not creating temporary objects

This seemed to have shaved a few microseconds:
10.8 µs ± 79.6 ns per loop → 8.53 µs ± 48.1 ns per loop
12 µs ± 613 ns per loop → 8.72 µs ± 30.2 ns per loop

With 100K loops each

* Fix AttributeError when fetching reactions without cache

* Fix gramatical error in Client guild_subscriptions docs

* [tasks] Remove HTTPException as an exception to silently continue for

* Fix endpoint strings with :443 instead of :80

Fix Rapptz#5191
Close Rapptz#5188

* Propagate manual close codes to socket subclass

aiohttp seems to not set it during its state machine flow

* Require people to use templates when making an issue

* Fix NameError and AttributeError in Template and Integrations

* Be defensive in case Discord breaks something with WS URLs again

* [commands] Restart subcommand_passed chain on invoke

Fix Rapptz#5198

* [commands] Provide a way to retrieve time left for a cooldown

* [commands] implement HelpCommand.add/remove_check

* Add missing comma in template.py

* Fix a typo with webhook documentation

* Fixed a typo in message unpinning docs

* Add remaining user flags

* Add changelog for 1.4

* Version bump to 1.4

* Terminate connection if a close code couldn't be handled

* Fix error when trying to clear empty image/thumbnail in embeds

* Extend __path__ with pkgutil to allow editable extensions

* Add changelog for 1.4.1

* Version bump to 1.4.1

* Document on_error "special" behavior

* Add South Korea VoiceRegion

* update the docs on RawReactionActionEvent.member

* Fix letter to be consistent with the rest of the docs

* Fix hyperlink reference to PartialInviteChannel in Client

* Document merging behaviour of AllowedMentions in Messageable.send

* Fix bug with Guild.by_category not showing some channels

If categories come after a child channel in the dictionary mapping for
whatever reason, then the previous code would remove it from the
mapping and set it to []. This commit aims to fix this.

* Version bump for development purposes

* Fix issue with empty overwrites

Fixes Rapptz#5756.

* [commands] Use edited timestamp if provided for cooldown timing

* [tasks] Don't update _next_iteration on retry

* [commands] Added ColorConverter alias

* Don't call close() if we've already been closed in Client.run

* Added __eq__ to Message

* Add COMMUNITY to Guild.features

* Classmethods all and none for AllowedMentions

* [commands] Add subclasses of BadArgument for converters

* [commands] BadBooleanArgument -> BadBoolArgument

* [commands] add require_var_positional

* [docs] remove unresolved doc refs, fix attribute ref

* [commands] Update Bot.command() decorator docs

* Add fetch_message_fast using history endpoint

* Add discord.Colour classmethod dark_theme

* Fix Member.joined_at documentation

* [commands] Fix exception raised in Command invoke hooks.

* [commands] Correct command removing during cog injecting

* Fix comparison for overwrites when checking if a channel is synced

* Add logging to webhooks

Fixes Rapptz#5798

* Handle cloudflare bans on webhook requests

Fixes Rapptz#5221

* Guard uses of the keep alive thread in case they're None

Fixes Rapptz#5800

* Add a more concrete exception for 500 status codes.

Fixes Rapptz#5797

* [tasks] Lazily fetch event loop if one isn't provided

Fixes Rapptz#5808

* Remove caching from AutoShardedClient.shards

* Add missing permission in clone documentation

* Revert "Add fetch_message_fast using history endpoint"

This reverts commit a309088.

A rate limited was added to this method after 5 years defeating the
purpose of it.

* Completely update member references from message inner members.

Fixes Rapptz#5819

* Add labels to the issue templates

* Update issue template to redirect to discussions

* issue/PR templates: use h2 instead of h3

`h2` is the semantically correct heading here, as `h1` is for 
document titles and `h2` is for the top level headings within
a document. `h3` should be used for subheadings of `h2` headings.

* Add competing activity type

* Fix allowed_mentions when sending files

* Add bot.listen() suggestion to on_message faq

* Remove namedtuples to better future guard the library

* Use quotes when installing in the README

Other shells have a hard time with square brackets.

Closes Rapptz#5821

* Add support for message_reference on Message object

* Fix and add documentation

* Implement VoiceProtocol lower level hooks.

This allows changing the connect flow and taking control of it without
relying on internal events or tricks.

* Correct some protocol errors in v4 of voice gateway

* Fix issues with VoiceProtocol docstrsings.

* Properly handle disconnects in voice when force disconnected

* Add support for guild intents

* Handle gateway rate limits by using a rate limiter.

With the new chunking changes this will become necessary and we don't
want to disconnect from having too many outwards requests.

* Change unknown cache log warnings from WARNING -> DEBUG

* Add more close codes that can't be handled for reconnecting.

* Rewrite chunking to work with intents.

This slows down chunking significantly for bots in a large number of
guilds since it goes down from 75 guilds/request to 1 guild/request.
However the logic was rewritten to fire the chunking request
immediately after receiving the GUILD_CREATE rather than waiting for
all the guilds in the ready stream before doing it.

* Handle user updates within GUILD_MEMBER_UPDATE

* All guilds require chunking if opting into it

* Heartbeats bypass the rate limits for gateway

* Use a lock for the gateway rate limiter.

This will allow for higher concurrency in AutoSharded situations where
I can mostly "fire and forget" the chunk requests.

* Maximize concurrency when chunking on AutoSharded clients

* Speed up chunking for guilds with presence intent enabled

* Check for zombie connections through last received payload

The previous code would check zombie connections depending on whether
HEARTBEAT_ACK was received. Unfortunately when there's exceeding
backpressure the connection can terminate since the HEARTBEAT_ACK is
buffered very far away despite it being there, just not received yet.

* Maximize the amount of concurrency while chunking.

In order to reduce our amount of backpressure we need to limit the
amount of concurrent chunk requests we can have so the gateway buffer
has some time to breathe.

* Fix timeouts due to hitting the gateway rate limit

* Explicitly disable the members presence by default

* Add versionadded for intents enum

* Fix Client.request_offline_members no longer working

* Add Guild.chunk and deprecated Client.request_offline_members

* Don't cache members during guild start up if cache is disabled.

This is mainly a half-implemented commit. There are a few more places
where cache consistency is necessary. In the future there will
probably be a member cache policy enum that will be used and cache
consistency will be tackled in part of that larger refactoring.

* Raise if member intent is not enabled

* Allow finer grained control over the member cache.

* Intern status and overwrite strings

* Pass default intents if not explicitly given

* Add a special exception for required privileged intents

* Default MemberCacheFlags based on intents

* Some documentation fixes for MemberCacheFlags and Intents

* Fix up wording in MemberCacheFlags exception

* Disable voice cache in weird intent configurations.

* Fix presence intent docstring

* Mention potential Guild.member_count accuracy issues

* Add documentation for gateway intents

* Use /invites/ instead of /invite/

* Use delete_message_days instead of delete-message-days

* Add support for flag alias

* Fix typos in Intents documentation

* Add chunk_guilds_at_startup and deprecate fetch_offline_members

* More intent related documentation

* More intent documentation.

Mention that you can downgrade the library to revert. Also mention
that intents need to be updated in the code as well as the developer
portal.

* Fix typo in ValueError message

* Make Intent class creation more intuitive

* Fixed incorrectly named 'Intent' class in doc.

`Intent.members` -> `Intents.members`.

* Add Client.intents to query the current intents

Closes Rapptz#5854

* Update intents with small typo fixes

* Guard GUILD_MEMBER_ADD/GUILD_MEMBER_REMOVE from errors

If the guilds intent is disabled all guilds are unavailable. This means
we don't receive a member_count attribute and cannot update it.

* Add warning if guilds intent is disabled.

* Add changelog for v1.5.0

* Add changelog for v1.4.2

* Version bump to v1.5.0

* Some minor documentation fixes.

Make examples all mention where to put it for the unaware.

* Add intents to examples

* Add intents to event reference

* Update intent documentation to use defaults

* Add intents to the issue template

* Add note pointing to discord.AllowedMentions

* Fix typo in event reference

* Use Hashable mixin for Message

* logging.rst: Fix some typos and grammar errors

* Fix Colour.dark_theme docstring.

* Escape multi-line quotes properly

Fix Rapptz#5897

* Properly insert at the end if position is not found when moving.

Fixes Rapptz#5923

* Evict keys when they're set to None in PermissionOverwrite

Fixes Rapptz#5929

* Mark intent alias flags as actual aliases to skip them in __iter__

Fix Rapptz#5945

* Fix disconnect when trying to move to another voice channel.

Not overly proud of this implementation but this allows the library
to differentiate between a 4014 that means "move to another channel" or
"move nowhere". Sometimes the VOICE_STATE_UPDATE comes before the
actual websocket disconnect so special care had to be taken in that
case.

Fix Rapptz#5904

* Fix attribute errors when timing out during chunking start-up

* Add internal method to check if the websocket is currently ratelimited

* Ensure our own member is never evicted from the cache in any policy.

* [commands] Lazily fetch members in discord.Member converters

This makes commands taking members mostly work transparently without
much effort from the user.

* Load member from guild_member_update dispatch

* Allow concurrent calls to guild.chunk()

This allows people who write guild.chunk() calls in highly concurrent
places such as on_message or checks to not spam the gateway with an
actual request and instead waits for the pre-existing request to finish

* Fix error when querying members from the gateway.

I accidentally made this return True instead of the actual member list

* Add changelog for v1.5.1

* Version bump to v1.5.1

* Translation sync with crowdin

* Implement icon_rl_as and cover_image_url_as for AppInfo

* Raise ClientException when members intent is not enabled on guild.fetch_members

* [commands] Update MessageConverter link regex

Remove redundant parts of the MessageConverter regexes and support www

* Emphasize intents in the constructors of the examples

* Raise DiscordServerError for 503 Service Unavailable errors

* Properly document that categories throw 404's on create_invite.

* Add Colour.random factory method

* Clarify Colour.random RNG

* Bump version for development purposes

* Fix error with templates not having access to member cache flags.

This also changes the attribute from having an underscore

Fix Rapptz#5986

* Fix attribute error during rapid disconnects in VoiceClient.

Fix Rapptz#6039

* Clear the connected flag when potentially reconnecting the player

Fix Rapptz#5953

* Bump dependencies for 3.9 to work without build tools

Fix Rapptz#5984, Rapptz#5970

* Suppress the creation of a command window from ffmpeg on Windows

Fix Rapptz#6038

* Add sticker support

* Don't store a user cache if there's no member intent or cache is off

Without a cache or member intent the user cache can get out of date
with no events to update the underlying user in the member object.

Ref: Rapptz#6034

* Ensure member key is not overwritten by author key in MESSAGE_UPDATE

This also coerces the older message to take the member data from the
newer message so the types are not incompatible.

Fix Rapptz#5999

* Sticker implementation cleanup

* [commands] Fetch user if an ID is passed and cache lookup fails.

* Fix preview_asset key name in Sticker

* [commands] Allow setting description of cogs

* Implement role tags.

This comes with:

* The RoleTags class
* Role.is_premium_subscriber()
* Role.is_bot_managed()
* Role.is_integration()
* Guild.self_role
* Guild.premium_subscriber_role

* Add a way to check if the websocket is rate limited.

This is mainly for low level decision making for utilities that need
to know whether to fetch a member by HTTP or to query through the
websocket.

The library already does this trick in some places so it's only fair
that end users possess the same ability as well.

* Fix `discord.RoleTags` resolution

* Implement discord.Message.reply

* Code cleanup involving enums and message replies

* Allow MessageReference to be constructible by users

* Added MessageReference.resolved attribute to get replied to message

* Correct docstring missing ]

* Fix Message.to_reference from the MessageReference changes

* Change reply example to use replies

* Fix `UnboundLocalError` for editing `public_updates_channel`

* [chore] Remove redundant imports

This also removes the historical patch for NullHandler implemented in bbf1c54, as it has been available since Python 3.1.

* [bug] call super constructor for `CustomActivity` to fix `created_at`

* Fix Team.icon_url_as format argument default value

* Add reaction roles example

* Update documentation for rules/updates channels

* Add support for chunking AsyncIterator objects

* [commands] Cog unload failures are swallowed.

Fix Rapptz#6113

* Add created_at property to PartialEmoji

Also fixed docstring for PartialEmoji.url

Co-authored-by: Tarek <13603398+Taarek@users.noreply.github.com>
Co-authored-by: apple502j <33279053+apple502j@users.noreply.github.com>
Co-authored-by: Anurag <30367300+anurag-7@users.noreply.github.com>
Co-authored-by: NCPlayz <chowdhurynadir0@outlook.com>
Co-authored-by: Jeffrey <22608443+Jefffrey@users.noreply.github.com>
Co-authored-by: Tsumiki <mirkoiz@hotmail.de>
Co-authored-by: Rapptz <rapptz@gmail.com>
Co-authored-by: Sebastian Law <44045823+SebbyLaw@users.noreply.github.com>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Josh <josh.ja.butt@gmail.com>
Co-authored-by: Skezza <36114463+SkezzaB@users.noreply.github.com>
Co-authored-by: Znunu <61394004+Znunu@users.noreply.github.com>
Co-authored-by: James <gobot1234yt@gmail.com>
Co-authored-by: James <50501825+Gobot1234@users.noreply.github.com>
Co-authored-by: AXVin <35896758+AXVin@users.noreply.github.com>
Co-authored-by: Jaime Garcia Jr <jjgarcia2725@gmail.com>
Co-authored-by: Jaime Garcia Jr <40704782+JJgar2725@users.noreply.github.com>
Co-authored-by: Riley S <30989490+ShineyDev@users.noreply.github.com>
Co-authored-by: Tyler North <1326564+tnoff@users.noreply.github.com>
Co-authored-by: Dan Hess <danielman0@yahoo.com>
Co-authored-by: Xua <17090652+XuaTheGrate@users.noreply.github.com>
Co-authored-by: ELginas <42967362+ELginas@users.noreply.github.com>
Co-authored-by: Bryan Forbes <bryan@reigndropsfall.net>
Co-authored-by: Vexs <mxgifford@gmail.com>
Co-authored-by: Patrick <jehyeokchoe@gmail.com>
Co-authored-by: Zomatree <39768508+Zomatree@users.noreply.github.com>
Co-authored-by: sinus-x <14353790+sinus-x@users.noreply.github.com>
Co-authored-by: Nanofaux <62013808+Nanofaux@users.noreply.github.com>
Co-authored-by: parafoxia <43846948+parafoxia@users.noreply.github.com>
Co-authored-by: alkatar21 <61387986+alkatar21@users.noreply.github.com>
Co-authored-by: Andres Torres <34612646+TurretAA12@users.noreply.github.com>
Co-authored-by: Alex Nørgaard <Umbra@AbstractUmbra.xyz>
Co-authored-by: Saphielle Akiyama <64285270+Saphielle-Akiyama@users.noreply.github.com>
Co-authored-by: Simon Beal <5381483+muddyfish@users.noreply.github.com>
Co-authored-by: khazhyk <khazhy@gmail.com>
Co-authored-by: Skye Im <fluffyterran@gmail.com>
Co-authored-by: BluePhoenixGame <38372706+BluePhoenixGame@users.noreply.github.com>
Co-authored-by: rodovia <64744799+rodovia@users.noreply.github.com>
Co-authored-by: Duck <43281440+CrunchyDuck@users.noreply.github.com>
Co-authored-by: iomintz <io@mintz.cc>
Co-authored-by: iDutchy <42503862+iDutchy@users.noreply.github.com>
Co-authored-by: PikalaxALT <PikalaxALT@users.noreply.github.com>
Co-authored-by: Michael <8661717+sgtlaggy@users.noreply.github.com>
Co-authored-by: Muhammad Hamza <muhammadhamza1311@gmail.com>
Co-authored-by: Nekokatt <nekoka.tt@outlook.com>
Co-authored-by: ChristopherJHart <christopherjhart95@gmail.com>
Co-authored-by: Eric Chan <67029526+Fresh-Mouse@users.noreply.github.com>
Co-authored-by: PythonCoderAS <13932583+PythonCoderAS@users.noreply.github.com>
Co-authored-by: numbermaniac <5206120+numbermaniac@users.noreply.github.com>
Co-authored-by: Florian Spieß <business@minnced.club>
Co-authored-by: Lukas <lukas@localhost.localdomain>
Co-authored-by: Jonathan Feenstra <jonathan.feenstra@upcmail.nl>
Co-authored-by: Harmon <Harmon758@gmail.com>
Co-authored-by: webtax-gh <72332327+webtax-gh@users.noreply.github.com>
Co-authored-by: Caio Alexandre <contato.kaiyo@gmail.com>
Co-authored-by: SNVMK <sidzahroman@gmail.com>
Co-authored-by: Kippiii <ianorzel@gmail.com>
Co-authored-by: RocketRace <35444188+RocketRace@users.noreply.github.com>
yagomichalak pushed a commit to yagomichalak/discord.py that referenced this issue May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug with the library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants