简体   繁体   English

如何使 discord bot 使用 webhook 从 shell 终端发送彩色文本

[英]How to make discord bot send colored text from shell terminal using webhook

webhook=https://discord.com/api/webhooks/abc123
curl -H "Content-Type: application/json" -X POST -d '{"content":"'"some message"'"}' $webhook

This is just a simple bash script that is used to send a message to discord using webhook.这只是一个简单的 bash 脚本,用于使用 webhook 向 discord 发送消息。 But is there a way to send colored text to discord?但是有没有办法将彩色文本发送到 discord? I know we can type in colored text on discord but how to send it from terminal?我知道我们可以在 discord 上输入彩色文本,但是如何从终端发送呢? To be more clear, how to make the discord bot send colored text?更清楚地说,如何让 discord 机器人发送彩色文本?

One hacky solution from here - https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51#syntax-highlighting 从这里开始的一个 hacky 解决方案 - https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51#syntax-highlighting

is based on syntax highlighting colors.基于语法高亮 colors。

You can try that in Discord UI.您可以在 Discord UI 中进行尝试。

If you post a message like this:如果您发布这样的消息:

```diff
+ line 1 asdasd
+ line 2 qwqwe
```

it should be green (has to contain "+" at the beginning of each line)它应该是绿色的(必须在每行的开头包含“+”)

If you post a message like this:如果您发布这样的消息:

```diff
- line 3 asdasd
- line 4 qwqwe
```

it will be red (has to contain "-" at the beginning of each line)它将是红色的(必须在每行的开头包含“-”)

In shell you need to use double quotes around the message ( -d "..." ), escape quotes and back-ticks inside with a back-slash like \" , and use \n to separate lines:在 shell 中,您需要在消息周围使用双引号( -d "..." ),使用类似\"的反斜杠转义引号和反引号,并使用\n分隔行:

-d "{\"content\": \"\`\`\`diff\n+ green\n\`\`\`\"}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM