Leizest
DIAdiscord.js - Imagine an app
•Created by Leizest on 11/10/2023 in #djs-voice
Music bot autopause
Didn't realize the file path worked that way.
5 replies
DIAdiscord.js - Imagine an app
•Created by Leizest on 11/10/2023 in #djs-voice
Music bot autopause
Thank you! That fixed it.
5 replies
DIAdiscord.js - Imagine an app
•Created by Leizest on 11/10/2023 in #djs-voice
Music bot autopause
Code:
const { SlashCommandBuilder } = require("@discordjs/builders");
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, VoiceConnectionStatus } = require('@discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Loads songs from local"),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply("You need to be in a voice channel to use this command.");
}
const player = createAudioPlayer();
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
}).subscribe(player);
connection.connection.on('error', error => {
console.error('Connection Error:', error);
});
console.log("Audio file path:", './drumeo-play-along-with-metronome.mp3');
const resource = createAudioResource('./drumeo-play-along-with-metronome.mp3', {
inlineVolume: true
});
console.log("Audio resource created:", resource);
resource.volume.setVolume(0.5);
player.play(resource);
player.on('stateChange', (oldState, newState) => {
console.log('currrent state: ', player.state);
});
player.on('error', error => {
console.error('Error:', error);
});
player.on(VoiceConnectionStatus.Disconnected, () => {
connection.destroy();
});
interaction.reply('Playing local audio in the voice channel.');
}
};
const { SlashCommandBuilder } = require("@discordjs/builders");
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, VoiceConnectionStatus } = require('@discordjs/voice');
module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Loads songs from local"),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply("You need to be in a voice channel to use this command.");
}
const player = createAudioPlayer();
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
}).subscribe(player);
connection.connection.on('error', error => {
console.error('Connection Error:', error);
});
console.log("Audio file path:", './drumeo-play-along-with-metronome.mp3');
const resource = createAudioResource('./drumeo-play-along-with-metronome.mp3', {
inlineVolume: true
});
console.log("Audio resource created:", resource);
resource.volume.setVolume(0.5);
player.play(resource);
player.on('stateChange', (oldState, newState) => {
console.log('currrent state: ', player.state);
});
player.on('error', error => {
console.error('Error:', error);
});
player.on(VoiceConnectionStatus.Disconnected, () => {
connection.destroy();
});
interaction.reply('Playing local audio in the voice channel.');
}
};
5 replies