paperclipai/paperclip · error · Error

Discord bot membership could not be verified

Error message

Discord bot membership could not be verified

What it means

listDiscordBotChannels fetches the guild, the bot's member record (GET /guilds/{guildId}/members/{botUserId}), roles, and channels in parallel. If the member lookup yields no user id, or the returned guild id does not equal the requested guildId, the bot's membership in that server cannot be confirmed and the function throws instead of computing channel permissions against an unverified identity.

Source

Thrown at server/src/services/chat-discord.ts:295

      `/guilds/${encodeURIComponent(guildId)}/members/${encodeURIComponent(botUserId)}`,
      "bot membership lookup",
    ),
    discordJson<DiscordRole[]>(
      input.fetch,
      input.botToken,
      `/guilds/${encodeURIComponent(guildId)}/roles`,
      "server roles lookup",
    ),
    discordJson<DiscordChannel[]>(
      input.fetch,
      input.botToken,
      `/guilds/${encodeURIComponent(guildId)}/channels`,
      "server channels lookup",
    ),
  ]);
  const memberId = member.user?.id;
  if (!memberId || guild.id !== guildId) {
    throw new Error("Discord bot membership could not be verified");
  }
  const memberRoleIds = new Set(member.roles ?? []);
  const resources: ChatProviderResourceInventoryItem[] = channels
    .filter((channel) => channel.type === 0 && channel.id)
    .filter((channel) => {
      const permissions = channelPermissions({
        channel,
        guildId,
        memberId,
        memberRoleIds,
        roles,
      });
      return (
        (permissions & REQUIRED_CHANNEL_PERMISSIONS) ===
        REQUIRED_CHANNEL_PERMISSIONS
      );
    })
    .sort((left, right) => (left.position ?? 0) - (right.position ?? 0))

View on GitHub (pinned to 01ad858492)

Solutions

  1. Re-run verifyDiscordBot to refresh the bot identity and confirm the bot is currently installed in the guild
  2. Re-invite the bot to the server if the member lookup fails (bot was kicked or left)
  3. Verify botUserId matches the bot token's user id from /users/@me
  4. Retry after confirming the botToken is valid and has not been regenerated in the Developer Portal

Example fix

// before: reusing a stale botUserId from an old verification
await listDiscordBotChannels({ botUserId: oldBotUserId, botToken, fetch, guildId });
// after: re-verify first, then use the fresh identity
const identity = await verifyDiscordBot({ applicationId, botToken, fetch, guildId });
await listDiscordBotChannels({ botUserId: identity.botExternalId, botToken, fetch, guildId });
Defensive patterns

Strategy: try-catch

Validate before calling

const member = await fetch(`https://discord.com/api/v10/guilds/${guildId}/members/${botUserId}`, { headers: { Authorization: `Bot ${botToken}` } });
if (!member.ok) throw new Error(`Bot member record missing in guild ${guildId}; re-invite and re-verify`);

Try / catch

try {
  await listDiscordBotChannels({ botUserId, botToken, fetch, guildId });
} catch (err) {
  if (err instanceof Error && err.message === "Discord bot membership could not be verified") {
    await reverifyAndRetry(guildId);
  } else throw err;
}

Prevention

When it happens

Trigger: listDiscordBotChannels({botUserId, botToken, fetch, guildId}) where GET /guilds/{guildId}/members/{botUserId} returns 404/empty member (member.user?.id falsy), or GET /guilds/{guildId} returns a guild whose id !== guildId.

Common situations: Bot was removed from the server after verification but before listing channels; botUserId recorded from a previous verification no longer matches the installed bot; stale cached provider credentials pointing at a different guild; Discord API returning a partial member object due to an expired/limited token.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-09-10). Data as JSON: /api/errors/955d8b4055724ff1. Report an issue: GitHub.