fix(core): discord http request

This commit is contained in:
Andyyy7666
2022-08-11 01:17:13 +02:00
parent e8f461fe56
commit 92a410937d

View File

@@ -10,16 +10,15 @@ local discordErrors = {
[400] = "improper http request", [400] = "improper http request",
[401] = "Discord bot token might be missing or incorrect", [401] = "Discord bot token might be missing or incorrect",
[404] = "user might not be in server.", [404] = "user might not be in server.",
[429] = "Discord bot rate limited.", [429] = "Discord bot rate limited."
} }
-- Used to retrive the players discord server nickname, discord name and tag, and the roles. -- Used to retrive the players discord server nickname, discord name and tag, and the roles.
function NDCore.Functions.GetUserDiscordInfo(discordUserId) function NDCore.Functions.GetUserDiscordInfo(discordUserId)
local data local data
local request = PerformHttpRequest("https://discordapp.com/api/guilds/" .. server_config.guildId .. "/members/" .. discordUserId, function(errorCode, resultData, resultHeaders) local timeout = 0
PerformHttpRequest("https://discordapp.com/api/guilds/" .. server_config.guildId .. "/members/" .. discordUserId, function(errorCode, resultData, resultHeaders)
if errorCode ~= 200 then if errorCode ~= 200 then
print("Error: " .. errorCode .. " " .. discordErrors[errorCode]) print("Error: " .. errorCode .. " " .. discordErrors[errorCode])
return false
end end
local result = json.decode(resultData) local result = json.decode(resultData)
local roles = {} local roles = {}
@@ -31,13 +30,15 @@ function NDCore.Functions.GetUserDiscordInfo(discordUserId)
discordTag = tostring(result.user.username) .. "#" .. tostring(result.user.discriminator), discordTag = tostring(result.user.username) .. "#" .. tostring(result.user.discriminator),
roles = roles roles = roles
} }
return true
end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = "Bot " .. server_config.discordServerToken}) end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = "Bot " .. server_config.discordServerToken})
if request then while not data do
return data Wait(1000)
else timeout = timeout + 1
return false if timeout > 5 then
break
end
end end
return data
end end
-- Get player any identifier, available types: steam, license, xbl, ip, discord, live. -- Get player any identifier, available types: steam, license, xbl, ip, discord, live.