Skip to content

Commit

Permalink
Merge pull request #2160 from elizaOS/tcm-join-voice
Browse files Browse the repository at this point in the history
fix: fix client-discord join voice action
  • Loading branch information
odilitime authored Jan 11, 2025
2 parents 0bdafda + 4a267eb commit b0e665e
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/client-discord/src/actions/joinvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
IAgentRuntime,
Memory,
State,
generateText,
ModelClass,
} from "@elizaos/core";
import {
Channel,
Expand All @@ -17,6 +19,7 @@ import {
Guild,
GuildMember,
} from "discord.js";
import { joinVoiceChannel } from "@discordjs/voice";

export default {
name: "JOIN_VOICE",
Expand Down Expand Up @@ -66,12 +69,7 @@ export default {
return false;
}

const client = state.discordClient as Client;

// Check if the client is connected to any voice channel
const isConnectedToVoice = client.voice.adapters.size === 0;

return isConnectedToVoice;
return true;
},
description: "Join a voice channel to participate in voice chat.",
handler: async (
Expand Down Expand Up @@ -115,31 +113,30 @@ export default {
);
});

if (!state.voiceManager) {
state.voiceManager = new VoiceManager({
client: state.discordClient,
runtime: runtime,
});
}

if (targetChannel) {
state.voiceManager.joinVoiceChannel({
joinVoiceChannel({
channelId: targetChannel.id,
guildId: (discordMessage as DiscordMessage).guild?.id as string,
adapterCreator: (client.guilds.cache.get(id) as Guild)
.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
group: client.user.id,
});
return true;
} else {
const member = (discordMessage as DiscordMessage)
.member as GuildMember;
if (member?.voice?.channel) {
state.voiceManager.joinVoiceChannel({
joinVoiceChannel({
channelId: member.voice.channel.id,
guildId: (discordMessage as DiscordMessage).guild
?.id as string,
adapterCreator: (client.guilds.cache.get(id) as Guild)
.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
group: client.user.id,
});
return true;
}
Expand Down Expand Up @@ -204,12 +201,15 @@ You should only respond with the name of the voice channel or none, no commentar
});

if (targetChannel) {
state.voiceManager.joinVoiceChannel({
joinVoiceChannel({
channelId: targetChannel.id,
guildId: (discordMessage as DiscordMessage).guild
?.id as string,
adapterCreator: (client.guilds.cache.get(id) as Guild)
.voiceAdapterCreator,
selfDeaf: false,
selfMute: false,
group: client.user.id,
});
return true;
}
Expand Down

0 comments on commit b0e665e

Please sign in to comment.