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

Cannot forward message if I don't interact with group first #4411

Closed
3 tasks done
Faycop opened this issue Jul 18, 2024 · 1 comment
Closed
3 tasks done

Cannot forward message if I don't interact with group first #4411

Faycop opened this issue Jul 18, 2024 · 1 comment

Comments

@Faycop
Copy link

Faycop commented Jul 18, 2024

Code that causes the issue

message = await client.get_messages(spam_lists[list_name]['chat_id'], ids=message_id)
                for i in range(0, len(groups), bulk_size):
                    bulk = groups[i:i + bulk_size]
                    for group in bulk:
                        retries = 0
                        while retries < 3:
                            try:
                                await fetch_chat_info(client, group)  # Manual polling
                                await client.get_entity(PeerChannel(group))

                                await client.forward_messages(group, message)
                                spam_lists[list_name]['last_sent'][group] = datetime.now(italy_tz).isoformat()
                                break
                            except ValueError:
                                logging.warning(f"Group {group} not accessible. Skipping.")
                                break
                            except errors.RPCError as e:
                                logging.error(f"Error sending message to group {group}: {e}")
                                retries += 1
                                await asyncio.sleep(2)
                        if retries == 3:
                            logging.error(f"Failed to send message to group {group} after 3 retries.")
                    await asyncio.sleep(delay / 1000)

Expected behavior

I am expecting to see the message forwarded.

Actual behavior

In the logs I get the "Invalid object ID for a chat" error because it didn't found the identity for the gruop via chat_id.
If I'm forwarding a message in the group manually then the code is executed perfectly.

Traceback

2024-07-18T17:29:29.664509+00:00 app[worker.1]: ERROR:root:Error sending message to group -1229581945: Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead (caused by ForwardMessagesRequest)
2024-07-18T17:29:31.746386+00:00 app[worker.1]: ERROR:root:Error sending message to group -1229581945: Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead (caused by ForwardMessagesRequest)
2024-07-18T17:29:33.833484+00:00 app[worker.1]: ERROR:root:Error sending message to group -1229581945: Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead (caused by ForwardMessagesRequest)
2024-07-18T17:29:35.836516+00:00 app[worker.1]: ERROR:root:Failed to send message to group -1229581945 after 3 retries.
2024-07-18T17:29:36.275161+00:00 app[worker.1]: ERROR:root:Error sending message to group -1177688883: Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead (caused by ForwardMessagesRequest)
2024-07-18T17:29:38.356095+00:00 app[worker.1]: ERROR:root:Error sending message to group -1177688883: Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead (caused by ForwardMessagesRequest)
2024-07-18T17:29:40.611554+00:00 app[worker.1]: ERROR:root:Error sending message to group -1177688883: Invalid object ID for a chat. Make sure to pass the right types, for instance making sure that the request is designed for chats (not channels/megagroups) or otherwise look for a different one more suited\nAn example working with a megagroup and AddChatUserRequest, it will fail because megagroups are channels. Use InviteToChannelRequest instead (caused by ForwardMessagesRequest)
2024-07-18T17:29:42.612171+00:00 app[worker.1]: ERROR:root:Failed to send message to group -1177688883 after 3 retries.

Telethon version

1.36

Python version

3.12.4

Operating system (including distribution name and version)

Linux (Hosted on heroku)

Other details

I am developing a userbot that among the other things spams its advertise in over 100 groups every 4-6 hour so I cannot have the possibility to interact manually with each group...

I also saw this post (#4345) but I don't know how I can implement it in my code, I'm kinda new on Python and Telethon, sorry in advance.

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.
@Lonami
Copy link
Member

Lonami commented Jul 18, 2024

Spamming is against the ToS, and the library cannot interact in any other way with just IDs.

@Lonami Lonami closed this as completed Jul 18, 2024
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

2 participants