So I have a discord bot where I am trying to send a message every hour. I got that part of it working using the scheduled executor service. It starts when I say !futureson
I want to be able to stop it when I send !futuresoff
However, I cannot get this to work properly. Here is my code:
When I send !futuresoff it recognizes it because it sends my "Futures bot off." message. The shutdown thing isn't working like I want it to though. Could someone point me in the right direction?
I want to be able to stop it when I send !futuresoff
However, I cannot get this to work properly. Here is my code:
Code
ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
String[] args = event.getMessage().getContentRaw().split(" ");
if (args[0].equalsIgnoreCase("!futuresOn")) {
Color red = new Color(255, 0, 0);
Color green = new Color(0, 204, 0);
Runnable futRun = new Runnable() {
public void run() {
EmbedBuilder futuresBot = new EmbedBuilder();
futuresBot.setAuthor("Futures Bot", null, event.getAuthor().getAvatarUrl());
try {
futuresBot.addField("**S&P 500**", getSPY(), false);
futuresBot.addField("**NASDAQ**", getNASDAQ(), false);
futuresBot.addField("**DOW**", getDOW(), false);
if (getSPY().contains("+")) {
futuresBot.setColor(green);
}
else {
futuresBot.setColor(red);
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
futuresBot.setFooter("Cantina Capital", event.getGuild().getIconUrl());
event.getChannel().sendMessage(futuresBot.build()).queue();
}
};
exec.scheduleAtFixedRate(futRun, 0, 1, TimeUnit.HOURS);
}
if (args[0].equalsIgnoreCase("!futuresoff")) {
event.getChannel().sendMessage("Futures bot off.").queue();
exec.shutdown();
}

