javascript - voiceChannel.join() 不是函数节点 v16 discord.js
问题描述
我制作了一个播放音乐的机器人。我升级到 NodeJS v16.6.1 并且 voiceChannel.join 不再工作了。我已经尝试过使用const { voiceChannel } = require('@discord.js/voice');
,但它只是说找不到模块。代码:
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.channel;
if (!voiceChannel) return message.channel.send('You need to be in a channel to execute this command');
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) return message.channel.send('You dont have the neccesary permissions');
if (!permissions.has("SPEAK")) return message.channel.send('You dont have the neccesary permissions');
if (!args.length) return message.channel.send('Define Video');
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
})
.on('finish', () => {
voiceChannel.leave();
});
await message.reply(`Now Playing **${video.title}**`)
} else {
message.channel.send('No videos found');
}
}
}```
解决方案
正如错误所说,voiceChannel#join
实际上不是一个函数。虽然它确实存在于 Discord.js v12 上,我假设您在更新 Node.js 版本之前使用过它,但请注意,在Discord.js v13 文档VoiceChannel
中找不到它。相反,您将迁移到@discordjs/voice
,其joinVoiceChannel
功能可以用作替代品。
推荐阅读
- powershell - 在 PowerShell 中使用来自先前计算属性的数据创建计算属性
- database - LMDB如何用只读mmap写入数据库?
- java - 我该如何解决这个 NullExceptionPointer 错误?
- javascript - 如何在 React 应用程序中添加 GASP 动画作为背景?
- c# - 如何让 Newtonsoft 按原样反序列化日期并将其称为 utc?
- c# - 使用 dotnetzip 库获取没有完整目录路径的 zip 文件
- python - 当我使用具有动态 fn 名称的 Ctypes 时,为什么我会得到负 ptr?
- r - 错误:无法提取不存在的列。使用 tidyr 包中的单独功能时
- bash - 我将自己的路径设置为 $PATH 变量,以便全局访问我的一些脚本,但我无法在任何目录中访问它们
- kubernetes - Kubernetes - 从文件更新现有配置映射