const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus, NoSubscriberBehavior } = require('@discordjs/voice');
const fs = require('fs');
const { generateDependencyReport } = require('@discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Play audio in your voice channel'),
async execute(interaction) {
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false
});
connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
]);
// Seems to be reconnecting to a new channel - ignore disconnect
} catch (error) {
// Seems to be a real disconnect which SHOULDN'T be recovered from
connection.destroy();
}
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});
player.on('stateChange', (oldState, newState) => {
console.log(`Audio player transitioned from ${oldState.status} to ${newState.status}`);
});
const resource = createAudioResource('../../sound.mp3');
player.play(resource);
const subscription = connection.subscribe(player);
if (subscription) {
setTimeout(() => subscription.unsubscribe(), 5_000);
}
interaction.reply("Now playing")
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus, VoiceConnectionStatus, NoSubscriberBehavior } = require('@discordjs/voice');
const fs = require('fs');
const { generateDependencyReport } = require('@discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Play audio in your voice channel'),
async execute(interaction) {
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: false
});
connection.on('stateChange', (oldState, newState) => {
console.log(`Connection transitioned from ${oldState.status} to ${newState.status}`);
});
connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
]);
// Seems to be reconnecting to a new channel - ignore disconnect
} catch (error) {
// Seems to be a real disconnect which SHOULDN'T be recovered from
connection.destroy();
}
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Pause,
},
});
player.on('stateChange', (oldState, newState) => {
console.log(`Audio player transitioned from ${oldState.status} to ${newState.status}`);
});
const resource = createAudioResource('../../sound.mp3');
player.play(resource);
const subscription = connection.subscribe(player);
if (subscription) {
setTimeout(() => subscription.unsubscribe(), 5_000);
}
interaction.reply("Now playing")
},
};