@@ -19,7 +19,8 @@ import {
19
19
type Guild ,
20
20
type GuildMember ,
21
21
} from "discord.js" ;
22
- import { joinVoiceChannel } from "@discordjs/voice" ;
22
+
23
+ import { DiscordClient } from "../index.ts" ;
23
24
24
25
export default {
25
26
name : "JOIN_VOICE" ,
@@ -82,6 +83,7 @@ export default {
82
83
) : Promise < boolean > => {
83
84
if ( ! state ) {
84
85
console . error ( "State is not available." ) ;
86
+ return false ;
85
87
}
86
88
87
89
for ( const response of responses ) {
@@ -95,15 +97,20 @@ export default {
95
97
if ( ! discordMessage . content ) {
96
98
discordMessage . content = message . content . text ;
97
99
}
98
-
100
+ const discordClient = runtime . getClient ( "discord" ) as DiscordClient ;
101
+ const voiceManager = discordClient ?. voiceManager ;
102
+ if ( ! voiceManager ) {
103
+ console . error ( "voiceManager is not available." ) ;
104
+ return false ;
105
+ }
99
106
const id = ( discordMessage as DiscordMessage ) . guild ?. id as string ;
100
107
const client = state . discordClient as Client ;
101
108
const voiceChannels = (
102
109
client . guilds . cache . get ( id ) as Guild
103
110
) . channels . cache . filter (
104
111
( channel : Channel ) => channel . type === ChannelType . GuildVoice
105
112
) ;
106
-
113
+
107
114
const messageContent = discordMessage . content ;
108
115
109
116
const targetChannel = voiceChannels . find ( ( channel ) => {
@@ -121,30 +128,13 @@ export default {
121
128
} ) ;
122
129
123
130
if ( targetChannel ) {
124
- joinVoiceChannel ( {
125
- channelId : targetChannel . id ,
126
- guildId : ( discordMessage as DiscordMessage ) . guild ?. id as string ,
127
- adapterCreator : ( client . guilds . cache . get ( id ) as Guild )
128
- . voiceAdapterCreator ,
129
- selfDeaf : false ,
130
- selfMute : false ,
131
- group : client . user . id ,
132
- } ) ;
131
+ await voiceManager . joinChannel ( targetChannel ) ;
133
132
return true ;
134
133
} else {
135
134
const member = ( discordMessage as DiscordMessage )
136
135
. member as GuildMember ;
137
136
if ( member ?. voice ?. channel ) {
138
- joinVoiceChannel ( {
139
- channelId : member . voice . channel . id ,
140
- guildId : ( discordMessage as DiscordMessage ) . guild
141
- ?. id as string ,
142
- adapterCreator : ( client . guilds . cache . get ( id ) as Guild )
143
- . voiceAdapterCreator ,
144
- selfDeaf : false ,
145
- selfMute : false ,
146
- group : client . user . id ,
147
- } ) ;
137
+ await voiceManager . joinChannel ( member ?. voice ?. channel ) ;
148
138
return true ;
149
139
}
150
140
@@ -172,20 +162,21 @@ You should only respond with the name of the voice channel or none, no commentar
172
162
state : guessState as unknown as State ,
173
163
} ) ;
174
164
175
- const _datestr = new Date ( ) . toUTCString ( ) . replace ( / : / g, "-" ) ;
176
-
177
165
const responseContent = await generateText ( {
178
166
runtime,
179
167
context,
180
168
modelClass : ModelClass . TEXT_SMALL ,
181
169
} ) ;
182
170
183
- runtime . databaseAdapter . log ( {
184
- body : { message, context, response : responseContent } ,
185
- userId : stringToUuid ( message . userId ) ,
186
- roomId : message . roomId ,
187
- type : "joinVoice" ,
188
- } ) ;
171
+ // FIXME: App crashes due to a missing import for `stringToUuid`.
172
+ // However, even after importing it, the crash still occurs.
173
+ // Temporarily commenting out this logging code until the root cause is investigated.
174
+ // runtime.databaseAdapter.log({
175
+ // body: { message, context, response: responseContent },
176
+ // userId: stringToUuid(message.userId),
177
+ // roomId: message.roomId,
178
+ // type: "joinVoice",
179
+ // });
189
180
190
181
if ( responseContent && responseContent . trim ( ) . length > 0 ) {
191
182
// join the voice channel
@@ -208,16 +199,7 @@ You should only respond with the name of the voice channel or none, no commentar
208
199
} ) ;
209
200
210
201
if ( targetChannel ) {
211
- joinVoiceChannel ( {
212
- channelId : targetChannel . id ,
213
- guildId : ( discordMessage as DiscordMessage ) . guild
214
- ?. id as string ,
215
- adapterCreator : ( client . guilds . cache . get ( id ) as Guild )
216
- . voiceAdapterCreator ,
217
- selfDeaf : false ,
218
- selfMute : false ,
219
- group : client . user . id ,
220
- } ) ;
202
+ await voiceManager . joinChannel ( targetChannel ) ;
221
203
return true ;
222
204
}
223
205
}
0 commit comments