Home > other >  How to make discord bot send colored text from shell terminal using webhook
How to make discord bot send colored text from shell terminal using webhook

Time:02-06

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. But is there a way to send colored text to discord? I know we can type in colored text on discord but how to send it from terminal? To be more clear, how to make the discord bot send colored text?

CodePudding user response:

One hacky solution from here - https://gist.github.com/matthewzring/9f7bbfd102003963f9be7dbcf7d40e51#syntax-highlighting

is based on syntax highlighting colors.

You can try that in 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:

-d "{\"content\": \"\`\`\`diff\n  green\n\`\`\`\"}"
  •  Tags:  
  • Related