Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preindex/2d594459f094ebda51f75b176145e7e6 to your computer and use it in GitHub Desktop.
Save preindex/2d594459f094ebda51f75b176145e7e6 to your computer and use it in GitHub Desktop.
sends messages to a discord channel using a bot via http POST
-- Post a message to discord api via a bot
-- Originally created by ianklatzco, forked and ported to lua by xxxYoloxxx999#2166 (preindex)
-- You don't need a library to do this, you just need something that runs lua to execute and a request function.
local channelId = 'your_id_goes_here'
local botToken = 'your_token_here'
local ToPost = { -- Stuff you need to post
['content'] = 'hello world!'
}
local baseURL = string.format('https://discordapp.com/api/channels/%s/messages', channelID)
local headers = {
['Authorization'] = string.format('Bot %s', botToken),
['Content-Type'] = 'application/json',
['User-Agent'] = 'xxxYoloxxx999#2166 (https://system-exodus.com, v0.1)'
}
-- Request using coro.request
local request = coro.request('POST', baseURL, headers, ToPost)
-- Request using any request function
local Request = request({
Url = baseURL,
Method = 'POST',
Headers = headers,
Body = ToPost
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment