lolka.js 0.3.0 → 0.3.1
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/README.md +53 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,3 +34,56 @@ client.on('messageCreate', (message) => {
|
|
|
34
34
|
|
|
35
35
|
client.login('token');
|
|
36
36
|
```
|
|
37
|
+
|
|
38
|
+
## Voice
|
|
39
|
+
|
|
40
|
+
Voice works over WebRTC (lolka's voice stack, not Discord's UDP transport) and ships with the base
|
|
41
|
+
install — there's nothing extra to add. The API is in the spirit of `@discordjs/voice`: get a
|
|
42
|
+
connection with `joinVoiceChannel`, play audio, and (optionally) receive other participants' audio.
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const { Client, GatewayIntentBits, joinVoiceChannel } = require('lolka.js');
|
|
46
|
+
|
|
47
|
+
const client = new Client({
|
|
48
|
+
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
client.on('messageCreate', async (message) => {
|
|
52
|
+
if (message.content !== '!play') return;
|
|
53
|
+
|
|
54
|
+
const channel = message.member?.voice?.channel;
|
|
55
|
+
if (!channel) return message.reply('Join a voice channel first.');
|
|
56
|
+
|
|
57
|
+
const connection = joinVoiceChannel({
|
|
58
|
+
channelId: channel.id,
|
|
59
|
+
guildId: channel.guild.id,
|
|
60
|
+
adapterCreator: channel.guild.voiceAdapterCreator,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// receive other participants' audio (optional)
|
|
64
|
+
connection.on('track', (track, userId) => {
|
|
65
|
+
// `track` is a MediaStreamTrack from @roamhq/wrtc
|
|
66
|
+
console.log(`receiving audio from ${userId}`);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await connection.awaitReady();
|
|
70
|
+
connection.play('song.mp3'); // a file path or any Readable stream (decoded via ffmpeg)
|
|
71
|
+
|
|
72
|
+
connection.on('idle', () => console.log('playback finished'));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
client.login('token');
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Leave the channel with `connection.destroy()`, and stop playback (without leaving) with
|
|
79
|
+
`connection.stop()`. Playing files requires `ffmpeg` to be available in the bot's environment.
|
|
80
|
+
|
|
81
|
+
`joinVoiceChannel(options)` accepts:
|
|
82
|
+
|
|
83
|
+
| option | type | description |
|
|
84
|
+
| --- | --- | --- |
|
|
85
|
+
| `channelId` | `string` | Voice channel id |
|
|
86
|
+
| `guildId` | `string` | Guild id |
|
|
87
|
+
| `adapterCreator` | `Function` | `guild.voiceAdapterCreator` |
|
|
88
|
+
| `selfMute` | `boolean` | default `false` |
|
|
89
|
+
| `selfDeaf` | `boolean` | default `false` |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "lolka.js",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description": "A powerful library for interacting with the lolka bot API (discord.js-compatible fork)",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "node ./scripts/esmDts.mjs",
|