I'm working on a whois slash command for a Discord Bot and I want to display the tag for the user selected within a command block but if I use " or ' for the value of the field on the embed, the variable doesn't work therefore I have to use `. The issue with this is, I can't see a way to show the text outputted by the variable as a code block.
My code:
.addFields(
{ name: '__User Information__', value: `**Name:** ${user.tag}\n <:Spacer:1064084066997129277> • Mention: ${user}`, inline:false},
)
CodePudding user response:
You can escape a backtick like so: \`,
So, if you want to add codeblocks inside your embed you can do:
`Example codeblock: \`\`\`This is a codeblock! ${variable}\`\`\``
Here's an example from my bot, which displays the user id and message id inside a codeblock:
`\`\`\`ini\nUser = ${message.member.id}\nID = ${message.id}\`\`\``
The code above roughly translates to:
```ini
User = ${message.member.id}
ID = ${message.id}
```
You can read more about template literals here