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
}
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
}
Share
Improve this question
edited Jul 24, 2017 at 19:53
JacobTDC
asked Jul 24, 2017 at 19:07
JacobTDCJacobTDC
4851 gold badge4 silver badges18 bronze badges
1 Answer
Reset to default 2Check out this section from the discord documentation regarding "sharding": https://discordapp./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./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.