如何在Discord消息的代码块中添加变量 [英] How can I add a variable in a code block in a Discord message

查看:46
本文介绍了如何在Discord消息的代码块中添加变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在这样的Discord消息中编写代码块(使用discord.js库):

How can I write a code block (using the discord.js library) in a Discord message like this:

我正在尝试使用变量 num ,但它仍会被识别为文本,并且不会被替换为实际值

I am trying with the variable num, but it still gets recognized as text and doesn't get replaced with the actual value

.addField("```change ${num}```");

推荐答案

您放置的图像不是嵌入的,它只是一条提及某人的消息,因此它是黄色的.

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

要在Discord中创建代码块,您必须输入如下常规消息:

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

```
your code text here
```

Discord随后将使用markdown将其显示为代码块.有关Discord降价的更多帮助,请参见

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

如果要在字符串中使用该 num 变量,则应以反引号(`)开头和结尾.请注意,如果要在字符串中放入其他反引号,则必须使用反斜杠( \ )对其进行转义.
这是一个示例:

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```"

这篇关于如何在Discord消息的代码块中添加变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆