I have some code that uses ejs but for some reason it adds lines in the middle of each server.
My ejs code:
<%- include("partials/header", { bot, user, path, title: "Twintails🎀 - Bot Dashboard" }) %>
<link rel="shortcut icon" href="https://i.imgur.com/NgV0KSf.png">
<style>
</style>
<% user.guilds.forEach(guild => {
const permsOnGuild = new perms(guild.permissions);
if(!permsOnGuild.has("MANAGE_GUILD")) return;
%>
<hr>
<p><%= guild.name %></p>
<% if (bot.guilds.cache.get(guild.id)) { %>
<a href="/dashboard/<%= guild.id %>">Edit Settings</a>
<% } else { %>
<a
href="<%= `https://discordapp.com/oauth2/authorize?client_id=${bot.user.id}&scope=bot&guild_id=${guild.id}&response_type=code&redirect_uri=${encodeURIComponent(`${bot.config.domain}${bot.config.port == 80 ? "" : `:${bot.config.port}`}/callback`)}` %>">Add
Bot</a>
<% } %>
<% }); %>
<%- include("partials/footer") %>
My dashboard endpoint:
app.get("/dashboard", checkAuth, (req, res) => {
renderTwin(res, req, "dashboard.ejs", { perms: Discord.Permissions });
});
app.get("/dashboard/:guildID", checkAuth, async (req, res) => {
const guild = bot.guilds.cache.get(req.params.guildID);
if (!guild) return res.redirect("/dashboard");
const member = guild.members.cache.get(req.user.id);
if (!member) return res.redirect("/dashboard");
if (!member.permissions.has("MANAGE_GUILD")) return res.redirect("/dashboard");
// We retrive the settings stored for this guild.
var storedSettings = await GuildSettings.findOne({ gid: guild.id });
if (!storedSettings) {
// If there are no settings stored for this guild, we create them and try to retrive them again.
const newSettings = new GuildSettings({
gid: guild.id
});
await newSettings.save().catch(()=>{});
storedSettings = await GuildSettings.findOne({ gid: guild.id });
}
renderTwin(res, req, "settings.ejs", { guild, settings: storedSettings, alert: null });
});
app.post("/dashboard/:guildID", checkAuth, async (req, res) => {
const guild = bot.guilds.cache.get(req.params.guildID);
if (!guild) return res.redirect("/dashboard");
const member = guild.members.cache.get(req.user.id);
if (!member) return res.redirect("/dashboard");
if (!member.permissions.has("MANAGE_GUILD")) return res.redirect("/dashboard");
var storedSettings = await GuildSettings.findOne({ gid: guild.id });
if (!storedSettings) {
const newSettings = new GuildSettings({
gid: guild.id
});
await newSettings.save().catch(()=>{});
storedSettings = await GuildSettings.findOne({ gid: guild.id });
}
storedSettings.prefix = req.body.prefix;
await storedSettings.save().catch(() => {});
renderTwin(res, req, "settings.ejs", { guild, settings: storedSettings, alert: "Your settings have been saved." });
});
Also, if you can, can you guys recommend me some good templates for the server list?
<%- include("partials/header", { bot, user, path, title: "Twintails🎀 - Edit" }) %>
<link rel="shortcut icon" href="https://i.imgur.com/NgV0KSf.png">
<% if (alert) { %>
<p><%= alert %></p><br>
<% } %>
<h1><%= guild.name %></h1>
<form style="margin-top: 1em;" method="POST">
<p>Prefix:</p>
<input type="text" name="prefix" value="<%= settings.prefix %>" placeholder="Your prefix."><br><br>
<button type="submit">Save Settings</button>
</form>
<%- include("partials/footer") %>
Thanks!