【问题标题】:Formatting Discord NodeJS格式化 Discord NodeJS
【发布时间】:2021-09-29 13:32:49
【问题描述】:

我一直在用 Python 为 Discord 编写代码,但我想切换到 JS,因为还有更多。我在格式化一行代码时遇到问题,我下载了这个音乐机器人来测试并熟悉 JS。它正在发送嵌入,但我想要文本。这是代码行:

if (this.textChannel) this.textChannel.send(f"Playing ???? Now playing ${this.current.info.title} - Right Now!");

我知道在 Python 中它会是这样的: await ctx.send(f"Playing ???? Now playing ${this.current.info.title} - Right Now!").

f的等价物是什么?

【问题讨论】:

标签: javascript node.js discord discord.js


【解决方案1】:

在 Javascript 中,使用反引号 (`) 表示 template string

let a = 123;
console.log(`a is ${a}`);

如果您需要在模板字符串中编写反引号(用于 markdown 代码块),您可以使用反斜杠对其进行转义。

let code = "I am some code";
console.log(`\`\`\`${code}\`\`\``);

【讨论】:

  • 感谢您的回复!我将如何将其作为代码块执行,所以我希望 ${this.current.info.title} 成为代码块?
  • 您可以在模板字符串中escape backticks
  • 如果您觉得此答案有用,请将其标记为已接受。
  • 好的!仍然习惯这个我从来没有使用过它。感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 2020-11-07
  • 2015-06-07
  • 2019-01-07
  • 2014-12-12
  • 2018-10-19
  • 2018-10-29
  • 2023-03-11
  • 1970-01-01
相关资源
最近更新 更多