首页 > 解决方案 > 为什么我的播放命令一直给我一个错误

问题描述

我试图为我的 discord.js 机器人制作音乐播放命令,但文件一直给我一个错误,我不明白为什么会这样。

const ytdl = require("ytdl-core");
const ytSearch = require("yt-search");

module.export = {
  name: "play",
  description: "Joins the vc and plays a yt vid",
  execute(message, args) {
    const voiceChannel = message.member.voiceChannel;

    if (!voiceChannel)
      return message.channel.send("You need to be in a vc to use this command");
    const permissions = voiceChannel.permissionsFor(message.client.user);
    if (!permissions.has("CONNECT"))
      return message.channel.send("You dont have the required permissions");
    if (!permissions.has("SPEAK"))
      return message.channel.send("You dont have the required permissions");
    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 });
    }
  },
};

标签: javascriptnode.jsdiscorddiscord.js

解决方案


根据给的错误,您的代码有错字导致给定的语法错误,它是

 + module.exports 
 - module.export // not this

在此处进行了适当的更改


推荐阅读