Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local http = game:GetService("HttpService")
- local Client = {}
- Client.__index = Client
- function Client.new(auth)
- local self = setmetatable({}, Client)
- self.auth = auth
- return self
- end
- function Client:send_message(channel_id, content)
- local message = {
- content = content
- }
- -- Convert the message payload to a JSON string
- local json_data = http:JSONEncode(message)
- -- Define the request headers with the Discord bot token
- local headers = {
- ["Authorization"] = self.auth,
- ["Content-Type"] = "application/json"
- }
- -- Send the message to the Discord channel using the http:RequestAsync() method
- local endpoint = ("https://discord.com/api/v9/channels/%s/messages"):format(channel_id)
- local response = syn.request({
- Url = endpoint,
- Method = "POST",
- Headers = headers,
- Body = json_data
- })
- return http:JSONDecode(response.Body)
- end
- function Client:edit_message(channel_id, message_id, content)
- local updated_message = {
- content = content
- }
- -- Convert the updated message content to a JSON string
- local json_data = http:JSONEncode(updated_message)
- -- Define the request headers with the Discord bot token
- local headers = {
- ["Authorization"] = self.auth,
- ["Content-Type"] = "application/json"
- }
- -- Send the updated message to the Discord channel using the http:RequestAsync() method
- local endpoint = ("https://discord.com/api/v9/channels/%s/messages/%s"):format(channel_id, message_id)
- local response = syn.request({
- Url = endpoint,
- Method = "PATCH",
- Headers = headers,
- Body = json_data
- })
- return http:JSONDecode(response.Body)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement