Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

music bot sound lags #228

Closed
Yudha2204 opened this issue Nov 9, 2021 · 0 comments
Closed

music bot sound lags #228

Yudha2204 opened this issue Nov 9, 2021 · 0 comments
Labels
bug Something isn't working need repro

Comments

@Yudha2204
Copy link

Issue description

I made a music bot
for the first month it played very well,
but after about 3 months it becomes laggy
even though i run it locally

Code sample

async execute() {
        if (!this.message.member?.voice?.channel) {
            this.message.channel.send('You Need To Join Voice Channel :microphone:')
            return;
        } else {
            const adapter = this.message?.guild?.voiceAdapterCreator as unknown;
            this.server.channel = joinVoiceChannel({
                channelId : this.message.member.voice.channelId ?? '',
                guildId : this.message.guildId ?? '',
                adapterCreator : adapter as DiscordGatewayAdapterCreator
            });
        }
        
        let filterQueue: Song[] = this.server.queue.filter((x: Song) => x.status === MusicStatus.Unplayed);
        
        if (filterQueue.length > 0) {
            this.server.status = 'active';
            this.server.player = createAudioPlayer();
            const song = await playDl.stream(filterQueue[0].url);
            const audioResource = createAudioResource(song.stream, {
                inputType : song.type
            })
            this.server.player.play(audioResource);
            this.server.channel.subscribe(this.server.player);
            filterQueue[0].status = MusicStatus.Playing;
            // filterQueue[1].status = MusicStatus.Next;
            this.server.player.on(AudioPlayerStatus.Idle, async () => {
                filterQueue[0].status = MusicStatus.Done;
                await this.execute();
                return;
            })
            this.message.channel.send(`Now Playing ${filterQueue[0].name} :musical_note:`);
        } else {
            this.message.channel.send(`Queue Is Empty, I Will Leave Voice Channel If Theres No Activity, :hand_splayed:`);
            this.server.status = 'inactive';
        }   
        this.server.timeStamp = new Date();
    }

@discordjs/voice version

0.6.0

Node.js version

16.11.1

Operating system

Windows

Priority this issue should have

Low (slightly annoying)

@Yudha2204 Yudha2204 added bug Something isn't working need repro labels Nov 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working need repro
Projects
None yet
Development

No branches or pull requests

1 participant