Am I missing something completely?

Bot will join voice channel but wont play music.

const {
SlashCommandBuilder,
userMention,
VoiceBasedChannel,
Events,
} = require('discord.js');
const {
joinVoiceChannel,
createAudioResource,
createAudioPlayer,
entersState,
StreamType,
AudioPlayerStatus,
VoiceConnectionStatus,
NoSubscriberBehavior
} = require("@discordjs/voice");


module.exports = {

data: new SlashCommandBuilder()
.setName("join")
.setDescription("We know your lonely, Rust Monkey will keep you company!"),
async execute(interaction) {
await interaction.reply("Don't worry, I wont tell them im forced to be your friend.")
const resource = createAudioResource('./BOOOOOM.mp3')

const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
}
});

async function connectToChannel(VoiceBasedChannel) {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
try {

await entersState(connection, VoiceConnectionStatus.Ready, 30_000);
return connection;
} catch (error) {
connection.destroy();
throw error;
}
}
const channel = interaction.member?.voice.channel;
if (channel) {

}
try {

const connection = await connectToChannel(channel);
player.play(resource)
connection.subscribe(player);
} catch (error) {
console.error(error);
}

}



};

const {
SlashCommandBuilder,
userMention,
VoiceBasedChannel,
Events,
} = require('discord.js');
const {
joinVoiceChannel,
createAudioResource,
createAudioPlayer,
entersState,
StreamType,
AudioPlayerStatus,
VoiceConnectionStatus,
NoSubscriberBehavior
} = require("@discordjs/voice");


module.exports = {

data: new SlashCommandBuilder()
.setName("join")
.setDescription("We know your lonely, Rust Monkey will keep you company!"),
async execute(interaction) {
await interaction.reply("Don't worry, I wont tell them im forced to be your friend.")
const resource = createAudioResource('./BOOOOOM.mp3')

const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
}
});

async function connectToChannel(VoiceBasedChannel) {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
try {

await entersState(connection, VoiceConnectionStatus.Ready, 30_000);
return connection;
} catch (error) {
connection.destroy();
throw error;
}
}
const channel = interaction.member?.voice.channel;
if (channel) {

}
try {

const connection = await connectToChannel(channel);
player.play(resource)
connection.subscribe(player);
} catch (error) {
console.error(error);
}

}



};
apologies if iv done something dumb, im new to discordjs voice, please bare with me
2 Replies
d.js toolkit
d.js toolkit2w ago
- What are your intents? GuildVoiceStates is required to receive voice data! - Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples. - 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! - Marked as resolved by OP
itsprobcrazy
itsprobcrazyOP2w ago
My intents are as follows
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
],
});
const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
],
});
Dependencies i currently have installed are +-- @discordjs/[email protected] +-- [email protected] `-- [email protected]

Did you find this page helpful?