Skip to content

Commit

Permalink
[commands] Add warning if Intent.message_content is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Aug 17, 2022
1 parent cdce8fa commit 54ee383
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions discord/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ def __init__(

# internal helpers

async def _async_setup_hook(self) -> None:
# self/super() resolves to Client/AutoShardedClient
await super()._async_setup_hook() # type: ignore
prefix = self.command_prefix

# This has to be here because for the default logging set up to capture
# the logging calls, they have to come after the `Client.run` call.
# The best place to do this is in an async init scenario
if not self.intents.message_content: # type: ignore
trigger_warning = (
(callable(prefix) and prefix is not when_mentioned)
or isinstance(prefix, str)
or (isinstance(prefix, collections.abc.Iterable) and len(list(prefix)) >= 1)
)
if trigger_warning:
_log.warning('Privileged message content intent is missing, commands may not work as expected.')

def dispatch(self, event_name: str, /, *args: Any, **kwargs: Any) -> None:
# super() will resolve to Client
super().dispatch(event_name, *args, **kwargs) # type: ignore
Expand Down

0 comments on commit 54ee383

Please sign in to comment.