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

[400 BOT_METHOD_INVALID] - The method can't be used by bots (caused by "messages.GetDialogs" #18

Open
pierluigizagaria opened this issue Nov 29, 2024 · 1 comment

Comments

@pierluigizagaria
Copy link

pierluigizagaria commented Nov 29, 2024

Thank you for the bot.
I'm trying to set it up by using a bot account. After entering the bot token in the first step, this is what I get from the trace.

Traceback (most recent call last):
  File "D:\Files\Code\python\PyWardBot\app\main.py", line 1208, in <module>
    for dialog in user.get_dialogs():
                  ^^^^^^^^^^^^^^^^^^
  File "D:\Files\Code\python\PyWardBot\venv\Lib\site-packages\pyrogram\sync.py", line 42, in async_to_sync_gen
    item, done = loop.run_until_complete(anext(agen))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "D:\Files\Code\python\PyWardBot\venv\Lib\site-packages\pyrogram\sync.py", line 36, in anext
    return await agen.__anext__(), False
           ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Files\Code\python\PyWardBot\venv\Lib\site-packages\pyrogram\methods\chats\get_dialogs.py", line 58, in get_dialogs
    r = await self.invoke(
        ^^^^^^^^^^^^^^^^^^
  File "D:\Files\Code\python\PyWardBot\venv\Lib\site-packages\pyrogram\methods\advanced\invoke.py", line 94, in invoke
    r = await session.invoke(
        ^^^^^^^^^^^^^^^^^^^^^
  File "D:\Files\Code\python\PyWardBot\venv\Lib\site-packages\pyrogram\session\session.py", line 399, in invoke
    return await self.send(query, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Files\Code\python\PyWardBot\venv\Lib\site-packages\pyrogram\session\session.py", line 367, in send
    RPCError.raise_it(result, type(data))
  File "D:\Files\Code\python\PyWardBot\venv\Lib\site-packages\pyrogram\errors\rpc_error.py", line 91, in raise_it
    raise getattr(
pyrogram.errors.exceptions.bad_request_400.BotMethodInvalid: Telegram says: [400 BOT_METHOD_INVALID] - The method can't be used by bots (caused by "messages.GetDialogs")

I've tried using a user account and everything worked fine. Probably some telegram api changes caused this?

@pierluigizagaria
Copy link
Author

pierluigizagaria commented Nov 29, 2024

As the documentation suggests, the .get_dialogs() method is not usable by bots (docs).
I commented the two lines as it seems like the method call is doing nothing. (not really)

for dialog in user.get_dialogs():

Now the bot starts up as expected. However, the method is_identical_to_last is using the get_chat_history api method that suffers the same issue of the first one (docs).

After disabling the "Duplicate text" option from the bot, it skips the method call and now everything seems to work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant