我正在做一个需要我创建一个电报机器人的任务

eqzww0vc  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(267)
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.util.concurrent.completablefuture的java.util.concurrent.completablefuture类文件

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题