Introduction
I fully understand that using Discord Webhooks is not looked upon as a good thing as Discord primary use is for social encounters and communities. But currently Discord is something I understand enough to send HTTP requests to and fully get the information. I will of course be moving to a database if I get the resources and look more into possibilities.
The issue
This code use to work and suddently it has stopped working when none of our scripters have edited any of its components. I tried to heed the help of some other scripters to no resolution. Hence I am here on the forum asking for your help.
Main Code
local WebhookId = "INSERT ID HERE"
local WebhookToken = "INSERT TOKEN HERE"
server = nil
service = nil
local Http = game:GetService("HttpService")
local webHook = require(script.WebhookAPI)
local PlaceName = game:GetService('MarketplaceService'):GetProductInfo(game.PlaceId).Name
return function()
function LvlFromNum(p)
local level = server.Admin.GetLevel(p)
if level >= 4 then
return 'Creator'
elseif level >= 3 then
return 'Owner'
elseif level >= 2 then
return 'Admin'
elseif level >= 1 then
return 'Mod'
else
return 'Player'
end
end
service.Events.CommandRan:connect(function(p,tab)
local msg = tab.message
local command = tab.command
local args = tab.args
local index = tab.index
local table = tab.table
local ran = tab.ran
local error = tab.error
local level = server.Admin.GetLevel(p)
wait(1)
local Discord_Webhook = webHook.new(WebhookId,WebhookToken)
if ran then
local arg = ""
if args and #args > 1 then
for i,v in pairs(args) do
arg = arg..","..v
end
else
arg = args[1]
end
-- So you know what type of admin, put the group ID.
local rank= p:GetRoleInGroup(5121069)
if rank == "Guest" then
rank = "Other/Admined"
end
local IMG = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=200&Format=Png&username="..p.Name
Discord_Webhook:post{
username = 'SR Logging',
["embeds"] = {{
["title"] = "**Command Logs**",
["type"] = "rich",
["color"] = tonumber(0xb51b20),
["thumbnail"] = {["url"] = IMG},
["footer"] = {
["text"] = "System created for SR",
["icon_url"] = "https://cdn.discordapp.com/attachments/636740004890017792/636748580639735828/256-256-5fbc60a4335d01cd9c35dcf8fae02410.png"},
["fields"] = {
{
["name"] = "Player :person_with_blond_hair:",
["value"] = "["..tostring(p.Name)..' | '..LvlFromNum(p).."](https://roblox.com/users/"..p.UserId.."/profile)",
["inline"] = true
},
{
["name"] = "Command :link:",
["value"] = tostring("`"..msg.."`"),
["inline"] = true
},
{
["name"] = "Rank :first_place:",
["value"] = rank,
["inline"] = true
},
{
["name"] = "Place :house:",
["value"] = tostring("["..game:GetService('MarketplaceService'):GetProductInfo(game.PlaceId).Name.. " | "..game.PlaceId.."](https://roblox.com/games/"..game.PlaceId.."/r)"),
["inline"] = true
},
{
["name"] = "Time :clock1:",
["value"] = tostring(service.GetTime()).. " (UTC)",
["inline"] = true
}
}
}}
}
end
end)
end
The Webhook API
This is a table for the API
local webHook = {}
webHook.__index = webHook
local Http = game:GetService("HttpService")
function webHook.new(id,key)
local mt = setmetatable({id=id,key=key}, webHook)
return mt
end
function webHook:post(config,host)
local data = nil
local success = pcall(function()
data = Http:JSONEncode(config)
end)
if not success then
warn("Conversion error, please re-check your data.")
return
end
Http:PostAsync("https://discordapp.com/api/webhooks/"..self.id.."/"..self.key,data)
end
return webHook
The Question
What is the error or why is it not working? (Also some extra information this code is scripted for Adonis)