diff --git a/src/server/server.ts b/src/server/server.ts
index 3eda1e6..8f5da22 100644
--- a/src/server/server.ts
+++ b/src/server/server.ts
@@ -1167,6 +1167,30 @@ export const server = createServer(
} catch {
guildConfig = null;
}
+ // Attempt to fetch guild roles via Discord Bot API if token available
+ let guildRoles: Array<{ id: string; name: string }> = [];
+ try {
+ const botToken = process.env.DISCORD_BOT_TOKEN;
+ if (botToken) {
+ const rolesRes = await fetch(
+ `https://discord.com/api/guilds/${encodeURIComponent(
+ String(guildId)
+ )}/roles`,
+ { headers: { Authorization: `Bot ${botToken}` } }
+ );
+ if (rolesRes.ok) {
+ const rolesJson = await rolesRes.json();
+ if (Array.isArray(rolesJson)) {
+ guildRoles = rolesJson.map((r: any) => ({
+ id: String(r.id),
+ name: String(r.name || r.id),
+ }));
+ }
+ }
+ }
+ } catch (err) {
+ // ignore; fallback to no roles
+ }
// Render dashboard with selected guild context; show dashboard nav
await renderTemplate(req, res, "dashboard", {
appName: pkg.name ?? "Amayo Bot",
@@ -1176,6 +1200,7 @@ export const server = createServer(
selectedGuildId: guildId,
selectedGuildName,
guildConfig,
+ guildRoles,
page,
hideNavbar: false,
useDashboardNav: true,
diff --git a/src/server/views/pages/dashboard.ejs b/src/server/views/pages/dashboard.ejs
index 159074d..5c74c29 100644
--- a/src/server/views/pages/dashboard.ejs
+++ b/src/server/views/pages/dashboard.ejs
@@ -58,8 +58,18 @@
-
-
+
+ <% if (typeof guildRoles !== 'undefined' && guildRoles && guildRoles.length) { %>
+
+ <% } else { %>
+
+
No se pudo obtener roles desde la API. Introduce IDs manualmente separadas por coma.
+ <% } %>
@@ -72,17 +82,20 @@
(function(){
const form = document.getElementById('guildSettingsForm');
const status = document.getElementById('saveStatus');
- form.addEventListener('submit', async (e)=>{
+ form.addEventListener('submit', async (e)=>{
e.preventDefault();
status.textContent = 'Guardando...';
const prefix = document.getElementById('prefixInput').value.trim();
const aiRolePrompt = document.getElementById('aiRoleInput').value.trim();
- const staffRaw = document.getElementById('staffInput').value.trim();
- const payload = {
- prefix: prefix,
- aiRolePrompt: aiRolePrompt.length ? aiRolePrompt : null,
- staff: staffRaw ? staffRaw.split(',').map(s=>s.trim()).filter(Boolean) : [],
- };
+ let staffArr = [];
+ const staffSelect = document.getElementById('staffSelect');
+ if (staffSelect) {
+ for (const o of staffSelect.selectedOptions) staffArr.push(o.value);
+ } else {
+ const staffRaw = (document.getElementById('staffInput') && document.getElementById('staffInput').value) ? document.getElementById('staffInput').value.trim() : '';
+ staffArr = staffRaw ? staffRaw.split(',').map(s=>s.trim()).filter(Boolean) : [];
+ }
+ const payload = { prefix: prefix, aiRolePrompt: aiRolePrompt.length ? aiRolePrompt : null, staff: staffArr };
try {
const res = await fetch(`/api/dashboard/${encodeURIComponent('<%= selectedGuild %>')}/settings`, {
method: 'POST',