Skip to content

Commit 9e9d23b

Browse files
committed
implement stop
1 parent adfda1a commit 9e9d23b

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

packages/client-discord/src/index.ts

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { getEmbeddingZeroVector } from "@ai16z/eliza";
2-
import { Character, Client as ElizaClient, IAgentRuntime } from "@ai16z/eliza";
3-
import { stringToUuid } from "@ai16z/eliza";
4-
import { elizaLogger } from "@ai16z/eliza";
1+
import {
2+
getEmbeddingZeroVector,
3+
stringToUuid,
4+
elizaLogger,
5+
Character,
6+
Client as ElizaClient,
7+
IAgentRuntime,
8+
} from "@ai16z/eliza";
59
import {
610
Client,
711
Events,
@@ -111,6 +115,16 @@ export class DiscordClient extends EventEmitter {
111115
);
112116
}
113117

118+
async stop() {
119+
try {
120+
// disconnect websocket
121+
// this unbinds all the listeners
122+
await this.client.destroy();
123+
} catch(e) {
124+
elizaLogger.error('client-discord instance stop err', e);
125+
}
126+
}
127+
114128
private async onClientReady(readyClient: { user: { tag: any; id: any } }) {
115129
elizaLogger.success(`Logged in as ${readyClient.user?.tag}`);
116130

@@ -388,7 +402,13 @@ export function startDiscord(runtime: IAgentRuntime) {
388402

389403
export const DiscordClientInterface: ElizaClient = {
390404
start: async (runtime: IAgentRuntime) => new DiscordClient(runtime),
391-
stop: async (_runtime: IAgentRuntime) => {
392-
console.warn("Discord client does not support stopping yet");
405+
stop: async (runtime: IAgentRuntime) => {
406+
try {
407+
// stop it
408+
elizaLogger.log('Stopping discord client', runtime.agentId)
409+
await runtime.clients.discord.stop()
410+
} catch(e) {
411+
elizaLogger.error('client-discord interface stop error', e);
412+
}
393413
},
394414
};

0 commit comments

Comments
 (0)