Error Dashboard

Hello, I have an error in my dashboard. Could you help me because I don't understand what's going on Thanks
TypeError: C:\Users\james\OneDrive\Bureau\boots\src\views\index.ejs:2
1| <head>
>> 2| <%- include('parts/head', {bot, user, path}) %>
3|
4|
5| </head>

C:\Users\james\OneDrive\Bureau\boots\src\views\parts\head.ejs:173
171|
172| <% if(user) { %>
>> 173| <%
174| let guild = bot.guilds.cache.get(config.server.id).members.cache.get(user.id);
175| if(guild) {
176| if(guild.roles.cache.get(roles.administrator) || guild.roles.cache.get(roles.moderator)) {

Cannot read properties of undefined (reading 'guilds')
at eval ("C:\\Users\\james\\OneDrive\\Bureau\\boots\\src\\views\\parts\\head.ejs":75:33)
at head (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:703:17)
at include (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:701:39)
at eval ("C:\\Users\\james\\OneDrive\\Bureau\\boots\\src\\views\\index.ejs":12:17)
at index (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:703:17)
at tryHandleCache (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:274:36)
at exports.renderFile [as engine] (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:491:10)
at View.render (C:\Users\james\OneDrive\Bureau\boots\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\james\OneDrive\Bureau\boots\node_modules\express\lib\application.js:657:10)
at Function.render (C:\Users\james\OneDrive\Bureau\boots\node_modules\express\lib\application.js:609:3)
TypeError: C:\Users\james\OneDrive\Bureau\boots\src\views\index.ejs:2
1| <head>
>> 2| <%- include('parts/head', {bot, user, path}) %>
3|
4|
5| </head>

C:\Users\james\OneDrive\Bureau\boots\src\views\parts\head.ejs:173
171|
172| <% if(user) { %>
>> 173| <%
174| let guild = bot.guilds.cache.get(config.server.id).members.cache.get(user.id);
175| if(guild) {
176| if(guild.roles.cache.get(roles.administrator) || guild.roles.cache.get(roles.moderator)) {

Cannot read properties of undefined (reading 'guilds')
at eval ("C:\\Users\\james\\OneDrive\\Bureau\\boots\\src\\views\\parts\\head.ejs":75:33)
at head (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:703:17)
at include (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:701:39)
at eval ("C:\\Users\\james\\OneDrive\\Bureau\\boots\\src\\views\\index.ejs":12:17)
at index (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:703:17)
at tryHandleCache (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:274:36)
at exports.renderFile [as engine] (C:\Users\james\OneDrive\Bureau\boots\node_modules\ejs\lib\ejs.js:491:10)
at View.render (C:\Users\james\OneDrive\Bureau\boots\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\james\OneDrive\Bureau\boots\node_modules\express\lib\application.js:657:10)
at Function.render (C:\Users\james\OneDrive\Bureau\boots\node_modules\express\lib\application.js:609:3)
51 Replies
Lioness100
Lioness1002y ago
It looks like bot is undefined. Can you show where you are using this view in the javascript?
!" 𝑱𝒂𝒎𝒆𝒔__
I looked in the code & bot is not declared
Lioness100
Lioness1002y ago
I meant where you were using ejs.renderFile Well, that's your problem Did you copy and paste the code from somewhere else? If so, always try to understand what it's doing first so errors like these don't arise
!" 𝑱𝒂𝒎𝒆𝒔__
That's what I'm trying to understand but personally I find my code correct & I don't understand why I have this error
Lioness100
Lioness1002y ago
Because you're not passing in a bot variable
Can you show where you are using this view in the javascript?
Lioness100
Lioness1002y ago
I meant where you were using ejs.renderFile
In src\views\index.ejs you are rendering the head.ejs, and injecting the bot, user, and path variable for use in that file. However, bot is undefined That's the only info I can really give you with this context
!" 𝑱𝒂𝒎𝒆𝒔__
How can I define it if it is already defined?
Lioness100
Lioness1002y ago
I need to see your code lol src\views\index.ejs and the javascript where that's rendered
Lioness100
Lioness1002y ago
You already sent me that, that's not the code I need
Lioness100
Lioness1002y ago
and the javascript where that's rendered
!" 𝑱𝒂𝒎𝒆𝒔__
On the code Javascript & notified with this
<%
//code
%>
<%
//code
%>
Here
Lioness100
Lioness1002y ago
This is how ejs is rendered
Lioness100
Lioness1002y ago
Data is where you would pass in variables, such as bot. Obviously you're either not, or passing in the wrong data type. But I need to see the javascript where the ejs is being rendered Which is where one of those functions would be called If you're using expressjs you'd be calling res.render I think. But I need to see that code @!" 𝑱𝒂𝒎𝒆𝒔__
!" 𝑱𝒂𝒎𝒆𝒔__
Do you want to see this code ?
app.get("/login", (req, res, next) => {

if (req.session.backURL) {
req.session.backURL = req.session.backURL;
} else if (req.headers.referer) {
const parsed = url.parse(req.headers.referer);
if (parsed.hostname === app.locals.domain) {
req.session.backURL = parsed.path;
}
} else {
req.session.backURL = "/";
}
next();
},
app.get("/login", (req, res, next) => {

if (req.session.backURL) {
req.session.backURL = req.session.backURL;
} else if (req.headers.referer) {
const parsed = url.parse(req.headers.referer);
if (parsed.hostname === app.locals.domain) {
req.session.backURL = parsed.path;
}
} else {
req.session.backURL = "/";
}
next();
},
Lioness100
Lioness1002y ago
No I want to see the code where you're rendering index.ejs
Lioness100
Lioness1002y ago
Again, not index.ejs itself. Where you're rendering index.ejs It might be in the same file as this code
!" 𝑱𝒂𝒎𝒆𝒔__
Which code do you want, because I don't really understand
Drexy_xD
Drexy_xD2y ago
He wants to see the rendering file Where the index.ejs file is rendering
Lioness100
Lioness1002y ago
Sorry, I missed this haha @!" 𝑱𝒂𝒎𝒆𝒔__ just send me your index.js
!" 𝑱𝒂𝒎𝒆𝒔__
Hello @Lioness100 sorry I was busy. Here is the index.js
Lioness100
Lioness1002y ago
Please send it in text or send a link to a pastebin, I'm on mobile
Lioness100
Lioness1002y ago
In what file do you define API routes? Please send that. Where stuff like this is
!" 𝑱𝒂𝒎𝒆𝒔__
In the server.js here it is: https://pastecord.com/ilapatamez.js
Lioness100
Lioness1002y ago
What route are you accessing that creates the error
!" 𝑱𝒂𝒎𝒆𝒔__
As soon as I log in
Lioness100
Lioness1002y ago
This concerns whatever route handles /, which is what you get redirected to after login. When you render the page, which you seem to be doing through res.render or renderTemplate, you aren't passing in bot as part of the data object, or the value for bot is undefined
!" 𝑱𝒂𝒎𝒆𝒔__
How can I fix this error?
Lioness100
Lioness1002y ago
Pass bot as part of the data object and make sure it's the client
!" 𝑱𝒂𝒎𝒆𝒔__
Could you please show me how to do this?
Lioness100
Lioness1002y ago
Show the place in your code where you call res.render('index.ejs') or renderTemplate('index.ejs') or something similar
!" 𝑱𝒂𝒎𝒆𝒔__
const renderTemplate = async (res, req, template, data = {}) => {
const baseData = {
bot: client,
path: req.path,
_token: req.session['_token'],
user: req.isAuthenticated() ? req.user : null
};
res.render(path.resolve(`${templateDir}${path.sep}${template}`), Object.assign(baseData, data));
};
const renderTemplate = async (res, req, template, data = {}) => {
const baseData = {
bot: client,
path: req.path,
_token: req.session['_token'],
user: req.isAuthenticated() ? req.user : null
};
res.render(path.resolve(`${templateDir}${path.sep}${template}`), Object.assign(baseData, data));
};
Lioness100
Lioness1002y ago
I'm referring to the code where you specifically render index.ejs
!" 𝑱𝒂𝒎𝒆𝒔__
Okay, what should I do?
Lioness100
Lioness1002y ago
Send it to me
!" 𝑱𝒂𝒎𝒆𝒔__
I have sent the code render
Lioness100
Lioness1002y ago
^
!" 𝑱𝒂𝒎𝒆𝒔__
What should I send you the index.js or the server.js?
Lioness100
Lioness1002y ago
I can't really think of another way to word what I've already said, sorry
!" 𝑱𝒂𝒎𝒆𝒔__
I have sent you the route & renderTemplate as you requested
Lioness100
Lioness1002y ago
I'm looking for the code where you render index.ejs Where this happens ^
!" 𝑱𝒂𝒎𝒆𝒔__
this :
app.engine("vcodes-xyz", ejs.renderFile);
app.engine("vcodes-xyz", ejs.renderFile);
Lioness100
Lioness1002y ago
No, I'm referring to where index.ejs specifically is rendered
!" 𝑱𝒂𝒎𝒆𝒔__
this :
const app = require('express').Router();
const botsdata = require("../database/models/botlist/bots.js");

app.get("/", async (req,res) => {
res.render("index.ejs", {
bot: global.Client,
path: req.path,
config: global.config,
user: req.isAuthenticated() ? req.user : null,
req: req,
botdata: await botsdata.find(),
roles:global.config.server.roles,
channels: global.config.server.channels
})
})

module.exports = app;
const app = require('express').Router();
const botsdata = require("../database/models/botlist/bots.js");

app.get("/", async (req,res) => {
res.render("index.ejs", {
bot: global.Client,
path: req.path,
config: global.config,
user: req.isAuthenticated() ? req.user : null,
req: req,
botdata: await botsdata.find(),
roles:global.config.server.roles,
channels: global.config.server.channels
})
})

module.exports = app;
Lioness100
Lioness1002y ago
Yes! That's it global.Client doesn't exist It might be global.client lowercase, or you might need to get client a different way It looks like global.clientSL exists, but I don't know if that's the one you want to yse It doesn't look like the other client is attached to the global object, you accessed it in server.js via function patameter
Want results from more Discord servers?
Add your server