gpt4 book ai didi

javascript - 如何使用 Discordie 一次连接到多个语音连接

转载 作者:行者123 更新时间:2023-11-30 21:20:00 25 4
gpt4 key购买 nike

每当我尝试让我的机器人连接到两个语音连接时,它都会与前一个断开连接。有没有办法使用 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
}

最佳答案

从有关“分片”的 discord 文档中查看此部分: 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,我都无法在文档中找到任何说明您是否可以使用的内容。

如需更多帮助,请发布您尝试执行的代码示例,有人可能会发现您的代码中的问题。

关于javascript - 如何使用 Discordie 一次连接到多个语音连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45288237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com