• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
  • Eevee Expo's webhost has been having technical issues since Nov. 20th and you might be unable to connect to our site. Staff are also facing issues connecting, so please send a DM to Cat on-site or through Discord directly for faster service!
Post Data to Discord Webhooks

Resource Post Data to Discord Webhooks 1.0

Luka S.J.

Wastage of Time
Member
Joined
Mar 27, 2017
Posts
101
Luka S.J. submitted a new resource:

Post Data to Discord Webhooks - If you ever feel like annoying your server

Hidden Text


Z9H8QIt.png

Hidden Text

...

Read more about this resource...
 
D

Deleted member 1065

Guest
Interesting script :)
I wouldn't have thought about this :q

For those who use a normal Ruby version I made a translation of the script :p
Ruby:
Expand Collapse Copy
require 'json'
require 'net/http'

ENV['SSL_CERT_FILE'] ||= './lib/cert.pem' if $0 == 'Game.rb' # Launched from PSDK

module DiscordWebhooks
  DISCORD_WEBHOOK_URI = URI('<INSERT WEBHOOK URL HERE!>')
 
  module_function
 
  # @overload post(data)
  #   Post data to the default DISCORD_WEBHOOK_URI
  #   @param data [Hash] the webhook data
  # @overload post(url, data)
  #   Post data to a Discord Webhook using an URL or an URI
  #   @param url [URI, String] the Discord Webhook
  #   @param data [Hash] the webhook data
  def post(url, data = url)
    url = DISCORD_WEBHOOK_URI if url.is_a?(Hash)
    url = URI(url) if url.is_a?(String)
    Net::HTTP.post(url, data.to_json, "Content-Type" => "application/json")
  end
end
It works the same way (you can also define a default URL so you just call DiscordWebhooks.post(hash) since the game is "supposed" to only communicate with one server).

I tested with this :
Ruby:
Expand Collapse Copy
DiscordWebhooks.post(
  username: 'Nuri Yuri',
  avatar_url: 'https://yt3.ggpht.com/-ZQxRItl-UQA/AAAAAAAAAAI/AAAAAAAAAIc/OoeMfVC1D0E/s88-mo-c-c0xffffffff-rj-k-no/photo.jpg',
  content: 'Coucou :)',
  embeds: [
    {
      color: 0x961696, # Asking decimal but no need to convert when using 0x :)
      author: {
        name: 'Chat-Tan',
        url: 'https://pokemonworkshop.fr/',
        icon_url: 'https://cdn.discordapp.com/app-icons/186157007500345345/c695c6232a85260b7016684a12773f35.png'
      },
      title: 'Your Game',
      url: 'http://resources.luka-sj.com',
      description: 'Yuri sucessfully traded its [Pikachu](https://www.pokepedia.fr/Pikachu) for a [Meowth](https://www.pokepedia.fr/Miaouss).'
    }
  ]
)

The result is the following on Discord :
discordwebhook.png
 

Luka S.J.

Wastage of Time
Member
Joined
Mar 27, 2017
Posts
101
Having access to all of these standard scripts/modules sure makes life more convenient. Your solution is much more elegant. I might look into the "pbPostData" and HTTP request handlers in Essentials to see if it's possible to make this more standalone. cURL was that "hacky" solution to get the job done with minimal effort (though I had to quickly come up with a proper Hash to JSON parser).
 
D

Deleted member 1065

Guest
Yep.

If you work on the pbPostData make sure you fix the \r\n issue (actually it's only \n and since the HTTP standard specify that field separator is \r\n some servers just respond with 400 - Bad Request).
 

MakerBlack

Trainer
Member
Joined
Nov 23, 2020
Posts
88
Every time I run it, my CMD opens and closes quickly, which bothers the player's screen, how to solve?
 
Back
Top