feat: suppress Discord link embed previews on bot messages

Add MessageFlags.SuppressEmbeds to all send() calls so URLs in
agent responses don't generate large preview cards.
This commit is contained in:
Eyejoker
2026-03-14 03:29:26 +09:00
parent f388323987
commit e4eca65c7c
2 changed files with 6 additions and 0 deletions

View File

@@ -98,6 +98,7 @@ vi.mock('discord.js', () => {
Client: MockClient, Client: MockClient,
Events, Events,
GatewayIntentBits, GatewayIntentBits,
MessageFlags: { SuppressEmbeds: 1 << 2 },
TextChannel, TextChannel,
}; };
}); });
@@ -760,10 +761,12 @@ describe('DiscordChannel', () => {
expect(mockChannel.send).toHaveBeenNthCalledWith(1, { expect(mockChannel.send).toHaveBeenNthCalledWith(1, {
content: 'x'.repeat(2000), content: 'x'.repeat(2000),
files: undefined, files: undefined,
flags: 1 << 2,
}); });
expect(mockChannel.send).toHaveBeenNthCalledWith(2, { expect(mockChannel.send).toHaveBeenNthCalledWith(2, {
content: 'x'.repeat(1000), content: 'x'.repeat(1000),
files: undefined, files: undefined,
flags: 1 << 2,
}); });
}); });
}); });

View File

@@ -7,6 +7,7 @@ import {
Events, Events,
GatewayIntentBits, GatewayIntentBits,
Message, Message,
MessageFlags,
TextChannel, TextChannel,
} from 'discord.js'; } from 'discord.js';
@@ -457,6 +458,7 @@ export class DiscordChannel implements Channel {
await textChannel.send({ await textChannel.send({
content: cleaned || undefined, content: cleaned || undefined,
files: files.length > 0 ? files : undefined, files: files.length > 0 ? files : undefined,
flags: MessageFlags.SuppressEmbeds,
}); });
} else { } else {
// Send text in chunks, attach images to the first chunk // Send text in chunks, attach images to the first chunk
@@ -465,6 +467,7 @@ export class DiscordChannel implements Channel {
await textChannel.send({ await textChannel.send({
content: chunk, content: chunk,
files: i === 0 && files.length > 0 ? files : undefined, files: i === 0 && files.length > 0 ? files : undefined,
flags: MessageFlags.SuppressEmbeds,
}); });
} }
} }