首页 > 解决方案 > 我做一个要求我创建一个电报机器人机器人的任务

问题描述

package org.example;

import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;

public class App {
    public static void main( String[] args ) {
        try {
            TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
            botsApi.registerBot(new s261251Bot());
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
}


package org.example;


import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

public class s261251Bot extends TelegramLongPollingBot {

    @Override
    public String getBotUsername() {
        return "username";
    }

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

    @Override
    public void onUpdateReceived(Update update) {
        SendMessage message = new SendMessage();
        message.setChatId(String.valueOf((update.getMessage().getChatId())));
        message.setText("hello " + update.getMessage().getFrom().getFirstName() +" " +  "\nInsert your matric number." + update.getMessage().getText());
        try {
            execute(message);
        }catch (TelegramApiException e){
            e.printStackTrace();
        }
    }

}

我输入了正确的用户名和令牌,但在这里我将其替换为其他

我不断收到此错误:

C:\Users\safwa\Documents\IntelliJ\assignment-2-safwan0908\src\main\java\my\assignment2\src\main\java\org\example\s261251Bot.java:9:8 java: 无法访问 java。未找到 java.util.concurrent.CompletableFuture 的 util.concurrent.CompletableFuture 类文件

标签: javabotstelegram

解决方案


我有同样的问题。确保在项目和框架中使用正确或相同的 Java 版本。

有关更多详细信息,请阅读这篇文章

就我而言,我使用这些属性(如文章中所述)更新了我的 Maven 版本:

<properties>
  <maven.compiler.source>11</maven.compiler.source>
  <maven.compiler.target>11</maven.compiler.target>
</properties>

或者

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>LATEST</version>
      <configuration>
        <source>11</source>
        <target>11</target>
      </configuration>
    </plugin>
  </plugins>
</build>

推荐阅读