Constant in and out of VC

Issue in video
client.isMp3.set(interaction.guildId, true);

const media = interaction.options.getAttachment("mp3_file");
const audioPlayer = createAudioPlayer();
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator,
debug: true,
});

try {
connection;
connection.subscribe(audioPlayer);

const resource = createAudioResource(media.url, {
inputType: StreamType.Opus,
});

audioPlayer.play(resource);

setInterval(() => {
if (resource.ended) {
const isMp3Playing = client.isMp3.get(interaction.guildId);
if (interaction.guild.members.me.voice?.channel && isMp3Playing) {
client.isMp3.set(interaction.guildId, false);
connection.destroy();
return interaction.guild.members.me.voice.disconnect();
} else return;
}
}, 1000);

return await Embed(
client,
interaction,
client.i18n.__mf(
{ phrase: "premium.mp3play.success", locale },
{ name: media.name }
)
);
} catch (error) {
if (error) await Embed(client, interaction, "An error occured...");
throw error;
}
client.isMp3.set(interaction.guildId, true);

const media = interaction.options.getAttachment("mp3_file");
const audioPlayer = createAudioPlayer();
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator,
debug: true,
});

try {
connection;
connection.subscribe(audioPlayer);

const resource = createAudioResource(media.url, {
inputType: StreamType.Opus,
});

audioPlayer.play(resource);

setInterval(() => {
if (resource.ended) {
const isMp3Playing = client.isMp3.get(interaction.guildId);
if (interaction.guild.members.me.voice?.channel && isMp3Playing) {
client.isMp3.set(interaction.guildId, false);
connection.destroy();
return interaction.guild.members.me.voice.disconnect();
} else return;
}
}, 1000);

return await Embed(
client,
interaction,
client.i18n.__mf(
{ phrase: "premium.mp3play.success", locale },
{ name: media.name }
)
);
} catch (error) {
if (error) await Embed(client, interaction, "An error occured...");
throw error;
}
discord.jsv14.11.0 @discordjs/[email protected] @discordjs/[email protected] node v18.13.0
1 Reply
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Want results from more Discord servers?
Add your server