Skip to content

Kruger0/GMHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GitHub license GitHub release GameMaker Discord API GitHub last commit

GMHook Icon

GMHook 2.0.1

GMHook is a Discord Webhook integration system made for GameMaker, implemented with complete message, embed, file and poll support

How to use!

  1. Create a Discord Webhook in your server channel by going to Edit channelIntegrationsWebhooksCreate Webhook. Configure the name, avatar and channel, then copy the webhook URL.

  2. Create a webhook instance and start sending messages:

    // Create webhook instance
    webhook = new DiscordWebhook("YOUR_WEBHOOK_URL");
    
    // Send a simple message
    webhook.SetContent("Hello from GameMaker!")
           .Execute();
  3. Create rich embeds for better presentation:

    // Create an embed
    embed = new DiscordEmbed();
    embed.SetTitle("Game Stats")
         .SetDescription("Player achievements")
         .SetColor(0x00ff00)
         .AddField("Score", string(score), true)
         .AddField("Level", string(level), true);
    
    // Send the embed
    webhook.AddEmbed(embed)
           .Execute();
  4. Call the function webhook.Async(trace) in an Async HTTP event to get the message ID, in order to use features like Processed(), Edit() or Delete():

    // Async HTTP Event
    webhook.Async(true);
    
    // Anywhere
    if (webhook.Processed()) {
        show_debug_message("Message sent successfully!");
    }

Advanced Features

File Uploads

Send screenshots, logs or any file directly to Discord:

// Send a file
webhook.SetContent("Check out this screenshot!")
       .AddFile("screenshot.png")
       .Execute();

// Send a buffer as file
webhook.AddBuffer(my_buffer, "game_data.json")
       .Execute();

// Send an embed with attatched images
embed.SetTitle("Game Screenshot")
     .SetDescription("Latest gameplay")
     .SetImageURL("https://example.com/image.png")      // Use web image
     .SetImageFile("screenshot.png");                   // Or use attached file that is included on the webhook

webhook.AddEmbed(embed);

Interactive Polls

Create polls for community engagement:

// Create a poll
poll = new DiscordPoll("What's your favorite feature?", 24, false);
poll.AddAnswer("Embeds", "📋")
    .AddAnswer("File Upload", "📎")
    .AddAnswer("Polls", "🗳️");

webhook.AddPoll(poll)
       .Execute();

Message Management

Edit or delete messages after sending:

// After successful send, you can edit the message
webhook.SetContent("Updated message!")
       .Edit();

// Or delete it completely
webhook.Delete();

Custom User Identity

Make your webhook appear as different users:

webhook.SetUser("GameBot", "https://example.com/bot_avatar.png")
       .SetContent("Message from custom bot!")
       .Execute();

Batch Operations

Set multiple embeds or fields at once:

// Set multiple embeds at once
embeds_array = [embed1, embed2, embed3];
webhook.SetEmbeds(embeds_array);

// Set multiple fields for an embed
fields_array = [
    {name: "Field 1", value: "Value 1", inline: true},
    {name: "Field 2", value: "Value 2", inline: false}
];
embed.SetFields(fields_array);

Webhook Restrictions

  • No reaction detection: Webhooks cannot detect when users react to messages they send
  • No incoming events: Webhooks are send-only and cannot listen for Discord events
  • No self-reactions: Webhooks cannot add reactions to their own messages

For interactive features requiring user input detection, consider using a Discord bot alongside webhooks.

Complete API Reference

DiscordWebhook Methods

  • SetURL(url) - Change the webhook URL after creation
  • SetUser(username, avatar_url) - Set custom webhook identity
  • SetContent(content) - Set message text content
  • SetPayload(payload) - Set raw payload as a struct or a valid JSON string
  • SetEmbeds(embeds) - Set an array of embeds at once
  • SetTTS(enabled) - Enable text-to-speech
  • AddEmbed(embed) - Attach rich embed
  • AddPoll(poll) - Attach interactive poll
  • AddFile(filename) - Attach file from disk
  • AddBuffer(buffer, name) - Attach buffer as file
  • Execute() - Send new message
  • Edit() - Edit existing message
  • Delete() - Delete message
  • Async(trace) - Process HTTP response with optional debug traces
  • Processed() - Check if request completed
  • Clear() - Clear all webhook data and reset to initial state
  • Destroy() - Destroy webhook object and clean up all resources. Use if the webhook created but not executed

DiscordEmbed Methods

  • SetTitle(title) - Set embed title
  • SetDescription(description) - Set main text
  • SetFields(fields) - Set multiple fields at once using an array
  • SetColor(color) - Set sidebar color
  • SetAuthor(name, icon_url, url) - Set author info
  • SetURL(url) - Make title clickable
  • SetImageURL(url) - Set large image from URL
  • SetImageFile(filename) - Set large image from attached file
  • SetThumbnail(url) - Set small corner image
  • SetFooter(text, icon_url) - Set bottom text
  • SetTimestamp(timestamp) - Set time indicator
  • AddField(name, value, inline) - Add data field

DiscordPoll Methods

  • AddAnswer(text, emoji) - Add poll option with optional emoji (supports both emoji names as strings and emoji IDs as numbers)

Related links