Mudlet Discord Webhook Support

Share your scripts and packages with other Mudlet users.
Post Reply
SynecticLabs
Posts: 4
Joined: Thu Jul 16, 2020 6:49 pm

Mudlet Discord Webhook Support

Post by SynecticLabs »

The function below will allow a Mudlet user to send a message to a Discord server via a webhook.

Code: Select all

function sendToDiscordWebhook(discord_username, avatarurl, message)
  local httpdone = registerAnonymousEventHandler('sysPostHttpDone', 
    function(event, rurl, response)
      if rurl == url then display(r) else return true end
    end, true)

  local httperror = registerAnonymousEventHandler('sysPostHttpError', 
    function(event, response, rurl)
      if rurl == url then display(r) else return true end
    end, true)

  local url = ""
  local data = {
    username = discord_username, 
    avatar_url = avatarurl,
    content = message
  }
  local header = {
    ["Content-Type"] = "application/json",
    --["Content-Length"] = data:len()
  }
  
  postHTTP(yajl.to_string(data), url, header)
  
  killAnonymousEventHandler(httpdone)
  killAnonymousEventHandler(httperror)
end
Place this into a script object, then insert your webhook endpoint into the url variable.

To send a message, you can do something akin to:

Code: Select all

sendToDiscordWebhook("MyBotName", false, "My boring message.")
Put this into a trigger to do fancy things like announcing kills, forwarding clan tells into your server, etc.

Enjoy!

neongrey
Posts: 1
Joined: Wed Nov 18, 2020 4:19 pm

Re: Mudlet Discord Webhook Support

Post by neongrey »

hey, got this working but just wanted to leave this here for anyone else who tries to get this to work-- discord wants null, not false for the avatarurl, and you can also null out the bot name on the trigger too, like so:
Code: [show] | [select all] lua
sendToDiscordWebhook(null, null, "My Boring Message")

User avatar
XMODS
Posts: 6
Joined: Tue Aug 06, 2019 2:06 am

Re: Mudlet Discord Webhook Support

Post by XMODS »

I did a mod of this, with embeds etc, and the package is here...
https://github.com/Xiija/MudletStuff/tr ... rd_Modules

screenshot
Image

seamer
Posts: 5
Joined: Tue Jul 28, 2020 1:19 am

Re: Mudlet Discord Webhook Support

Post by seamer »

Hi xmods, I'm having trouble with this... I have the Webhooks/integration properly, but it looks like each of the aliases is not functioning as expected.. I am able to use dmsg to send with fixing a period in the payload, but no matter what I try for auction/group I just see a blank line sent to discord.

For what its worth, the default dmsg function sends

Code: Select all

content  = ".\n \n"..msg
which just generates a period, a blank line, and then the message.

Any ideas?
Last edited by seamer on Sun Jan 03, 2021 5:32 am, edited 1 time in total.

User avatar
XMODS
Posts: 6
Joined: Tue Aug 06, 2019 2:06 am

Re: Mudlet Discord Webhook Support

Post by XMODS »

Make suer & check that you aren't blocking embeds with settings?
local user, server, and channel all may have a setting for that.

The dmsg alias was set that way to make it easier to read,
if you want to change the dmsg alias, .. just set it to..

content = msg

SynecticLabs
Posts: 4
Joined: Thu Jul 16, 2020 6:49 pm

Re: Mudlet Discord Webhook Support

Post by SynecticLabs »

Oh, this is great seeing this. Thanks for that. You've done a much better job at it.

Post Reply