From 54ee3835850022ec355a54e895c02a0e8a5a4c14 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 17 Aug 2022 03:51:50 -0400 Subject: [PATCH] [commands] Add warning if Intent.message_content is not enabled --- discord/ext/commands/bot.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index eb1cdee02..050e2c4f1 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -198,6 +198,23 @@ class BotBase(GroupMixin[None]): # 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