discordjs / voice

Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Apache License 2.0
327 stars 110 forks source link

You can't use Multiple clients at once #230

Closed Majoramari closed 3 years ago

Majoramari commented 3 years ago

Issue description

I have private bots for my private server, I'm using Discord.js@12.x.x, I'm willing to upgrade to Discord.js@13.x.x.

One of the key things I love to have is having multiple clients at multiple voice channels to let people enjoy music.

But I found a Bug in The joinVoiceChannel method from @discordjs/voice.

Explain: When you use joinVoiceChannel Always the first client that login is the one who join the channel, you can't make the rest of the clients join.

Code sample

import { Client } from 'discord.js';
import { joinVoiceChannel } from '@discordjs/voice';

const tokens = [
    "TOKEN1",
    "TOKEN2"
];

for (const token of tokens) {
    const client = new Client({ intents: ['GUILD_VOICE_STATES', 'GUILD_MESSAGES', 'GUILDS'] });

    client.on('ready', () => console.log(`${client.user.username} is ready!`));

    client.on('messageCreate', async (message) => {

        if (message.content === '1') {
            const channel = message.member.voice.channel;
            joinVoiceChannel({
                channelId: channel.id,
                guildId: channel.guild.id,
                adapterCreator: channel.guild.voiceAdapterCreator,
            });
        }

    });

    client.login(token);
}

@discordjs/voice version

0.7.2

Node.js version

node: v16.6.1, typescript: 4.2.4

Operating system

Tried it on Linux Debian, Linux Ubuntu, WSL Debian, Windows 11

Priority this issue should have

Medium (should be fixed soon)

Liightu commented 3 years ago

I have the same problem, I think the problem is from the package

vijayymmeena commented 3 years ago

This issue is already addressed back in days, you can assign a custom value to group field in your joinVoiceChannel config. That will resolve the issue.

Majoramari commented 3 years ago

This issue is already addressed back in days, you can assign a custom value to group field in your joinVoiceChannel config. That will resolve the issue.

Thank you!, Could you give me an example please because I tried this, but it didn't work!

vijayymmeena commented 3 years ago

This issue is already addressed back in days, you can assign a custom value to group field in your joinVoiceChannel config. That will resolve the issue.

Thank you!, Could you give me an example please because I tried this, but it didn't work!

    const _voiceConnection = joinVoiceChannel({
      adapterCreator: <adapter>,
      channelId: channel.id,
      group: "<your custom group id>",
      guildId: channel.guild.id,
    });
ghost commented 2 years ago

using discord.js 13 and voice 0.7.5, group thing did not change anything. I don't understand why one voice connection should have any effect on others for other client instances; seems like the module is storing state in itself or globally and violating common sense. Instances should have nothing to do with each-other.

kyranet commented 2 years ago

The question is more like, why are you running multiple bots within the same process, violating the single-purpose software principle many places follow?

Run your bots in separate threads or processes, and this problem will be solved.