在 Python 中将用户添加到 Telegram 组时如何修复 FloodWaitError?
How to fix FloodWaitError when adding a user to a Telegram group inPython?
我不知道出了什么问题,但我一直在制作我的程序。有人对此有任何想法吗?
这是我遇到的错误:
*Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Telegram Marketing\add members in channel\add members.py", line 50, in <module>
user_to_add = client.get_input_entity(user['username'])
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\sync.py", line 39, in syncified
return loop.run_until_complete(coro)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\client\users.py", line 404, in get_input_entity
await self._get_entity_from_string(peer))
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\client\users.py", line 516, in _get_entity_from_string
result = await self(
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\client\users.py", line 47, in __call__
raise errors.FloodWaitError(request=r, capture=diff)
telethon.errors.rpcerrorlist.FloodWaitError: A wait of 71180 seconds is required (caused by ResolveUsernameRequest)
Unexpected Error *
我的代码:
channel = client(GetFullChannelRequest(channel_username))
mode = 1
for user in users:
try:
print ("Adding {}".format(user['id']))
if mode == 1:
if user['username'] == "":
continue
user_to_add = client.get_input_entity(user['username'])
else:
sys.exit("Invalid Mode Selected. Please Try Again.")
client(InviteToChannelRequest(channel,[user_to_add]))
print("Waiting 60 Seconds...")
time.sleep(60)
except PeerFloodError:
print("Getting Flood Error from telegram. Script is stopping now. Please try again after some time.")
time.sleep(900)
except UserPrivacyRestrictedError:
print("The user's privacy settings do not allow you to do this. Skipping.")
except:
traceback.print_exc()
print("Unexpected Error")
continue
试试这个:
client(InviteToChannelRequest(channel_username,[user['username']]))
GetFullChannelRequest returns ChatFull 并将其用作 InviteToChannelRequest 的输入将引发类型错误。任何类实体都可以。
- 频道邀请link
- 频道用户名
- 频道用户id
可以用作InviteToChannelRequest 的频道参数。
还有,
- 用户名,
- 用户编号,
- phone个数
将适用于用户参数。
我不知道出了什么问题,但我一直在制作我的程序。有人对此有任何想法吗?
这是我遇到的错误:
*Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Telegram Marketing\add members in channel\add members.py", line 50, in <module>
user_to_add = client.get_input_entity(user['username'])
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\sync.py", line 39, in syncified
return loop.run_until_complete(coro)
File "c:\users\administrator\appdata\local\programs\python\python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\client\users.py", line 404, in get_input_entity
await self._get_entity_from_string(peer))
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\client\users.py", line 516, in _get_entity_from_string
result = await self(
File "c:\users\administrator\appdata\local\programs\python\python38\lib\site-packages\telethon\client\users.py", line 47, in __call__
raise errors.FloodWaitError(request=r, capture=diff)
telethon.errors.rpcerrorlist.FloodWaitError: A wait of 71180 seconds is required (caused by ResolveUsernameRequest)
Unexpected Error *
我的代码:
channel = client(GetFullChannelRequest(channel_username))
mode = 1
for user in users:
try:
print ("Adding {}".format(user['id']))
if mode == 1:
if user['username'] == "":
continue
user_to_add = client.get_input_entity(user['username'])
else:
sys.exit("Invalid Mode Selected. Please Try Again.")
client(InviteToChannelRequest(channel,[user_to_add]))
print("Waiting 60 Seconds...")
time.sleep(60)
except PeerFloodError:
print("Getting Flood Error from telegram. Script is stopping now. Please try again after some time.")
time.sleep(900)
except UserPrivacyRestrictedError:
print("The user's privacy settings do not allow you to do this. Skipping.")
except:
traceback.print_exc()
print("Unexpected Error")
continue
试试这个:
client(InviteToChannelRequest(channel_username,[user['username']]))
GetFullChannelRequest returns ChatFull 并将其用作 InviteToChannelRequest 的输入将引发类型错误。任何类实体都可以。
- 频道邀请link
- 频道用户名
- 频道用户id
可以用作InviteToChannelRequest 的频道参数。 还有,
- 用户名,
- 用户编号,
- phone个数
将适用于用户参数。