Skip to content

ninjubaer/DiscordBuilderAHK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DiscordBuilderAHK

An easy to use discord webhook builder Inspired by the EmbedBuilder from the discord.js library

Docs


 

Initializing

Webhook := Discord.Webhook(
  "https://discord.com/api/webhooks/123456789012345678/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)

the Discord.Webhook() requires your webhook url as a parameter


EmbedBuilder

Discord embeds enhance messages with structured content,
including text, images, and links, improving communication by providing context and visual appeal.

The EmbedBuilder simplifies the process of creating rich embeds for discord webhook. Inspired by the syntax of discordjs' EmbedBuilder

create a new Embed like this:

Embed := EmbedBuilder()

 

EmbedBuilder methods

Discord embeds have multiple contents:

  • Title
  • Description
  • Color
  • Field(s)
  • URL
  • Author
  • Footer
  • TimeStamp
  • Thumbnail
  • Image

with the EmbedBuilder() you can add all of those easily.   .setTitle()

embed.setTitle("example title")

.setDescription()

embed.setDescription("example description")

.setColor()

embed.setColor(0xFFFFFF)

or

embed.setColor(16777215)

.addFields() since we can have multiple fields in an embed, the parameter is an array:

embed.addFields([
  {
    name:"Field1",
    value: "Value of field1",
    inline: true
  },
  {
    name: "Field2",
    value: "value of field2",
    inline: true
  }
])

.setURL()

embed.setURL("https://github.com/ninjubaer/DiscordBuilderAHK")

.setAuthor()

embed.setAuthor({
  name: "example name",
  icon_url: "https://..."
})

.setFooter()

embed.setFooter({
  text: "DiscordBuilder.ahk by ninju"
})

.setTimestamp() sets the timestamp to embed.now()

embed.setTimestamp()

or

embed.setTimestamp("1970-01-01T00:00:00.000Z")

.setThumbnail() and .setImage()

embed.setThumbnail({url:"https://..."})
embed.setImage({url:"https://..."})

 

AttachmentBuilder

The AttachmentBuilder creates an attachment which you can then send through the webhook For example:

Attachment := AttachmentBuilder("config.ini")

The parameter path needs to be a relative path to your A_WorkingDir. Make sure to use

SetWorkingDir(A_ScriptDir)

if you want to use that


 

Attachments in Embeds

The attachments you create with the AttachmentBuilder
can also be used in fields of the EmbedBuilder that require an url. For example:

image := AttachmentBuilder("banner.jpg")
embed.setImage(image.attachmentName)

same thing works with thumbnail.url, author.icon_url or footer.icon_url


&bnsp;

Sending the Webhook

We can send messages to discord webhook like this (only after initializing:

Webhook.Send({
  content: "this is a message"
})

Now if we wanted to send embed(s) (yes you can send multiple!) we do that:

Webhook.Send({
  Embeds: [embed]
})

if you want multiple embeds just add them in the array.

If you want to add attachments or have attachments in the embed, we need to add those to the object:

Webhook.Send({
  embeds: [embed],
  files: [image]
}

Pro Tipp: use "<@" userID ">" in content to get pinged from the webhook

Credits:

CreateFormData by Timplishi converted to v2 and edited by me