Discord: fix voice command typing

This commit is contained in:
Shadow
2026-02-20 16:31:41 -06:00
parent 4ab946eebf
commit ab27d7b05a
3 changed files with 13 additions and 6 deletions

View File

@@ -2,8 +2,10 @@ import { inspect } from "node:util";
import {
Client,
ReadyListener,
type BaseCommand,
type BaseMessageInteractiveComponent,
type Modal,
type Plugin,
} from "@buape/carbon";
import { GatewayCloseCodes, type GatewayPlugin } from "@buape/carbon/gateway";
import { VoicePlugin } from "@buape/carbon/voice";
@@ -433,7 +435,7 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
);
}
const voiceManagerRef: { current: DiscordVoiceManager | null } = { current: null };
const commands = commandSpecs.map((spec) =>
const commands: BaseCommand[] = commandSpecs.map((spec) =>
createDiscordNativeCommand({
command: spec,
cfg,
@@ -524,7 +526,9 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
}
}
const clientPlugins = [createDiscordGatewayPlugin({ discordConfig: discordCfg, runtime })];
const clientPlugins: Plugin[] = [
createDiscordGatewayPlugin({ discordConfig: discordCfg, runtime }),
];
if (voiceEnabled) {
clientPlugins.push(new VoicePlugin());
}

View File

@@ -3,10 +3,12 @@ import {
Command,
CommandWithSubcommands,
type CommandInteraction,
type CommandOptions,
} from "@buape/carbon";
import {
ApplicationCommandOptionType,
ChannelType as DiscordChannelType,
type APIApplicationCommandChannelOption,
} from "discord-api-types/v10";
import { resolveCommandAuthorizedFromAuthorizers } from "../../channels/command-gating.js";
import type { OpenClawConfig } from "../../config/config.js";
@@ -25,7 +27,7 @@ import { resolveDiscordSenderIdentity } from "../monitor/sender-identity.js";
import { resolveDiscordThreadParentInfo } from "../monitor/threading.js";
import type { DiscordVoiceManager } from "./manager.js";
const VOICE_CHANNEL_TYPES: DiscordChannelType[] = [
const VOICE_CHANNEL_TYPES: NonNullable<APIApplicationCommandChannelOption["channel_types"]> = [
DiscordChannelType.GuildVoice,
DiscordChannelType.GuildStageVoice,
];
@@ -192,7 +194,7 @@ export function createDiscordVoiceCommand(params: VoiceCommandContext): CommandW
description = "Join a voice channel";
defer = true;
ephemeral = params.ephemeralDefault;
options = [
options: CommandOptions = [
{
name: "channel",
description: "Voice channel to join",

View File

@@ -620,15 +620,16 @@ export class DiscordVoiceManager {
logger.warn(`discord voice: TTS failed: ${ttsResult.error ?? "unknown error"}`);
return;
}
const audioPath = ttsResult.audioPath;
logVoiceVerbose(
`tts ok (${speakText.length} chars): guild ${entry.guildId} channel ${entry.channelId}`,
);
this.enqueuePlayback(entry, async () => {
logVoiceVerbose(
`playback start: guild ${entry.guildId} channel ${entry.channelId} file ${path.basename(ttsResult.audioPath)}`,
`playback start: guild ${entry.guildId} channel ${entry.channelId} file ${path.basename(audioPath)}`,
);
const resource = createAudioResource(ttsResult.audioPath);
const resource = createAudioResource(audioPath);
entry.player.play(resource);
await entersState(entry.player, AudioPlayerStatus.Playing, PLAYBACK_READY_TIMEOUT_MS).catch(
() => undefined,