@elizaos/plugin-discord 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +3946 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shaw Walters, aka Moon aka @lalalune
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @elizaos/client-discord
|
|
2
|
+
|
|
3
|
+
A Discord client implementation for ElizaOS, enabling rich integration with Discord servers for managing interactions, voice, and message handling.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Handle server join events and manage initial configurations.
|
|
8
|
+
- Voice event management via the voice manager.
|
|
9
|
+
- Manage and process new messages with the message manager.
|
|
10
|
+
- Slash command registration and interaction handling.
|
|
11
|
+
- Disconnect websocket and unbind all listeners when required.
|
|
12
|
+
- Robust permissions management for bot functionality.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
As this is a workspace package, it's installed as part of the ElizaOS monorepo:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
The client requires the following environment variables:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Discord API Credentials
|
|
28
|
+
DISCORD_APPLICATION_ID=your_application_id
|
|
29
|
+
DISCORD_API_TOKEN=your_api_token
|
|
30
|
+
|
|
31
|
+
# Optional Settings (add any additional details here if necessary)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### Basic Initialization
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { DiscordClientInterface } from '@elizaos/client-discord';
|
|
40
|
+
|
|
41
|
+
// Initialize the client
|
|
42
|
+
const discordManager = await DiscordClientInterface.start(runtime);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Slash Command Registration
|
|
46
|
+
|
|
47
|
+
To register slash commands:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
await discordManager.command.registerCommands([
|
|
51
|
+
{
|
|
52
|
+
name: 'example',
|
|
53
|
+
description: 'An example slash command',
|
|
54
|
+
options: []
|
|
55
|
+
}
|
|
56
|
+
]);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Handling Messages
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// Listen for new messages
|
|
63
|
+
await discordManager.message.handleNewMessage({
|
|
64
|
+
channelId: 'channel-id',
|
|
65
|
+
content: 'Hello Discord!'
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Managing Voice Events
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// Join a voice channel
|
|
73
|
+
await discordManager.voice.joinChannel('channel-id');
|
|
74
|
+
|
|
75
|
+
// Handle voice interactions
|
|
76
|
+
await discordManager.voice.handleInteraction({
|
|
77
|
+
userId: 'user-id',
|
|
78
|
+
action: 'speak'
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Key Components
|
|
83
|
+
|
|
84
|
+
1. **ClientBase**
|
|
85
|
+
- Handles authentication and session management.
|
|
86
|
+
- Manages websocket connections.
|
|
87
|
+
|
|
88
|
+
2. **MessageManager**
|
|
89
|
+
- Processes incoming messages and responses.
|
|
90
|
+
- Supports message formatting and templating.
|
|
91
|
+
|
|
92
|
+
3. **VoiceManager**
|
|
93
|
+
- Manages voice interactions and events.
|
|
94
|
+
- Handles joining and leaving voice channels.
|
|
95
|
+
|
|
96
|
+
4. **CommandManager**
|
|
97
|
+
- Registers and processes slash commands.
|
|
98
|
+
- Ensures permissions are validated.
|
|
99
|
+
|
|
100
|
+
## Notes
|
|
101
|
+
|
|
102
|
+
Ensure that your `.env` file includes the required environment variables for proper functionality. Additional features or modules can be extended as part of the ElizaOS framework.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Media, Character, IAgentRuntime, ChannelType, UUID, Plugin, Service } from '@elizaos/core';
|
|
2
|
+
import { Message, Client, Channel, VoiceState, BaseGuildVoiceChannel, Guild, OAuth2Guild, MessageReaction, User } from 'discord.js';
|
|
3
|
+
import { VoiceConnection, AudioPlayer } from '@discordjs/voice';
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
6
|
+
|
|
7
|
+
declare class MessageManager {
|
|
8
|
+
private client;
|
|
9
|
+
private runtime;
|
|
10
|
+
private attachmentManager;
|
|
11
|
+
private getChannelType;
|
|
12
|
+
constructor(discordClient: any);
|
|
13
|
+
handleMessage(message: Message): Promise<void>;
|
|
14
|
+
processMessage(message: Message): Promise<{
|
|
15
|
+
processedContent: string;
|
|
16
|
+
attachments: Media[];
|
|
17
|
+
}>;
|
|
18
|
+
fetchBotName(botToken: string): Promise<string>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface IDiscordService {
|
|
22
|
+
client: Client;
|
|
23
|
+
character: Character;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare class VoiceManager extends EventEmitter {
|
|
27
|
+
private processingVoice;
|
|
28
|
+
private transcriptionTimeout;
|
|
29
|
+
private userStates;
|
|
30
|
+
private activeAudioPlayer;
|
|
31
|
+
private client;
|
|
32
|
+
private runtime;
|
|
33
|
+
private streams;
|
|
34
|
+
private connections;
|
|
35
|
+
private activeMonitors;
|
|
36
|
+
private ready;
|
|
37
|
+
constructor(service: DiscordService, runtime: IAgentRuntime);
|
|
38
|
+
getChannelType(channel: Channel): Promise<ChannelType>;
|
|
39
|
+
private setReady;
|
|
40
|
+
isReady(): boolean;
|
|
41
|
+
handleVoiceStateUpdate(oldState: VoiceState, newState: VoiceState): Promise<void>;
|
|
42
|
+
joinChannel(channel: BaseGuildVoiceChannel): Promise<void>;
|
|
43
|
+
getVoiceConnection(guildId: string): VoiceConnection;
|
|
44
|
+
private monitorMember;
|
|
45
|
+
leaveChannel(channel: BaseGuildVoiceChannel): void;
|
|
46
|
+
stopMonitoringMember(memberId: string): void;
|
|
47
|
+
debouncedProcessTranscription(entityId: UUID, name: string, userName: string, channel: BaseGuildVoiceChannel): Promise<void>;
|
|
48
|
+
handleUserStream(userId: UUID, name: string, userName: string, channel: BaseGuildVoiceChannel, audioStream: Readable): Promise<void>;
|
|
49
|
+
private processTranscription;
|
|
50
|
+
private handleMessage;
|
|
51
|
+
private convertOpusToWav;
|
|
52
|
+
scanGuild(guild: Guild): Promise<void>;
|
|
53
|
+
playAudioStream(entityId: UUID, audioStream: Readable): Promise<void>;
|
|
54
|
+
cleanupAudioPlayer(audioPlayer: AudioPlayer): void;
|
|
55
|
+
handleJoinChannelCommand(interaction: any): Promise<void>;
|
|
56
|
+
handleLeaveChannelCommand(interaction: any): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class DiscordService extends Service implements IDiscordService {
|
|
60
|
+
static serviceType: string;
|
|
61
|
+
capabilityDescription: string;
|
|
62
|
+
client: Client;
|
|
63
|
+
character: Character;
|
|
64
|
+
messageManager: MessageManager;
|
|
65
|
+
voiceManager: VoiceManager;
|
|
66
|
+
constructor(runtime: IAgentRuntime);
|
|
67
|
+
ensureAllChannelsExist(runtime: IAgentRuntime, guild: OAuth2Guild): Promise<void>;
|
|
68
|
+
private setupEventListeners;
|
|
69
|
+
private handleGuildMemberAdd;
|
|
70
|
+
static start(runtime: IAgentRuntime): Promise<DiscordService>;
|
|
71
|
+
static stop(runtime: IAgentRuntime): Promise<void>;
|
|
72
|
+
stop(): Promise<void>;
|
|
73
|
+
private onClientReady;
|
|
74
|
+
getChannelType(channel: Channel): Promise<ChannelType>;
|
|
75
|
+
handleReactionAdd(reaction: MessageReaction, user: User): Promise<void>;
|
|
76
|
+
handleReactionRemove(reaction: MessageReaction, user: User): Promise<void>;
|
|
77
|
+
private handleGuildCreate;
|
|
78
|
+
private handleInteractionCreate;
|
|
79
|
+
/**
|
|
80
|
+
* Builds a standardized list of rooms from Discord guild channels
|
|
81
|
+
*/
|
|
82
|
+
private buildStandardizedRooms;
|
|
83
|
+
/**
|
|
84
|
+
* Builds a standardized list of users from Discord guild members
|
|
85
|
+
*/
|
|
86
|
+
private buildStandardizedUsers;
|
|
87
|
+
private onReady;
|
|
88
|
+
}
|
|
89
|
+
declare const discordPlugin: Plugin;
|
|
90
|
+
|
|
91
|
+
export { DiscordService, discordPlugin as default };
|