我如何控制 userbot 是否受限?
How i control if an userbot is limited?
如何在不发出 invite/chat 请求的情况下控制用户机器人是否处于 FloodWait 或 PeerFlood(受限)?
我向 SpamBot 发送消息,但它仅在 userbot 受限时通知我,如果在 FloodWait 中则不会。
谢谢,抱歉我的英语不好!
How can I check if my userbot is restricted?
您只能检查自己是否受限,这意味着您无法检查其他用户是否受限。
import asyncio
from telethon import TelegramClient
name = 'test'
api_id = '1043101'
api_hash = '5ade788056adad54e71aa558e38337bc'
client = TelegramClient(name, api_id, api_hash)
client.start(phone=+xxxxxxxxxx)
async def main():
if (await client_get_me()).restricted):
print('I'm restricted')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
请参阅 Telethon docs 以了解如何优雅地处理各种 RPC 错误。
来自文档的 FloodWait 示例:
from telethon import errors
try:
messages = await client.get_messages(chat)
print(messages[0].text)
except errors.FloodWaitError as e:
print('Have to sleep', e.seconds, 'seconds')
time.sleep(e.seconds)
如何在不发出 invite/chat 请求的情况下控制用户机器人是否处于 FloodWait 或 PeerFlood(受限)? 我向 SpamBot 发送消息,但它仅在 userbot 受限时通知我,如果在 FloodWait 中则不会。 谢谢,抱歉我的英语不好!
How can I check if my userbot is restricted?
您只能检查自己是否受限,这意味着您无法检查其他用户是否受限。
import asyncio
from telethon import TelegramClient
name = 'test'
api_id = '1043101'
api_hash = '5ade788056adad54e71aa558e38337bc'
client = TelegramClient(name, api_id, api_hash)
client.start(phone=+xxxxxxxxxx)
async def main():
if (await client_get_me()).restricted):
print('I'm restricted')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
请参阅 Telethon docs 以了解如何优雅地处理各种 RPC 错误。
来自文档的 FloodWait 示例:
from telethon import errors
try:
messages = await client.get_messages(chat)
print(messages[0].text)
except errors.FloodWaitError as e:
print('Have to sleep', e.seconds, 'seconds')
time.sleep(e.seconds)