I am currently learning Java and have decided to work on a discord bot just for fun, but I have ran into a problem. I was working on an announce command that would send an announcement to a certain channel but the problem is that the line breaks do not show up in the output when put in the input (Note: I am using normal line breaks "shift+enter", I am not using "\n"). For example, here is an input I have put in:
-announce Hello there! Hope you're having a wonderful day!
Hello there again! I hope YOU'RE having a wonderful day!
Test
Test
But it sends the embed to the channel looking like this: image
This is my code:
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
String[] args = event.getMessage().getContentRaw().split("\\s+");
String msg = event.getMessage().getContentRaw();
if (args[0].equalsIgnoreCase("-announce")) {
if (args.length < 2) {
EmbedBuilder embed = new EmbedBuilder();
embed
.setDescription("Usage: -announce <test>")
.setColor(Color.CYAN);
event.getChannel().sendMessage(embed.build()).queue();
embed.clear();
} else {
try {
TextChannel textChannel = event.getJDA().getTextChannelById("CHANNEL-ID");
if (textChannel.canTalk()) {
EmbedBuilder embed = new EmbedBuilder();
String message = "";
for (int i = 1; i < args.length; i++) {
message += args[i] + " ";
}
embed
.setColor(Color.CYAN)
.setDescription(message);
textChannel.sendMessage(embed.build()).queue();
embed.clear();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
You're removing all newlines with your split("\\s+")
. You should use a substring
instead:
String message = msg.substring(msg.indexOf(' ') + 1);
embed.setDescription(message);