1 回答
TA贡献1786条经验 获得超11个赞
这是discord.js 中的一个错误,为了解决这个问题,我们需要播放音频......
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
const { Readable } = require('stream');
const SILENCE_FRAME = Buffer.from([0xF8, 0xFF, 0xFE]);
class Silence extends Readable {
_read() {
this.push(SILENCE_FRAME);
this.destroy();
}
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', async message => {
if (message.content === 's' && message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
const audio = connection.receiver.createStream(message, { mode: 'pcm', end: 'manual' });
audio.pipe(fs.createWriteStream('user_audio'));
connection.play(new Silence(), { type: 'opus' });
console.log(message.member.user.id);
}
});
client.login('token');
添加回答
举报