From d3540a05f6784c92c669fb7049a3b160285acc7b Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Tue, 13 Dec 2022 17:28:20 +0100 Subject: [PATCH] fix: user not found in server --- server/functions.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/server/functions.lua b/server/functions.lua index 49ae40e..7109e4f 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -50,12 +50,28 @@ function NDCore.Functions.GetUserDiscordInfo(discordUserId) end local result = json.decode(resultData) local roles = {} - for _, roleId in pairs(result.roles) do - roles[roleId] = roleId + local nickname = "" + local tag = "" + if result and result.roles then + for _, roleId in pairs(result.roles) do + roles[roleId] = roleId + end + if result.nick then + nickname = result.nick + end + if result.user and result.user.username and result.user.discriminator then + tag = tostring(result.user.username) .. "#" .. tostring(result.user.discriminator) + end + data = { + nickname = nickname, + discordTag = tag, + roles = roles + } + return end data = { - nickname = result.nick, - discordTag = tostring(result.user.username) .. "#" .. tostring(result.user.discriminator), + nickname = nickname, + discordTag = tag, roles = roles } end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = "Bot " .. server_config.discordServerToken})