如何使用 Discordie 一次连接到多个语音连接
How connect to multiple voice connections at once using Discordie
每当我尝试让我的机器人连接到两个语音连接时,它都会与前一个断开连接。有没有办法使用 Discordie 连接到多个语音套接字?如果可以,怎么做?
这是我的代码:
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
}
从有关 "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.
这是指网关连接,但根据本节:
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.
所以,你可以推断,如果多个网关连接是可能的,并且语音连接是类似的,那么是可以的。是否可以使用 discordie,我无法在文档中找到任何说明是否可以的内容。
如需更多帮助,post您正在尝试执行的操作的代码示例,有人可能会发现您的代码中的问题。
每当我尝试让我的机器人连接到两个语音连接时,它都会与前一个断开连接。有没有办法使用 Discordie 连接到多个语音套接字?如果可以,怎么做?
这是我的代码:
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
}
从有关 "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.
这是指网关连接,但根据本节: 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.
所以,你可以推断,如果多个网关连接是可能的,并且语音连接是类似的,那么是可以的。是否可以使用 discordie,我无法在文档中找到任何说明是否可以的内容。
如需更多帮助,post您正在尝试执行的操作的代码示例,有人可能会发现您的代码中的问题。