Advertisement
henrymistert

SynapseDiscord

Mar 21st, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | Software | 0 0
  1. local http = game:GetService("HttpService")
  2.  
  3. local Client = {}
  4. Client.__index = Client
  5.  
  6. function Client.new(auth)
  7. local self = setmetatable({}, Client)
  8. self.auth = auth
  9. return self
  10. end
  11.  
  12. function Client:send_message(channel_id, content)
  13. local message = {
  14. content = content
  15. }
  16.  
  17. -- Convert the message payload to a JSON string
  18. local json_data = http:JSONEncode(message)
  19.  
  20. -- Define the request headers with the Discord bot token
  21. local headers = {
  22. ["Authorization"] = self.auth,
  23. ["Content-Type"] = "application/json"
  24. }
  25.  
  26. -- Send the message to the Discord channel using the http:RequestAsync() method
  27. local endpoint = ("https://discord.com/api/v9/channels/%s/messages"):format(channel_id)
  28. local response = syn.request({
  29. Url = endpoint,
  30. Method = "POST",
  31. Headers = headers,
  32. Body = json_data
  33. })
  34.  
  35. return http:JSONDecode(response.Body)
  36. end
  37.  
  38. function Client:edit_message(channel_id, message_id, content)
  39. local updated_message = {
  40. content = content
  41. }
  42.  
  43. -- Convert the updated message content to a JSON string
  44. local json_data = http:JSONEncode(updated_message)
  45.  
  46. -- Define the request headers with the Discord bot token
  47. local headers = {
  48. ["Authorization"] = self.auth,
  49. ["Content-Type"] = "application/json"
  50. }
  51.  
  52. -- Send the updated message to the Discord channel using the http:RequestAsync() method
  53. local endpoint = ("https://discord.com/api/v9/channels/%s/messages/%s"):format(channel_id, message_id)
  54. local response = syn.request({
  55. Url = endpoint,
  56. Method = "PATCH",
  57. Headers = headers,
  58. Body = json_data
  59. })
  60.  
  61. return http:JSONDecode(response.Body)
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement