itsprobcrazy
DIAdiscord.js - Imagine an app
•Created by itsprobcrazy on 1/15/2025 in #djs-voice
Am I missing something completely?
Bot will join voice channel but wont play music.
apologies if iv done something dumb, im new to discordjs voice, please bare with me
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);
}
}
};
4 replies