Jump to content

A little question about webhook discord connection


ZeusXBr

Recommended Posts

I want to do this:

GcsedrG.png

Using webhook, something like this:

-- created by zsenel

local discordWebhookURL = "https://discord.com/api/webhooks/835103134270488596/FY5*********EXAMPLE************yKEaRsKJp4"

function sendDiscordMessage(message)
    sendOptions = {
        formFields = {
            content = "Example:",
            username = "webhook - Example",
            embed = {
                description= "```Some user have typed \"help\" command.```",
                color= null,
                author= {
                    name= "Webhook   -  Example"
                },
                footer = {
                    text = "I want to do this..."
                },
            },
        },
    }
    fetchRemote ( discordWebhookURL, sendOptions, WebhookCallback )
end

function WebhookCallback(responseData) 
    outputDebugString("(Discord webhook callback): responseData: "..responseData)
end

function SendDiscordTestMessage(player, command, ...)
    local msg = table.concat({...}," ") -- for multiple words
    sendDiscordMessage(msg)
end

 

unknown.png  Return < 

 

Thats only a example do i want to do, any kind of help please? ❤️

Edited by ZeusXBr
Link to comment
  • Moderators

This way works for me, to send data as JSON.

function sendDiscordMessage(message)
    local data = {
        content = "Example:",
        username = "Webhook   -  Example",
        embeds = {
            {
                title = "Webhook - Example",
                description = "```Some user have typed \"help\" command.```",
                footer = {
                    text = "I want to do this...",
                }
            }
        }
    }

    local jsonData = toJSON(data)
          jsonData = string.sub(jsonData, 3, #jsonData - 2)

    local sendOptions = {
        headers = {
            ["Content-Type"] = "application/json"
        },
        postData = jsonData,
    }

    fetchRemote ( discordWebhookURL, sendOptions, WebhookCallback )
end

 

  • Thanks 1
Link to comment
11 hours ago, Patrick said:

This way works for me, to send data as JSON.


function sendDiscordMessage(message)
    local data = {
        content = "Example:",
        username = "Webhook   -  Example",
        embeds = {
            {
                title = "Webhook - Example",
                description = "```Some user have typed \"help\" command.```",
                footer = {
                    text = "I want to do this...",
                }
            }
        }
    }

    local jsonData = toJSON(data)
          jsonData = string.sub(jsonData, 3, #jsonData - 2)

    local sendOptions = {
        headers = {
            ["Content-Type"] = "application/json"
        },
        postData = jsonData,
    }

    fetchRemote ( discordWebhookURL, sendOptions, WebhookCallback )
end

 

Thanks a lot.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...