@jubbio/voice 1.0.7 → 1.0.8

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.
Files changed (2) hide show
  1. package/README.md +26 -14
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -39,6 +39,7 @@ import {
39
39
  createAudioPlayer,
40
40
  createAudioResourceFromUrl,
41
41
  probeAudioInfo,
42
+ getVoiceConnection,
42
43
  AudioPlayerStatus
43
44
  } from '@jubbio/voice';
44
45
 
@@ -49,6 +50,18 @@ const client = new Client({
49
50
  ]
50
51
  });
51
52
 
53
+ // Store players per guild
54
+ const players = new Map();
55
+
56
+ function getPlayer(guildId) {
57
+ let player = players.get(guildId);
58
+ if (!player) {
59
+ player = createAudioPlayer();
60
+ players.set(guildId, player);
61
+ }
62
+ return player;
63
+ }
64
+
52
65
  client.on('interactionCreate', async (interaction) => {
53
66
  if (!interaction.isCommand()) return;
54
67
 
@@ -60,33 +73,32 @@ client.on('interactionCreate', async (interaction) => {
60
73
  return interaction.reply('❌ Join a voice channel first!');
61
74
  }
62
75
 
63
- // Defer reply while fetching song info
64
76
  await interaction.deferReply();
65
77
 
66
78
  try {
67
- // Get song info
68
79
  const info = await probeAudioInfo(url);
69
80
 
70
- // Join voice channel
71
- const connection = joinVoiceChannel({
72
- channelId: voiceChannel,
73
- guildId: interaction.guildId,
74
- adapterCreator: client.voice.adapters.get(interaction.guildId)
75
- });
81
+ // Check for existing connection, only join if not connected
82
+ let connection = getVoiceConnection(interaction.guildId);
83
+ if (!connection) {
84
+ connection = joinVoiceChannel({
85
+ channelId: voiceChannel,
86
+ guildId: interaction.guildId,
87
+ adapterCreator: client.voice.adapters.get(interaction.guildId)
88
+ });
89
+
90
+ const player = getPlayer(interaction.guildId);
91
+ connection.subscribe(player);
92
+ }
76
93
 
77
- // Create player and play
78
- const player = createAudioPlayer();
94
+ const player = getPlayer(interaction.guildId);
79
95
  const resource = createAudioResourceFromUrl(info.url);
80
-
81
- connection.subscribe(player);
82
96
  player.play(resource);
83
97
 
84
- // Format duration
85
98
  const minutes = Math.floor(info.duration / 60);
86
99
  const seconds = info.duration % 60;
87
100
  const durationStr = `${minutes}:${seconds.toString().padStart(2, '0')}`;
88
101
 
89
- // Create embed with song info
90
102
  const embed = new EmbedBuilder()
91
103
  .setTitle('🎵 Now Playing')
92
104
  .setDescription(`**${info.title}**`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jubbio/voice",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Voice library for Jubbio bots with LiveKit backend",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",