Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  58] [ 3]  / answers: 1 / hits: 20472  / 7 Years ago, mon, july 24, 2017, 12:00:00

Whenever I try to make my bot connect to two voice connections, it disconnects from the previous one. Is there a way to connect to multiple voice sockets using Discordie? If so, how?



Here is my code:





const Discordie = require(discordie);
const fs = require('fs');

const Events = Discordie.Events;
const client = new Discordie({autoReconnect: true});
client.autoReconnect.enable();
client.connect({token: token});


var channels = new Array();
var connections = new Object();


client.Dispatcher.on(Events.GATEWAY_READY, e => {
client.User.setStatus(online);
console.log(Connected as: + client.User.username);
process.title = Discord Bot: + client.User.username;
client.Channels.forEach((channel) => {
if (channel.name == 'cantina') channels.push(channel.id);
});
r.context.client = client;
r.displayPrompt();
});

client.Dispatcher.on(Events.CHANNEL_CREATE, (e) => {
if (e.channel.name == 'cantina') {
channels.push(e.channel.id);
}
});

client.Dispatcher.on(Events.VOICE_CHANNEL_JOIN, (e) => {
if (channels.includes(e.channel.id) && e.channel.members.length <= 2) {
e.channel.join().then((info) => {
var connection = info.voiceConnection;
connections[e.channel.id] = {
channel: e.channel,
connectionInfo : info,
connection: connection
}
play(e.channel, connection);
});
}
});

function play(channel, connection) {
//function to play the song
}




More From » node.js

 Answers
7

Check out this section from the discord documentation regarding sharding:
https://discordapp.com/developers/docs/topics/gateway#sharding




As bots grow and are added to an increasing number of guilds, some developers may find it necessary to break or split portions of their bots operations into separate logical processes. As such, Discord gateways implement a method of user-controlled guild-sharding which allows for splitting events across a number of gateway connections. Guild sharding is entirely user controlled, and requires no state-sharing between separate connections to operate.




That's referring to gateway connections, but according to this section:
https://discordapp.com/developers/docs/topics/voice-connections#voice




Voice connections operate in a similar fashion to the Gateway connection, however they operate on a different set of payloads, and utilize a separate UDP-based connection for voice data transmission.




So, you can infer that if multiple gateway connections are possible and voice connections are similar, then yes it is possible. Whether it's possible using discordie, I was not able to find anything in the documentation that said whether you can or not.



For more help, post a code example of what you're trying to do, someone might be able to spot an issue in your code.


[#56992] Thursday, July 20, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;