gpt4 book ai didi

java - 尝试在 Spring Boot 应用程序中连接到 Telegram Bot 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 09:34:49 24 4
gpt4 key购买 nike

我无法解决我的 Spring Boot 应用程序的问题,我尝试创建自己的 Telegram 机器人。创建 Spring 容器并启动应用程序后,我在日志中看到相同的错误: Error logs

2019-06-17 23:26:33.117 ERROR 3340 --- [gram Connection] Telegram Bots Api : BOTSESSION

Bot Impl :

public TelegramBot(BotProperties botProperties) {
this.botProperties = botProperties;
}

@PostConstruct
public void init() {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
try {
telegramBotsApi.registerBot(new TelegramBot(botProperties));
logger.info("bot successfully register");
} catch (TelegramApiException e) {
logger.error(e.getMessage(), e);
}
}

@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
System.out.println(update.getMessage().getText());
}
}

@Override
public String getBotUsername() {
return botProperties.getBotName();
}

@Override
public String getBotToken() {
return botProperties.getBotToken();
}
}

主类:

public class TelegramApplication {
public static void main(String[] args) {
ApiContextInitializer.init();
SpringApplication.run(TelegramApplication.class, args);
}
}

最佳答案

如果访问机器人,请验证一次只有一台服务器。 Telegram Bot 地址一次只能由一台服务器访问。如果您在本地有一台服务器,而另一台服务器在另一台服务器上运行,那么当您尝试在本地连接它时,它会抛出同样的错误。

如果您使用开发工具重建代码而不重新启动,请尝试停止应用程序并重新启动它。它应该可以工作。

关于java - 尝试在 Spring Boot 应用程序中连接到 Telegram Bot 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56638732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com