如何使用 Discord .js 通过 Discord 机器人流式传输特定麦克风?



我正在尝试创建一个机器人来流式传输我电脑的特定音频输入设备。我能够成功连接到语音聊天,但我找不到一种方法来列出我的音频输入设备并流式传输其中的特定设备。 这是我的代码:

const Discord = require('discord.js');
const client = new Discord.Client();
const {token} = require('./secret.json');
const {prefix}  = require('./config.json');
//const broadcast = client.createVoiceBroadcast();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === `${prefix}summon`) {
msg.member.voiceChannel.join()
.then(connection => {
console.log('Streaming audio.');
// should stream one of my mics
}).catch(console.error);
} else if (msg.content === `${prefix}unsummon`){
client.leaveVoiceChannel(mesg.member.voiceStat.channelID);
}
});
client.login(token);

您必须创建一个readableStream并使用connection.playStream()将数据传输到语音通道。由于 Discord.js 没有本机方法来执行此操作,因此您必须使用另一个节点模块。 https://www.npmjs.com/package/microphone-stream 可能有一些用处

最新更新