I'm trying to make a calculator command for my discord bot!
In this code i tried to convert the user input into a double (e.g. user inputs: *calculate 1 + 1) and send a message containing the double value! This however didn't work so then i tried converting the double back to a string!
public void onMessageReceived(MessageReceivedEvent event) {
Message message = event.getMessage();
String content = message.getContentRaw();
MessageChannel channel;
channel = event.getChannel();
String[] args = content.split(" ");
if (args[0].equalsIgnoreCase("!calculate")) {
if (args.length == 1) {
channel.sendMessage("error message").queue();
}else {
String input = content;
input = input.replace(args[0], "");
double result = Double.parseDouble(text);
channel.sendMessage(result).queue();
}
}
}
after i put in a double.toString in between the result and the output as it wouldn't print the double.
String output = Double.toString(result);
channel.sendMessage(output).queue();
first attempt had no output! second had a "numberformatexception"! how do i solve this problem?