How to return player in external function

function playURL(interaction){
let url = interaction.options.getString("url");
const player = interaction.legacyPlayer
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.member.voice.channel.guild.id,
adapterCreator: interaction.member.voice.channel.guild.voiceAdapterCreator,
});

player.play(createAudioResource(url), { type: 'unknown' });
connection.subscribe(player);
interaction.legacyPlayer.test = player
interaction.reply('Now playing audio!');

}
function playURL(interaction){
let url = interaction.options.getString("url");
const player = interaction.legacyPlayer
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.member.voice.channel.guild.id,
adapterCreator: interaction.member.voice.channel.guild.voiceAdapterCreator,
});

player.play(createAudioResource(url), { type: 'unknown' });
connection.subscribe(player);
interaction.legacyPlayer.test = player
interaction.reply('Now playing audio!');

}
How to stop if below method not work
console.log(interaction.legacyPlayer)
try{
interaction.legacyPlayer.stop();
interaction.reply({embeds: [stopEmbed]})
}
console.log(interaction.legacyPlayer)
try{
interaction.legacyPlayer.stop();
interaction.reply({embeds: [stopEmbed]})
}
2 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Klubuntu
KlubuntuOP17mo ago
This method return only
AudioPlayer {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_state: { status: 'idle' },
subscribers: [],
behaviors: { noSubscriber: 'pause', maxMissedFrames: 5 },
debug: [Function (anonymous)],
[Symbol(kCapture)]: false
}
AudioPlayer {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_state: { status: 'idle' },
subscribers: [],
behaviors: { noSubscriber: 'pause', maxMissedFrames: 5 },
debug: [Function (anonymous)],
[Symbol(kCapture)]: false
}
Want results from more Discord servers?
Add your server