mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
fix(discord): handle missing guild/channel data in link resolution
Add null checks for guild.id and guild.name when resolving Discord entities. This prevents TypeError when processing invite links for servers/channels the bot doesn't have cached. Fixes #6606
This commit is contained in:
@@ -27,7 +27,8 @@ export async function listDiscordDirectoryGroupsLive(
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const query = normalizeQuery(params.query);
|
const query = normalizeQuery(params.query);
|
||||||
const guilds = await fetchDiscord<DiscordGuild[]>("/users/@me/guilds", token);
|
const rawGuilds = await fetchDiscord<DiscordGuild[]>("/users/@me/guilds", token);
|
||||||
|
const guilds = rawGuilds.filter((g) => g.id && g.name);
|
||||||
const rows: ChannelDirectoryEntry[] = [];
|
const rows: ChannelDirectoryEntry[] = [];
|
||||||
|
|
||||||
for (const guild of guilds) {
|
for (const guild of guilds) {
|
||||||
@@ -69,7 +70,8 @@ export async function listDiscordDirectoryPeersLive(
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const guilds = await fetchDiscord<DiscordGuild[]>("/users/@me/guilds", token);
|
const rawGuilds = await fetchDiscord<DiscordGuild[]>("/users/@me/guilds", token);
|
||||||
|
const guilds = rawGuilds.filter((g) => g.id && g.name);
|
||||||
const rows: ChannelDirectoryEntry[] = [];
|
const rows: ChannelDirectoryEntry[] = [];
|
||||||
const limit = typeof params.limit === "number" && params.limit > 0 ? params.limit : 25;
|
const limit = typeof params.limit === "number" && params.limit > 0 ? params.limit : 25;
|
||||||
|
|
||||||
|
|||||||
@@ -74,16 +74,21 @@ function parseDiscordChannelInput(raw: string): {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function listGuilds(token: string, fetcher: typeof fetch): Promise<DiscordGuildSummary[]> {
|
async function listGuilds(token: string, fetcher: typeof fetch): Promise<DiscordGuildSummary[]> {
|
||||||
const raw = await fetchDiscord<Array<{ id: string; name: string }>>(
|
const raw = await fetchDiscord<Array<{ id?: string; name?: string }>>(
|
||||||
"/users/@me/guilds",
|
"/users/@me/guilds",
|
||||||
token,
|
token,
|
||||||
fetcher,
|
fetcher,
|
||||||
);
|
);
|
||||||
return raw.map((guild) => ({
|
return raw
|
||||||
id: guild.id,
|
.filter(
|
||||||
name: guild.name,
|
(guild): guild is { id: string; name: string } =>
|
||||||
slug: normalizeDiscordSlug(guild.name),
|
typeof guild.id === "string" && typeof guild.name === "string",
|
||||||
}));
|
)
|
||||||
|
.map((guild) => ({
|
||||||
|
id: guild.id,
|
||||||
|
name: guild.name,
|
||||||
|
slug: normalizeDiscordSlug(guild.name),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listGuildChannels(
|
async function listGuildChannels(
|
||||||
|
|||||||
@@ -62,16 +62,21 @@ function parseDiscordUserInput(raw: string): {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function listGuilds(token: string, fetcher: typeof fetch): Promise<DiscordGuildSummary[]> {
|
async function listGuilds(token: string, fetcher: typeof fetch): Promise<DiscordGuildSummary[]> {
|
||||||
const raw = await fetchDiscord<Array<{ id: string; name: string }>>(
|
const raw = await fetchDiscord<Array<{ id?: string; name?: string }>>(
|
||||||
"/users/@me/guilds",
|
"/users/@me/guilds",
|
||||||
token,
|
token,
|
||||||
fetcher,
|
fetcher,
|
||||||
);
|
);
|
||||||
return raw.map((guild) => ({
|
return raw
|
||||||
id: guild.id,
|
.filter(
|
||||||
name: guild.name,
|
(guild): guild is { id: string; name: string } =>
|
||||||
slug: normalizeDiscordSlug(guild.name),
|
typeof guild.id === "string" && typeof guild.name === "string",
|
||||||
}));
|
)
|
||||||
|
.map((guild) => ({
|
||||||
|
id: guild.id,
|
||||||
|
name: guild.name,
|
||||||
|
slug: normalizeDiscordSlug(guild.name),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function scoreDiscordMember(member: DiscordMember, query: string): number {
|
function scoreDiscordMember(member: DiscordMember, query: string): number {
|
||||||
|
|||||||
Reference in New Issue
Block a user