|
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"; |
5 | 9 | import {
|
6 | 10 | Client,
|
7 | 11 | Events,
|
@@ -111,6 +115,16 @@ export class DiscordClient extends EventEmitter {
|
111 | 115 | );
|
112 | 116 | }
|
113 | 117 |
|
| 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 | + |
114 | 128 | private async onClientReady(readyClient: { user: { tag: any; id: any } }) {
|
115 | 129 | elizaLogger.success(`Logged in as ${readyClient.user?.tag}`);
|
116 | 130 |
|
@@ -388,7 +402,13 @@ export function startDiscord(runtime: IAgentRuntime) {
|
388 | 402 |
|
389 | 403 | export const DiscordClientInterface: ElizaClient = {
|
390 | 404 | 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 | + } |
393 | 413 | },
|
394 | 414 | };
|
0 commit comments