我在 python 中使用远程机器人 API 时遇到问题。如果用户向机器人发送消息并等待响应,同时阻止机器人。我收到此错误,机器人不会响应其他用户:
403,"description":"禁止:机器人被用户阻止
尝试,catch 块没有为我处理这个错误
还有其他想法可以摆脱这种情况吗?如何发现机器人被用户阻止并避免回复此消息?
这是我的代码:
import telebot
import time
@tb.message_handler(func=lambda m: True)
def echo_all(message):
try:
time.sleep(20) # to make delay
ret_msg=tb.reply_to(message, "response message")
print(ret_msg)
assert ret_msg.content_type == 'text'
except TelegramResponseException as e:
print(e) # do not handle error #403
except Exception as e:
print(e) # do not handle error #403
except AssertionError:
print( "!!!!!!! user has been blocked !!!!!!!" ) # do not handle error #403
tb.polling(none_stop=True, timeout=123)
Run Code Online (Sandbox Code Playgroud) 我正在创建一个从另一个类扩展的模块,但我需要使用getBaseContext().我怎样才能在自己的模块中使用它?如果我必须运行活动,那么如果不是如何解决问题该怎么办谢谢
public class TelcoModule extends KrollModule
{
...
// Methods
@Kroll.method
public String GetTelco()
{
TelephonyManager tm =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
String operatorName = tm.getNetworkOperatorName();
return operatorName ;
}
}
Run Code Online (Sandbox Code Playgroud)