我想出了如何将我的漫游器连接到语音通道,但是我不知道如何使它播放mp3文件。
bot.on('message', async message => {
// Voice only works in guilds, if the message does not come from a guild,
// we ignore it
if (!message.guild) return;
if (message.content === '/join') {
// Only try to join the sender's voice channel if they are in one themselves
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
} else {
message.reply('You need to join a voice channel first!');
}
}
});
答案 0 :(得分:0)
您可以使用voiceConnection
来play()
音频文件
const channel = message.member.voice.channel;
channel.join().then(async(connection) => {
const stream = connection.play('/path/to/audio/file.mp3');
stream.on("finish", () => {
channel.leave(); // Leaves channel once the mp3 file finishes playing
});
}).catch((err: any) => console.log(err));