当我说“+sing”时,我试图让我的机器人加入用户所在的 vc。音频完成后,机器人应与 vc 断开连接。就我所知,我不知道我做错了什么。
client.on("message", msg => {
if (message.content === '+sing') {
const connection = msg.member.voice.channel.join()
channel.join().then(connection => {
console.log("Successfully connected.");
connection.play(ytdl('https://www.youtube.com/watch?v=jRxSRyrTANY', { quality: 'highestaudio' }));
}).catch(e => {
console.error(e);
connection.disconnect();
})
});
顺便说一句,我正在使用 discord.js。
答案 0 :(得分:1)
您可以获取他们的 GuildMember#VoiceState#channel 并将其用作加入的频道对象
client.on("message", msg => {
if (message.content === '+sing') {
// you should add a check to make sure they are in a voice channel
// join their channel
const connection = msg.member.voice.channel.join()
}
})