在这个API上挣扎。它适用于邮递员期望的步骤:
用户完成聊天命令/user id。
2-脚本调用API并传递id。
3-使用该id的用户搜索数据库。
4- API传回该用户的用户名,并将其打印到聊天中。
我想这个代码是可怕的,完全错误的,但是我对Lua和FiveM代码非常陌生。这是错误代码。
FIVEM ERROR
[ script:TestingPOST] 2
[ script:TestingPOST] table: 000001ADC3990530
[ script:TestingPOST] 2
[ script:TestingPOST] nil
[ script:TestingPOST] SCRIPT ERROR: @TestingPOST/webhook_s.lua:16: attempt to index a nil value (local 'data')我非常感谢你的帮助!)
我已经删除了API链接和auth令牌。
RegisterCommand("user", function(source, args, rawCommand)
local query = string.sub(rawCommand, 6)
print(source)
print(args)
print(query)
PerformHttpRequest('https://MYAPP.bubbleapps.io/version-test/api/1.1/wf/userdata',
function(err, text, header)
local data = json.decode(text)
TriggerClientEvent("chat:addMessage", source, {
args {
string.format("Display name is %s", data.response.displayname )
}
})
end, 'POST',
json.encode({userid = query}), {["Authorization"] = 'TOKEN'})
end)发布于 2021-12-16 08:47:58
错误指示数组data为nil,这意味着您在text中没有正确的值(如data = json.decode(text))
我对这个特定的API不太了解,但是作为一个一般的编程建议,您应该检查err、text和header的值,这些信息可能是代码不能工作的原因。如果你能在这里张贴这些值,那会有帮助
您还应该在代码中集成错误处理,以防API不可用或发生错误(例如,检查err == 200 )。
https://stackoverflow.com/questions/70365760
复制相似问题