Skip to content Skip to sidebar Skip to footer

How Can I Add A Variable In A Code Block In A Discord Message

How can I write a code block (using the discord.js library) in a Discord message like this: I am trying with the variable num, but it still gets recognized as text and doesn't ge

Solution 1:

The image you put is not an embed, it's just a message where someone has been mentioned, and so it's yellow.

To make a code block in Discord you have to type a normal message like this:

```
your code text here
```

Discord will then use markdown to display it as a code block. For further help on Discord markdown, please see this article.

If you're trying to use that num variable inside a string, you should start and end that string with backticks (`). Please note that if you want to put other backticks in the string you have to escape them with a backward slash (\). Here's an example:

`\`\`\`\nYour text: ${num}\n\`\`\``

You can always append the variable with a plus + operator:

"```\nYour text: " + num + "\n```"

Post a Comment for "How Can I Add A Variable In A Code Block In A Discord Message"