【发布时间】:2021-11-18 19:03:48
【问题描述】:
我正在尝试让我的 discord 机器人为我的 discord 服务器播放音乐(鉴于正常关闭)。
但是当我尝试使用message.members.voice.join() 让它加入时,它总是返回未定义,即使我在不和谐的语音频道中也是如此。我已离开并重新加入通话,并重新启动了机器人,但没有任何效果。
const ytdl = require('ytdl-core');
const ytSearch = require('yt-search');
module.exports = {
name: 'play',
description: 'Joins and plays a video from youtube',
async execute(message, args) {
const { voiceChannel } = message.member.voice;
if (!voiceChannel) return message.channel.send('Join a Voice-Channel to use this command');
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) return message.channel.send('You dont have the correct permissins');
if (!permissions.has('SPEAK')) return message.channel.send('You dont have the correct permissins');
if (!args.length) return message.channel.send('You need to send the second argument!');
const connection = await voiceChannel.join();
const videoFinder = async (query) => {
const videoResult = await ytSearch(query);
return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;
}
const video = await videoFinder(args.join(' '));
if (video) {
const stream = ytdl(video.url, { filter: 'audioonly' })
connection.play(stream, { seek: 0, volume: 1 });
}
}
}
【问题讨论】:
-
您使用的是 v13 吗?
-
你的 discord.js 版本是多少?
标签: discord.js