#Bot instantly stops playing
2 messages · Page 1 of 1 (latest)
The code is
const fs = require('fs');
const { createAudioResource, StreamType, createAudioPlayer, joinVoiceChannel, AudioPlayerStatus } = require('@discordjs/voice');
const { join } = require('path');
module.exports = {
event: "ready", // Name of the event
oneTime: true, // If set to true the event will only be fired once until the client is restarted
run: async (client) => {
let resources = fs.readdirSync(`${process.cwd()}/audio/`);
const connection = joinVoiceChannel({
channelId: '948559053448163359',
guildId: client.guilds.cache.first().id,
adapterCreator: client.guilds.cache.first().voiceAdapterCreator,
});
const player = createAudioPlayer();
player.on(AudioPlayerStatus.Idle, () => {
console.log("Song finished")
})
play()
console.log('playing')
async function play () {
let file = resources[Math.floor(Math.random() * resources.length)]
let resource = createAudioResource(join(__dirname, file));
player.play(resource);
connection.subscribe(player)
console.log('subscribed')
}
console.log(`Started as ${client.user.tag}`)
}
}