EJS Texts Are Not Visible

<table class="body">
<%let channel = bot.channels.cache.get(chid).messages.fetch({limit: 10});%>
<%channel.then(function(m){%>
      <tr>
        <th>Mesaj Sahibi</th>
        <th>Mesaj ID</th>
        <th>Mesaj Tarih</th> 
      </tr>
      <%m.forEach(function(cmds) {%>
      <%console.log(cmds.content)%>
        <tr>
          <td style="text-align:center;"><%=cmds.author.tag%></td>
          <td style="text-align:center;"><%=cmds.content%></td>
          <td style="text-align:center;"><%=momentz(cmds.createdAt).tz("Turkey").format("HH:mm:ss")%></td>
        </tr>
      <%});%>
    <%})%>
</table>

I’m creating a table but it doesn’t show up

How are you sending information to this EJS file?

Moved to #discord-help. (The OP has used the #discord tag and the code looks like a Discord bot’s code, too.)

app.get("/dashboard/:id/:chid/members/messages",loginReq, (req, res) => {
  let link = req.params.id;
  let chi = req.params.chid;
  let g = client.guilds.cache.has(link);
  if (g) {
    let gu = client.guilds.cache.find(ss => ss.id == link);
    const manage = gu && !!gu.member(req.user.id) ? gu.member(req.user.id).permissions.has("MANAGE_GUILD") : false;
    if (!manage && !req.session.isAdmin)
      return rend(res, req, "pages/err.ejs", { id: link });
    rend(res, req, "pages/messages.ejs", {chid:chi,momentz:momentz,db:db, id: link });
  } else {
    rend(res, req, "pages/err.ejs", { id: link });
  }
});
const dataDir = path.resolve(`${process.cwd()}${path.sep}views`);

const templateDir = path.resolve(`${dataDir}${path.sep}${path.sep}`);

const rend = (res, req, template, data = {}) => {
  const perms = Discord.Permissions;
  const baseData = {
    bot: client,
    path: req.path,
    user: req.isAuthenticated() ? req.user : null,
    perms: perms
  };
  res.render(
    path.resolve(`${templateDir}${path.sep}${template}`),Object.assign(baseData, data)
  );
};
1 Like

:thinking: What do !! and Object.assign do?

The error could be in in the EJS code: momentz. I don’t think libraries work in EJS.

  <%let channels = bot.channels.cache.get(chid).messages.fetch({limit: 10});%>
  <%channels.then(function(m){%>
      <%m.forEach(function(cmds) {%>
          <%console.log(cmds.author.tag)%>
          <p><%=cmds.author.tag%></p>
      <%});%>
    <%});%>

I just tried this and still couldn’t see the post

Log:
image

@CarlyRaeJepsenStan !! forces it to return true or false rather than truthy or falsey.
Object.assign(obj, data) is like array.push(data), but it adds the object data to object obj.

1 Like

Cool, thanks. I dunno what’s going on with the op’s EJS - maybe you can try <%- tags instead?

@NoName.txt it looks like you’re logging the tag of the author post with cmd.author.tag, and I assume NoName.txt#1234 is your discord username. To log the message I think you should use cmd.content. Also, I can’t see where you’re sending bot to the ejs file.
Happy Glitching!

Unfortunately it didn’t

<table class="table table-striped">
<%let channel = bot.channels.cache.get(chid).messages.fetch({limit: 10});%>
      <tr>
        <th>Mesaj Sahibi</th>
        <th>Mesaj ID</th>
        <th>Mesaj Tarih</th> 
      </tr>
  <%var arr = [];%>
<%channel.then(m=>{%>
    <%arr.push(m);%>
    <%});%>
    <%arr.map(cmds => {%>
      <%console.log(cmds.content)%>
        <tr>
          <td style="text-align:center;"><%=cmds.author.tag%></td>
          <td style="text-align:center;"><%=cmds.content%></td>
          <td style="text-align:center;"><%=momentz(cmds.createdAt).tz("Turkey").format("HH:mm:ss")%></td>
        </tr>
      <%});%>
</table>

I pushed it to the data and tried to retake it but it didn’t work

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.