2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Fix filters.command not working with multiple running bots

Closes #864
This commit is contained in:
Dan 2022-04-24 11:56:07 +02:00
parent 78efb04b40
commit 41f16a17c9
3 changed files with 5 additions and 11 deletions

View File

@ -286,6 +286,9 @@ class Client(Methods):
self.disconnect_handler = None
# Username used for mentioned bot commands, e.g.: /start@usernamebot
self.username = None
self.loop = asyncio.get_event_loop()
def __enter__(self):

View File

@ -745,11 +745,6 @@ linked_channel = create(linked_channel_filter)
# region command_filter
# Used by the command filter below
username = None
def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = "/", case_sensitive: bool = False):
"""Filter commands, i.e.: text messages starting with "/" or any other custom prefix.
@ -772,12 +767,7 @@ def command(commands: Union[str, List[str]], prefixes: Union[str, List[str]] = "
command_re = re.compile(r"([\"'])(.*?)(?<!\\)\1|(\S+)")
async def func(flt, client: pyrogram.Client, message: Message):
# Username shared among all commands; used for mention commands, e.g.: /start@username
global username
if username is None:
username = (await client.get_me()).username or ""
username = client.username or ""
text = message.text or message.caption
message.command = None

View File

@ -48,4 +48,5 @@ class Initialize:
await self.dispatcher.start()
await Syncer.add(self)
self.username = (await self.get_me()).username
self.is_initialized = True