最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How connect to multiple voice connections at once using Discordie - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 2

Check 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.

发布评论

评论列表(0)

  1. 暂无评论