Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix client-discord join voice action #2160

Merged
merged 2 commits into from
Jan 11, 2025
Merged
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
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;
odilitime marked this conversation as resolved.
Show resolved Hide resolved
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,
});
}
odilitime marked this conversation as resolved.
Show resolved Hide resolved

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
Loading