feat(bot): mirror heard voice turns to a text channel

Set DISCORD_TRANSCRIPT_CHANNEL_ID to a text channel and the userbot posts
"들은 말: <transcript> / 답변: <reply or (무응답)>" for every voice turn, so you can
verify what the bot understood even when it doesn't answer aloud.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-06-13 22:06:38 +09:00
parent 4e446c1d7c
commit 62bb0ab87e
2 changed files with 25 additions and 1 deletions

View File

@@ -27,6 +27,10 @@ export const config = {
// Userbot auto-join: if set, the userbot joins this voice channel on startup;
// if empty, it waits for a text command (e.g. "!자비스 join") to join.
autoJoinChannelId: opt("DISCORD_VOICE_CHANNEL_ID"),
// Optional text channel where the bot mirrors every voice turn it heard
// (transcript + reply) so you can verify what it understood even when it
// doesn't answer aloud.
transcriptChannelId: opt("DISCORD_TRANSCRIPT_CHANNEL_ID"),
// --- Python brain bridge ---
bridgeUrl: opt("BRIDGE_URL", "http://127.0.0.1:8765"),

View File

@@ -34,6 +34,21 @@ async function loadSelfbot(): Promise<any> {
}
}
/** Mirror a heard voice turn (transcript + reply) into a text channel. */
async function postTranscript(client: AnyClient, transcript: string, reply: string): Promise<void> {
const chId = config.transcriptChannelId;
if (!chId) return;
try {
const ch: any = await client.channels.fetch(chId).catch(() => null);
if (ch?.send) {
const r = (reply || "").trim();
await ch.send(`🗣️ 들은 말: ${transcript}\n🤖 답변: ${r || "(무응답)"}`);
}
} catch (e) {
console.error("[userbot] transcript post failed:", e);
}
}
async function joinAndListen(client: AnyClient, channelId: string): Promise<void> {
const channel: any = await client.channels.fetch(channelId).catch(() => null);
if (!channel || channel.isVoice?.() === false) {
@@ -43,7 +58,12 @@ async function joinAndListen(client: AnyClient, channelId: string): Promise<void
// The selfbot VoiceChannel is runtime-compatible with @discordjs/voice's
// joinVoiceChannel (it exposes id, guild.id and guild.voiceAdapterCreator).
const session = await joinChannel(channel as unknown as VoiceBasedChannel);
session.onTurn = ({ transcript, reply }) => console.log(`🗣️ ${transcript}\n🤖 ${reply}`);
session.onTurn = ({ transcript, reply }) => {
console.log(`🗣️ ${transcript}\n🤖 ${reply}`);
// Mirror every heard utterance (and the reply, if any) to a text channel so
// you can see what the bot understood even when it doesn't answer aloud.
void postTranscript(client, transcript, reply);
};
// Screen-share mode (STREAM_BROWSER=true): auto-start the broadcast on join,
// report its live state to the brain each turn, and let the brain toggle it by
// voice. Userbot is the only mode that can actually Go Live, so without this