I'm developing a search command for a music bot, every time I click an option in the selection menu it listens to the interaction once only the first time, and every time after that it listens to the same interaction one more time (twice, thrice and so on, notice the same ID on the last two logs), resulting in the same message being sent that amount of times.
Code:
const play = require('play-dl')
msg.reply({ embeds: [embed], components: [row] })
// Get selection
let playing = false;
let originalUser = msg.author.id
client.on(Events.InteractionCreate, async interaction => {
console.log(interaction)
if (interaction.isStringSelectMenu()) {
if (originalUser != interaction.user.id)
return interaction.reply({ content: 'You can\'t choose music for someone else', ephemeral: true })
if (playing == true && interaction.isStringSelectMenu())
return interaction.reply({ content: 'Another song is playing already', ephemeral: true })
// Video data
const vidInfo = await play.video_info(interaction.values[0])
const vidTitle = vidInfo.video_details.title
const vidChan = vidInfo.video_details.channel
// Initiate video stream
const video = await play.stream(interaction.values[0])
const resource = createAudioResource(video.stream, { inputType: video.type })
// Connect and play
connection
player.play(resource)
connection.subscribe(player)
// Set playing status to true while playing
player.on(AudioPlayerStatus.Playing, () => {
playing = true;
})
msg.reply({ content: `Playing **${vidTitle}** by **${vidChan}**` })
// Set playing status to false on idle
player.on(AudioPlayerStatus.Idle, () => {
playing = false;
})
What am I doing wrong for it to trigger the same interaction multiple times?
I've been advised to use a collector instead but I have no idea with how to implement that