我在JDA上无法使用“\n”进行换行。

huangapple go评论54阅读模式
英文:

I can't make new line with "\n" on JDA

问题

第一次在这里寻求帮助,所以如果我的帖子格式有误,我很抱歉。我的问题是我无法在Java的JDA(Java Discord API)中换行。

当我使用:

eb.setDescription("For \n Example");

它运行得很好,但我正在尝试做这个。

首先,我从配置文件中获取字符串:

String Message = plugin.getConfig().getString("Discord." + "PrivateMessage");

它可以成功地获取字符串,但当我使用 eb.setDescription(Message); 时,消息没有换行。消息中有换行符 \n,但它们并没有创建新的换行。消息显示如下:

"For \n Example" 没有新行。
英文:

first time I am asking for help in here so If my thread format is wrong I am so sorry.My problem is I can't make new line in Java JDA(Java Discord API).

When I use:

eb.setDescription("For \n Example");

It works just fine but I am trying to do this.

First I am getting string from config file:

String Message = plugin.getConfig().getString("Discord." + "PrivateMessage")

It gets the String fine but when I use eb.setDescription(Message);
Message coming without lines. There are new line brackets "\n" in message but they are not making new lines.Message coming like:

"For \n Example" without new lines.

答案1

得分: 1

我假设你实际的字符串在一个文件中,你刚刚将它读出。当你在文件中放入 \n 时,在读取时它不会自动转换为换行符。你可以使用 string = string.replace("\\n", "\n") 进行转换。

英文:

I'm assuming your actual string is in a file and you just read it out. When you put \n in a file that doesn't automatically convert to a newline when you read it. You can do string = string.replace("\\n", "\n") to convert it.

huangapple
  • 本文由 发表于 2020年9月11日 23:02:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63849645.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定