【发布时间】:2019-05-10 18:09:45
【问题描述】:
我正在构建我的第一个电报机器人。它每 5 秒向用户发送一条消息。
当它发送给一个用户时,它无法接收来自其他聊天的更新。
public void foo(msg, Update update){
msg.setChatId(update.getMessage().getChatId());
for (int i = 1; i < links.size(); i++){
msg.setText(links.get(i));
execute(msg);
}
Thread.sleep(wait * 1000);
}
如何使用线程?我试过在这里创建多个线程
public static void bot(){
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
try {
telegramBotsApi.registerBot(new myBot());
} catch (TelegramApiException e) {
e.printStackTrace();
}
但他试图创建多个机器人并失败了。如果这是可运行函数,则相同:
我该怎么做?我卡住了。我不能在不同的线程中创建这个函数
public void onUpdateReceived(Update update) {
leggi(new SendMessage(), update.getMessage().getText(), update);
//.setChatId(update.getMessage().getChatId())
public void leggi(SendMessage msg, String command, Update update){
if(command.equals("test") {
foo( msg, update);
}
这里有完整的代码...https://github.com/siamoInPochi/Ilsottomarinobot/tree/prova/src/main/java/Ilsottomarinobot
【问题讨论】:
标签: java telegram-bot