JDA Send message in Cyrillic results in a bunch of gibberish

25 Views Asked by At
@Override
    public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) {
        TextChannel textChannel = event.getGuild().getTextChannelsByName("channel-name", true).getFirst();
        String userMention = event.getMember().getAsMention();

        String greeting = String.format("Привет, %s. Зайди в канал #roles.", userMention);
        textChannel.sendMessage(greeting).queue();
    }
}

That is my code. I am a beginner only, but I suspect there might be a problem with encoding.

I searched through JDA documentation and didn't find much help. What is the problem here?

1

There are 1 best solutions below

0
lowlight On

I just fixed it, turns out you have this thing called Locale. If you need to process input of different languages it is a best practice to change the defaultLocale.

import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        Locale.setDefault(Locale.of("ru", "RU")); // Locale.of("lang", "country")
    }
}