0

So I'm trying to get a users username by id but I keep getting [object Promise]. I'm also trying to get their thumbnail but it doesn't show. These are my files

index.js

 app.use('/', function(req, res) {
      
      players.find({}, function(err, result) {
        //if (err) return handleError(err);
        if (err) return console.log(chalk.red(err));
        return res.render('data', { result, getImage, getUser })


      })
    });

getFunction.js

async function getThumbnail(userID){
   
      let data = await request({
      uri: `https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${userID}&size=100x100&format=Png&isCircular=true`,
      json: true,
      simple: false
    });
    return data.data[0].imageUrl;
  
}
async function getUsername(userID){
   let id = await userID;
  
   let data = await request({
      uri: `https://users.roblox.com/v1/users/${userID}`,
      json: true,
      simple: false
    });
 
    return data.name
}
//module.exports part

then the ejs file

<div class="row">
  <% if(result.length){%>
 
  <% for(var i = 0; i< result.length; i++) {%> 
    
    
  <% var userID = result[i].userID%>
  
  <div class="column">
    <div class="card">
      <img src="<%= getImage(result[i].userID)%>" alt="Avatar" style="float:right;width:42px;height:42px;">
      <h3>Username: <%= rbx.getUser(result[i].userID)%></h3>
      <p>Reason: <%= result[i].reason%></p>
      <p>Admin: <%= result[i].admin%></p>
    <p><%= getImage(result[i].userID)%></p></div>
  </div>
  </div>
  <%}%>
           
  <%}else{ %>
       <tr>
          <td colspan="3">No user</td>
       </tr>
    <% } %>    
 

Please help I'm out of ideas, I can't find any source on this so.

  • Does this answer your question? [How to display the data returned from an async function in .ejs?](https://stackoverflow.com/questions/69769588/how-to-display-the-data-returned-from-an-async-function-in-ejs) – Nick McCurdy Aug 07 '22 at 03:33
  • sorta but I'm calling the function in the ejs file that has the userID. If that made since – SniperrifleXD Aug 07 '22 at 03:36
  • I know, but ejs doesn't support async functions. You'll have to call it where you render the template (like the question I linked), or use something else (like Remix). – Nick McCurdy Aug 07 '22 at 03:44
  • Alright, well thank you. I'll try the question that you linked. – SniperrifleXD Aug 07 '22 at 03:48

0 Answers0