# Discord Webhooks (http)

This cool little plugin sends a POST request to a Discord webhook and allow users to send a message to a channel. Some things that could be added or changed would be to send all chat messages to discord, prevent users from using `@everyone` or mentioning users, and running it async so it doesn't slow down the server.

## Code

{% code title="main.lua" %}

```lua
-- Imports
unirest = import("com.mashape.unirest.http.Unirest")
color = newInstance("#.wrappers.ChatColorWrapper", {plugin.getPlugin()})

webhookUrl = "https://discordapp.com/api/webhooks/532360268223741952/1XLKZg9o3a93AMui2BauKUY7SPTWYe2ec_D9gf2UFEvuJ09L8OHJcSXf4j6HoD7j1Cq5"

local discordCommand = plugin.addCommand({name="discord", permission="lukkit.command.discord"}, function(cmd)
    -- Convert arguments into a single string
    argString = ''
    for i, arg in ipairs(cmd:getArgs()) do
        argString = argString .. arg
    end

    -- Make POST request
    response = unirest:post(webhookUrl):field("username", cmd:getSender():getName()):field("content", argString):asString()

    -- Tell user
    cmd.getSender():sendMessage(color.GREEN .. 'Message sent!')
end)

```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lukkit.net/examples/discord-webhooks-http.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
