這是我的代碼:
const secret = require('./secret.json'); //file with your bot credentials/token/etc
const discord = require('discord.js');
const discordTTS = require('discord-tts');
const client = new discord.Client();
client.login(secret.token);
client.on('ready', () => {
console.log('Online');
});
client.on('message', msg => {
if(msg.content === 'say test 123'){
const broadcast = client.voice.createBroadcast();
const channelId = msg.member.voice.channelID;
const channel = client.channels.cache.get(channelId);
channel.join().then(connection => {
broadcast.play(discordTTS.getVoiceStream('test 123'));
const dispatcher = connection.play(broadcast);
});
}
});
輸出出現錯誤:
TypeError: client.voice.createBroadcast is not a function
我正在使用 Node:17.0.0 和 Discord.js:13.1.0
我不確定為什么會收到此錯誤。
uj5u.com熱心網友回復:
Discord.js v13 不再支持語音。加入 VC 并播放音頻的新方法是使用 @discordjs/voice 庫。
const { joinVoiceChannel, createAudioPlayer } = require("@discordjs/voice")
const player = createAudioPlayer()
joinVoiceChannel({
channelId: msg.member.voice.channel.id,
guildId: msg.guild.id,
adapterCreator: msg.guild.voiceAdapterCreator
}).subscribe(player) //join VC and subscribe to the audio player
player.play(audioResource) //make sure "audioResource" is a valid audio resource
不幸的是,discord-tts可能會被棄用。您可以錄制您自己的用戶客戶端說的訊息并將其保存到音頻檔案中。然后你可以像這樣創建一個音頻資源:
const { createAudioResource } = require("@discordjs/voice")
const audioResource = createAudioResource("path/to/local/file.mp3")
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/335929.html
標籤:javascript 节点.js 功能 不和谐 不和谐.js
上一篇:函式的使用/回傳
