Discord webhook module


  • Discord webhook module

    This module manages the process of formatting a message or embedded message and sending this request. The module can be found here.

    API

    
    Discord webhook module for discord messages and embedded messages
    Discord webhook format:- https://discordapp.com/api/webhooks/[webhook id]/[webhook token]
    
    Module (returned function from module)
    id - string
    token - string
    returns a table of functions as followed:-
    
    Message, Embed, Shared
    
    
    ------------------------------------------ Message API ------------------------------------------
    
    NewMessage()
    Creates a new message to send		
    
    Append(txt string, nwLine optional bollean)
    Appends the given text to the current message and include a new line if set
    Returns true or false if the text has been appended to the message
    
    AppendFormattedText(txt string, format array of strings, nwLine optional bollean)
    Appends the given text to the current message while formatting it and include a new line if set
    Valid formats are italics, bold, underline, strike
    Returns true or false if the text has been appended to the message
    
    AppendCodeLine(code string, newLine optional bollean)
    Appends a code line to the current message and include a new line if set
    Returns true or false if the code has been appended to the message
    
    AppendCodeBlock(code string, syntax string optional, newLine optional bollean)
    Appends a code block to the current message with the optional syntax and new line
    Returns true or false if the code has been appended to the message
    
    AppendURL(url string, embedOrTxt nil, string or boolean, newLine optional bollean)
    Appends a raw url, embeded url or a text url and include a new line if set
    Returns true or false if the url has been appended to the message
    
    NewLine()
    Appends a new line to the message
    Returns true or false if a new line has been added
    
    Send(printDebug boolean)
    Sends the message note that this will not clear the message
    Returns a array in the format of {result, messsage}	
    	
    -------------------------------------------------------------------------------------------------
    
    --------------------------------------- Embed Message API ---------------------------------------
    	
    NewEmbedMessage()
    Creates a new embed message, note that it also sets up a new embed
    
    NewEmbed()
    Creates a new embed	within the message
    
    NewField()
    Creates a new embed field 
    
    SetTitle(title string)
    Sets the title of the embed
    Returns true or false if the title has been set
    
    AppendDescription(txt string, newLine optional boolean)
    Append the description to the embed
    Returns true or false if the description has been appended
    
    AppendDescriptionFormattedText(txt string, format array of strings, nwLine optional bollean)
    Appends the given text to the current embed while formatting it and include a new line if set
    Valid formats are italics, bold, underline, strike
    Returns true or false if the text has been appended to the embed field
    
    AppendDescriptionCodeLine(code string, newLine optional bollean)
    Appends a code line to the current embed and include a new line if set
    Returns true or false if the code has been appended to the embed
    
    AppendDescriptiondCodeBlock(code string, syntax string optional, newLine optional bollean)
    Appends a code block to the current embed with the optional syntax and new line
    Returns true or false if the code has been appended to the embed
    
    AppendDescriptionURL(url string, embedOrTxt nil, string or boolean, newLine optional bollean)
    Appends a raw url, embeded url or a text url and include a new line if set
    Returns true or false if the url has been appended to the embed
    
    AppendDescriptionNewLine()
    Appends a new line to the embed
    Returns true or false if a new line has been added
    
    SetURL(url string)
    Sets the url of the embed (This url is also used for the author if none is set)
    Returns true or false if the URL has been set
    
    SetTimestamp(timeStamp string)
    Sets the timestamp of the embed using the format yyyy-mm-ddThh:mm:ss e.g. 2013-03-01T21:10:00
    Returns true or false if the timestamp has been set
    
    SetColor(color Color3)
    Sets the color of the embed
    
    SetFooter(text string, icon optional string)
    Sets the fotter text and icon if set
    Returns true or false if the fotter has been set
    
    SetImage(url string)
    Sets the image of the embed
    Returns true or false if the image has been set
    
    SetThumbnail(url string)
    Sets the thumbnail of the embed
    Returns true or false if the thumbnail has been set
    
    SetAuthor(author string, url optional string, icon optional string)
    Sets the author for the embed
    Returns true or false if the author has been set
    
    SetFieldTitle(title string)
    Sets the title of the embed field
    Returns true or false if the title has been set
    
    AppendFieldText(txt string, newLine optional boolean)
    Appends the given text to the embed field
    Returns true or false if the text has been appended
    
    AppendFieldFormattedText(txt string, format array of strings, nwLine optional bollean)
    Appends the given text to the current embed while formatting it and include a new line if set
    Valid formats are italics, bold, underline, strike
    Returns true or false if the text has been appended to the embed field
    
    AppendFieldCodeLine(code string, newLine optional bollean)
    Appends a code line to the current embed and include a new line if set
    Returns true or false if the code has been appended to the embed
    
    AppendFieldCodeBlock(code string, syntax string optional, newLine optional bollean)
    Appends a code block to the current embed with the optional syntax and new line
    Returns true or false if the code has been appended to the embed
    
    AppendFieldURL(url string, embedOrTxt nil, string or boolean, newLine optional bollean)
    Appends a raw url, embeded url or a text url and include a new line if set
    Returns true or false if the url has been appended to the embed
    
    FieldNewLine()
    Appends a new line to the embed
    Returns true or false if a new line has been added
    
    FieldInline(isInline boolean)
    Sets if the field is to be displayed inline
    
    Send(printDebug boolean)
    Sends the embed message note that this will not clear the embed message
    Returns a array in the format of {result, messsage}	
    
    -------------------------------------------------------------------------------------------------
    
    ------------------------------------------ Shared API -------------------------------------------
    
    SetUserName(name string)
    Sets the name the post will be displayed as (overwrites the def settings)
    
    SetAvatarURL(url string)
    Sets the avatar image the post will be displayed as (overwrites the def settings)
    
    SetTTS(isTTS boolean)
    Sets if the post is a text to speach post
    
    Clear()
    Clears all set settings
    
    Destroy()
    Destroys the web hook
    -------------------------------------------------------------------------------------------------
    

    Example setup

    -- Example setup
    local newWebHook = require(script.DiscordWebHook)
    local webHook = newWebHook('353183945120022550', 'zUFm0Qidk8HwfMFTUIy2l8Sy94PYnurNsTR5uwj14TnH1Mlsr2Aj9UXlq0hkA7ddm_YS') -- example only 
    
    local message = webHook.Message
    local embed = webHook.Embed
    local sharedSettings = webHook.Shared
    
    local img = game:GetService('Players'):GetUserThumbnailAsync(1540993, Enum.ThumbnailType.AvatarThumbnail, Enum.ThumbnailSize.Size420x420)
    
    -- set web hook shared settings
    sharedSettings:SetUserName('kingdom5')
    sharedSettings:SetAvatarURL(img)
    
    -- example message
    message:NewMessage()
    message:Append('Hi', true)
    message:AppendFormattedText('Formatted text', {'bold', 'italics'}, true)
    message:AppendCodeLine('This is a code line', true)
    
    local code = [[
    local a = 'a'
    print(a)
    ]]
    
    message:AppendCodeBlock(code, 'Lua', true)
    message:AppendURL('https://www.roblox.com/', nil, true)
    message:AppendURL('https://www.roblox.com/', true, true)
    message:AppendURL('https://www.roblox.com/', 'Link to roblox', true)
    message:Send(true)
    
    -- message break
    message:NewMessage()
    sharedSettings:SetUserName('kingdom5 break up msg')
    message:Append('msg break', true)
    message:Send(true)
    sharedSettings:SetUserName('kingdom5')
    
    -- embed message example
    embed:NewEmbedMessage()
    embed:SetTitle('This is the embed title')
    embed:AppendDescription('This is the description this can also include *text formats* and [urls](https://www.roblox.com/). fucntions are available to include these')
    embed:SetURL('https://www.roblox.com/')
    embed:SetTimestamp('2013-03-01T21:10:01')
    embed:SetColor(Color3.fromRGB(255, 0, 0))
    embed:SetFooter('This is the footer', img)
    embed:SetThumbnail(img)
    
    embed:NewEmbed()
    embed:SetTitle('This is the second embed title')
    embed:SetColor(Color3.fromRGB(0, 255, 0))
    embed:SetImage(img)
    embed:SetAuthor('This is the author', img, 'https://www.roblox.com/')
    
    embed:NewEmbed()
    embed:SetTitle('This is the third embed title')
    embed:SetColor(Color3.fromRGB(255, 255, 255))
    
    -- using fields examples
    embed:NewField()
    embed:SetFieldTitle('This is a field title') -- a title must be set for a field
    embed:AppendFieldText('This is the field text it also *include formats* and [urls](https://www.roblox.com/). functions are avilable to include these')
    
    embed:NewField()
    embed:SetFieldTitle('Second field')
    embed:AppendFieldText('This is inline')
    embed:FieldInline(true)
    
    embed:NewField()
    embed:SetFieldTitle('Third field')
    embed:AppendFieldText('This also needs to be set inline')
    embed:FieldInline(true)
    embed:Send(true)
    
    -- you can also send the same message again
    message:Send(true)
    

    Output Image

    Img
    Img2


  • @kingdom5 This is amazing. I have something like this but it can't send embeds. I will probably use it, thanks!


  • @kingdom5 Can I ask how this works? It doesn't look like specific values are returned from things like :NewEmbed() and etc.


  • @Thundermaker300 Embeds work in a strange way. You start with creating a new embed message, this then can contain multiple embed messages, note that one is included for you when running the function NewEmbedMessag.

    Each embed can contain a max of 25 fields, note that one is not created for you as it is an optional field (most of the fields are optional)

    So the structure will look something like this:-

    { 
    -- this is the embed message
     {
      -- this is the first embed
      --  fields that the embed has
     },
     {
     -- this is the second embed
     --  fields that the embed has
     }
    }
    

    The code would be:-

    embed:NewEmbedMessage() -- the message has a new embed included by def
    -- setup for first embed
    
    embed:NewEmbed() -- create the second embed
    -- setup for the second embed
    
    message:Send() -- send the message
    
Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.