所以我設法從鏈接中獲取用戶名,但我不確定如何實際獲取用戶 ID。我想要它,所以當它說出完美作業的用戶名時,但是當我嘗試獲取用戶 ID 時,它會顯示為“未定義用戶 ID”。我確定解決方案是什么,但我想保留用戶 ID 和用戶名。這是我的代碼!
const getUsername = userId => new Promise(resolve => {
fetch('https://users.roblox.com/v1/users/' userId)
.then(res => res.json())
.then(body => resolve(body.name || 'Unknown'))
.catch(() => resolve('Unknown'))
})
(async () => {
const username = await getUsername(nextInQueue.offers[0].userId);
consola.success(`[${username}] has ok items`)
fetch(config.webhook, {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
"content": null,
"embeds": [
{
"title": ":tada: Trade sent to: " username " :tada:",
"color": 28420,
"fields": [
{
"name": "Cool Items:",
"value": itemNameList.join('\n')
},
{
"name": "Okay items:",
"value": toreceiveList.join('\n')
}
],
"author": {
"name": "Expoorttoo",
"icon_url": "https://i.pinimg.com/736x/4b/69/74/4b6974aef5d96580140ef2686072af3f.jpg"
},
"footer": {
"text": Sentto.toLocaleString() " sent & " tradeQueue.length.toLocaleString() " set in queue"
},
"thumbnail": {
"url": "https://www.roblox.com/headshot-thumbnail/image?userId=" userId "&width=420&height=420&format=png"
}
}
]
})
})
})().catch();
}
哦,是的,順便說一下,它是一個 webhook,它在不和諧的情況下發送給它。它在沒有縮略圖的情況下作業,但不適用于顯示用戶 ID 的縮略圖。
uj5u.com熱心網友回復:
你不見了
const userId = nextInQueue.offers[0].userId;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/492933.html
上一篇:onclick="copy(this)"不作業的javascript
下一篇:如何用js填充選擇選項?
