{"record":{"id":"2b26bcac4dbf190b","repo":"jackwener/OpenCLI","slug":"discord-app-servers","errorCode":null,"errorMessage":"discord-app servers","messagePattern":"discord-app servers","errorType":"exception","errorClass":"EmptyResultError","httpStatus":null,"severity":"error","filePath":"clis/discord-app/servers.js","lineNumber":18,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { EmptyResultError } from '@jackwener/opencli/errors';\nimport { listDiscordServers } from './utils.js';\n\nexport const serversCommand = cli({\n    site: 'discord-app',\n    name: 'servers',\n    access: 'read',\n    description: 'List all Discord servers (guilds) in the sidebar',\n    domain: 'localhost',\n    strategy: Strategy.UI,\n    browser: true,\n    args: [],\n    columns: ['Index', 'Server', 'guild_id', 'url'],\n    func: async (page) => {\n        const servers = await listDiscordServers(page);\n        if (servers.length === 0) {\n            throw new EmptyResultError('discord-app servers', 'No Discord servers were found in the sidebar.');\n        }\n        return servers;\n    },\n});\n\nexport const __test__ = {\n    serversCommand,\n};\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/discord-app/servers.js#L1-L27","documentation":"The 'discord-app servers' command throws EmptyResultError when the connected Discord client's sidebar yields no guild entries after scraping. The library treats an empty server list as a failed command rather than returning an empty table, because it almost always means the app is not logged in or the sidebar failed to render. It is a deliberate guard so callers never mistake 'nothing found' for 'command succeeded with 0 rows'.","triggerScenarios":"Running `discord-app servers` when listDiscordServers(page) returns an empty array: the browser page is not logged into Discord, the guild sidebar is collapsed or not yet rendered, or the in-page list-servers script ran before the Discord app finished loading.","commonSituations":"Automating Discord in CI where the logged-out login page loads instead of the app; running the command too soon after launching the Discord app so the sidebar hasn't hydrated; an account belonging to zero servers; a Discord UI update changing sidebar DOM selectors.","solutions":["Open the Discord app/page and confirm you are logged in and the server sidebar is visible before running the command","Re-run the command after waiting for the app to fully load (sidebar rendered)","Log the automation browser into an account that is a member of at least one server","If selectors changed after a Discord UI update, update the list-servers script in clis/discord-app/utils.js to match the new sidebar DOM"],"exampleFix":"// before\nawait discordAppServers(page);\n// after\nawait ensureDiscordLoggedIn(page); // wait for sidebar render/login\nconst servers = await discordAppServers(page);","handlingStrategy":"validation","validationCode":"async function assertServersAvailable(page) {\n  const sidebar = await page.$('[class*=\"guild\"]');\n  if (!sidebar) throw new Error('Discord sidebar not rendered — log in and wait for the app to load before running servers.');\n}","typeGuard":"function hasServers(v) {\n  return Array.isArray(v) && v.length > 0 && v.every(r => r && typeof r === 'object');\n}","tryCatchPattern":"try {\n  const servers = await discordAppServers(page);\n} catch (err) {\n  if (String(err.message).includes('discord-app servers')) {\n    console.error('No servers found: check login state and that the sidebar is visible.');\n  } else throw err;\n}","preventionTips":["Verify the automated browser is logged into Discord before listing servers","Wait for the guild sidebar selector to appear before scraping","Use an account that is a member of at least one server","Re-run with a startup delay in CI where app load is slow"],"tags":["discord","empty-result","automation"],"backgroundTag":"empty-result-set","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}