Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/communication/src/discord-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,13 @@ export class DiscordCommunicationProvider implements CommunicationProviderAdapte
guildId: string;
channelId: string;
}): Promise<DiscordChannelPermissionDiagnostics> {
const [bot, member, roles, channel] = await Promise.all([
this.getBotInfo(),
// The guild-members endpoint takes a real user id — Discord rejects the
// literal `@me` there with 400 Invalid Form Body (unlike /users/@me).
const bot = await this.getBotInfo();
const [member, roles, channel] = await Promise.all([
this.request<{ roles?: string[] }>(
'GET',
`/guilds/${input.guildId}/members/@me`,
`/guilds/${input.guildId}/members/${bot.id}`,
undefined,
{ retryNetworkErrors: true, retryServerErrors: true },
),
Expand Down
12 changes: 11 additions & 1 deletion packages/communication/src/mock-discord-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,17 @@ export class MockDiscordServer {
),
);
}
if (method === 'GET' && path === `/guilds/${this.guildId}/members/@me`) {
const guildMember = /^\/guilds\/([^/]+)\/members\/([^/?]+)$/u.exec(path);
if (method === 'GET' && guildMember && guildMember[1] === this.guildId) {
// Real Discord rejects the literal `@me` on this route (unlike
// /users/@me); keep the mock as strict so provider code cannot pass
// against the mock while failing in production.
if (guildMember[2] === '@me') {
return jsonResponse({ message: 'Invalid Form Body', code: 50035 }, 400);
}
if (guildMember[2] !== this.bot.id) {
return jsonResponse({ message: 'Unknown Member', code: 10007 }, 404);
}
return jsonResponse({ user: this.bot, roles: ['role-roomote'] });
}
if (method === 'GET' && path === `/guilds/${this.guildId}/roles`) {
Expand Down
Loading