* Sets up a message component collector for the playing message to handle * button interactions. This collector listens for button clicks and dispatches * commands based on the custom ID of the clicked button. It supports functionalities * like skip, stop, play/pause, volume control, and mo
(newState: AudioPlayerPlayingState)
| 308 | * ensuring that interactions are only valid for the current playing song. |
| 309 | */ |
| 310 | private async sendPlayingMessage(newState: AudioPlayerPlayingState) { |
| 311 | const song = (newState.resource as AudioResource<Song>).metadata; |
| 312 | |
| 313 | let playingMessage: Message; |
| 314 | |
| 315 | try { |
| 316 | playingMessage = await this.textChannel.send({ |
| 317 | content: song.startMessage(), |
| 318 | components: this.createButtonRow() |
| 319 | }); |
| 320 | } catch (error: unknown) { |
| 321 | console.error(error); |
| 322 | if (error instanceof Error) this.textChannel.send(error.message); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | const filter = (i: Interaction) => i.isButton() && i.message.id === playingMessage.id; |
| 327 | |
| 328 | const collector = playingMessage.createMessageComponentCollector({ |
| 329 | filter, |
| 330 | time: song.duration > 0 ? song.duration * 1000 : 60000 |
| 331 | }); |
| 332 | |
| 333 | collector.on("collect", async (interaction) => { |
| 334 | if (!interaction.isButton()) return; |
| 335 | if (!this.songs) return; |
| 336 | |
| 337 | const handler = this.commandHandlers.get(interaction.customId); |
| 338 | |
| 339 | if (["skip", "stop"].includes(interaction.customId)) collector.stop(); |
| 340 | |
| 341 | if (handler) await handler.call(this, interaction); |
| 342 | }); |
| 343 | |
| 344 | collector.on("end", () => { |
| 345 | // Remove the buttons when the song ends |
| 346 | playingMessage.edit({ components: [] }).catch(console.error); |
| 347 | |
| 348 | // Delete the message if pruning is enabled |
| 349 | if (config.PRUNING) { |
| 350 | setTimeout(() => { |
| 351 | playingMessage.delete().catch(); |
| 352 | }, 3000); |
| 353 | } |
| 354 | }); |
| 355 | } |
| 356 | } |
no test coverage detected