1

I've been coding with Python for Discord but I wanted to make the switch to JS as there is more. I'm having trouble formatting a line of code, I've downloaded this music bot to test and be come familiar with JS. It was sending an embed but I want text. Here is the line of code:

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

I know in Python it would be something like: await ctx.send(f"Playing Now playing ${this.current.info.title} - Right Now!").

What is the equivalent to f?

Lauren Yim
  • 12,700
  • 2
  • 32
  • 59
Toyu
  • 119
  • 7
  • Please do not use a stack snippet for code that isn't runnable. Stack snippets are only meant for HTML, CSS, and JavaScript code that can be run on a browser. Please format your code using a [code block](//meta.stackoverflow.com/q/251361/8289918) instead. – Lauren Yim Sep 29 '21 at 05:30
  • 1
    Does this answer your question? [JavaScript equivalent of Python's parameterised string.format() function](https://stackoverflow.com/questions/41520792/javascript-equivalent-of-pythons-parameterised-string-format-function) – Lauren Yim Sep 29 '21 at 05:32

1 Answers1

1

In Javascript, use backticks (`) for a template string

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

If you need to write backticks (for markdown code block) within a template string, you can escape them with backslashes.

let code = "I am some code";
console.log(`\`\`\`${code}\`\`\``);
Ricky Mo
  • 6,285
  • 1
  • 14
  • 30
  • Thanks for your response! How would I do that as a code block so I want ${this.current.info.title} to be a code block? – Toyu Sep 24 '21 at 01:34
  • You can [escape backticks](https://stackoverflow.com/questions/35803959/template-literals-with-nested-backticks-in-es6) within the template string. – Ricky Mo Sep 24 '21 at 01:37
  • Please mark this answer as accepted if you find it useful. – Ricky Mo Sep 24 '21 at 01:41
  • Yep done! Still getting use to this i've never used it. Thanks for your help! – Toyu Sep 24 '21 at 01:57