So i managed to get username from a link but im unsure of how to actually get the userid back. I want it so when it to say the username which works perfectly, but down in thumbnail when i try to fetch the userId it comes up as "userId is not defined". I'm it sure what the solution is but I want to keep both userId and username. here is my code!
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();
}
oh yeah by the way its a webhook which it sends to on discord. It works without thumbnail but doesnt work with the thumbnail saying userid.
CodePudding user response:
You are missing
const userId = nextInQueue.offers[0].userId;