电报机器人启动,但没有响应!
我的安慰:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/C:/Users/ivan_/.m2/repository/com/google/inject/guice/4.1.0/guice-4.1.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Bot
类:
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException;
import java.util.List;
public class Bot extends TelegramLongPollingBot {
protected Bot(DefaultBotOptions options) {
super(options);
}
public void sendMsg(Message massage, String text){
SendMessage sendMessage = new SendMessage();
sendMessage.enableMarkdown(true);
sendMessage.setChatId(massage.getChatId().toString());
sendMessage.setReplyToMessageId(massage.getMessageId());
sendMessage.setText(text);
try{
sendMessage(sendMessage);
}catch (TelegramApiException e){
e.printStackTrace();
}
}
@Override
public void onUpdateReceived(Update update) {
Message mes = update.getMessage();
if (mes!=null && mes.hasText()){
switch (mes.getText()){
case "/help":
sendMsg(mes,"sd");
break;
}
}
}
public void onUpdatesReceived(List<Update> updates) {
}
public String getBotUsername() {
return "****";
}
public String getBotToken() {
return "***********";
}
}
课程Main
:
public class Main {
private static String bot = "***";
private static String token = "***";
private static String Proxy = "**";
private static Integer Port = 65233;
private static String Proxy_user = "**";
private static String Proxy_Password = "**";
public static void main(String[] args) {
ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
new AuthScope(Proxy,Port),
new UsernamePasswordCredentials(Proxy_user,Proxy_Password));
HttpHost httpHost = new HttpHost(Proxy,Port);
RequestConfig requestConfig = RequestConfig.custom().setProxy(httpHost).setAuthenticationEnabled(true).build();
botOptions.setRequestConfig(requestConfig);
botOptions.setCredentialsProvider(credentialsProvider);
botOptions.setHttpProxy(httpHost);
try {
telegramBotsApi.registerBot(new Bot(botOptions));
} catch (TelegramApiException e) {
e.printStackTrace();
}
}