【发布时间】:2021-11-17 08:29:13
【问题描述】:
我试图创建我的不和谐音乐机器人,但是当我运行它时。它无法加入我的语音频道,返回此错误:channel_info.channelId.join 不是函数。下面是我的代码:
const Discord = require('discord.js');
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const ytdl = require('ytdl-core');
const streamOptions = { seek: 0, volume: 1 };
const botToken = 'mytoken';
bot.login(botToken);
bot.on('ready', () => {
console.log('to olain');
});
bot.on('message', msg => {
if (msg.author.bot) {
return;
}
if (msg.content.toLowerCase().startsWith(';p')) {
const channel_info = msg.member.guild.voiceStates.cache.find(user => user.id == msg.author.id);
if (channel_info.channelId == null) {
return console.log('Canal não encontrado!');
}
console.log('Canal encontrado');
channel_info.channelId.join().then(connection => {
const stream = ytdl('https://www.youtube.com/watch?v=BxmMGnvvDCo', { filter: 'audioonly' });
const DJ = connection.playStream(stream, streamOptions);
DJ.on('end', end => {
channel_info.channelId.leave();
});
})
.catch(console.error);
}
});
【问题讨论】:
-
channel_info.channelId是一个数组吗?因为你只能在数组或类数组对象上使用.join() -
我认为您正在尝试加入 vc。这不是正确的方法。如果您使用的是 v13,则需要
@discordjs/voice包。如果您使用的是 v12,请确保它是通道对象。不是身份证。 -
请修剪您的代码,以便更容易找到您的问题。请按照以下指南创建minimal reproducible example。
标签: javascript discord.js