【发布时间】:2021-11-02 10:48:25
【问题描述】:
const ytSearch = require('yt-search');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');
const player = createAudioPlayer()
module.exports = {
name: 'play',
description: 'Joins and plays a video from youtube',
execute: async (client, msg, arg, Discord) => {
const voiceChannel = msg.member.voice.channel;
if (!voiceChannel) return msg.channel.send('You need to be in a channel to execute this command!');
const permissions = voiceChannel.permissionsFor(msg.client.user);
if (!permissions.has('CONNECT')) return msg.channel.send('You dont have the correct permissins');
if (!permissions.has('SPEAK')) return msg.channel.send('You dont have the correct permissins');
if (!arg.length) return msg.channel.send('You need to send the second argument!');
var connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: msg.channel.guild.voiceAdapterCreator,
});
const videoFinder = async (query) => {
const videoResult = await ytSearch(query);
return (videoResult.videos.length > 1) ? videoResult.videos[0] : null;
}
const keywords = await arg.join(' ')
const video = await videoFinder(keywords);
if (video) {
const stream = ytdl(video.url, { filter: 'audioonly' });
const player = createAudioPlayer()
var resource = createAudioResource(stream)
player.play(resource)
connection.subscribe(player);
await msg.reply(`:thumbsup: Now Playing ***${video.title}***`)
}
else{
msg.reply('No Results Found')
}
}
}
过去几个月我一直在寻找解决方案 甚至尝试了每个平台 并去了支持服务器,但一无所获
代码执行没有任何错误 机器人加入 VC 还会发送一条消息,播放您的歌曲
但在 VC 中,机器人不会说话
所以有人可以帮助我 解决代码或修复我需要的东西 注意:我已经安装了每个必需的依赖项
【问题讨论】:
-
请在您的问题
client.on("debug", e => console.log(e))中添加调试日志,以便我们查看它是否真的在发送流位。 -
这对我也不起作用,在最新版本的 discord.js (13.x) 上。降级到 12.x 版的工作符合我的预期。
标签: javascript node.js discord discord.js voice