提问者:小点点

带有distube的不和谐音乐机器人|不和谐的. js


我的代码有问题,我尝试编写一个不和谐的音乐机器人,但我总是在可视化工作室代码中显示错误消息。我尝试了多件事,但没有一件奏效。我使用distube作为机器人,因为它更容易。

我的代码:

const Discord = require('discord.js')
    DisTube = require('distube')
    module.exports = {
        execute: async (client, message, args) => { 

    const distube = new DisTube(client, { searchSongs: false, emitNewSongOnly: false });


client.on("message", async (message) => {
    if (message.author.bot) return;
    if (!message.content.startsWith(config.prefix)) return;
    const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
    const command = args.shift();

    if (command == "play")
        distube.play(message, args.join(" "));
    
    if (command == "stop") {
        distube.stop(message);
        message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Stopped the music!** 
> If you want me to rejoin, type m!play.`);
    }
    if (command == "queue") {
        let queue = distube.getQueue(message);
        message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Current queue**:
> ` + queue.songs.map((song, id) => `**${id + 1}**. ${song.name} - \`${song.formattedDuration}\``
        ).slice(0, 10).join("\n"));
    }

    if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`].includes(command)) {
        let filter = distube.setFilter(message, command);
        message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Added filter: **
> ` + (filter || "off"));
    }
    }
);

// DisTube event listeners, more in the documentation page
distube
    .on("playSong", (message, queue, song) => message.channel.send(
        `**<:miraimusic:828978156512739378> ⁓ Playing now:**
> ${song.name}\` - \`${song.formattedDuration}\``
    ))
    .on("addSong", (message, queue, song) => message.channel.send(
        `**<:miraimusic:828978156512739378> ⁓ Added: **
> ${song.name} - \`${song.formattedDuration}\` **to the queue.**`
    ))
    .on("playList", (message, queue, playlist, song) => message.channel.send(
        `**<:miraimusic:828978156512739378> ⁓ Playing now:**
>` `${song.name}\` - \`${song.formattedDuration}\``
    ))
    .on("addList", (message, queue, playlist) => message.channel.send(
        `**<:miraimusic:828978156512739378> ⁓ Added: **
> ${song.name} - \`${song.formattedDuration}\` **to the queue.**`
    ))
    // DisTubeOptions.searchSongs = true
    .on("searchResult", (message, result) => {
        let i = 0;
        message.channel.send(`**Choose an option from below**\n${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`);
    })
    // DisTubeOptions.searchSongs = true
    .on("searchCancel", (message) => message.channel.send(`Searching canceled`))
    .on("error", (message, e) => {
        console.error(e)
        message.channel.send("An error encountered: " + e);
  }

错误:

music.js(64, 34): The parser expected to find a '}' to match the '{' token here. music.js(5, 51): The parser expected to find a '}' to match the '{' token here. music.js(4, 22): The parser expected to find a '}' to match the '{' token here

我不知道是什么问题,所以是的,请帮帮我!


共1个答案

匿名用户

关闭“)”和“}”有一些问题。尝试使您的代码格式正确并具有良好的标识,以便更容易找到这些问题。

这是正确的代码:

const Discord = require('discord.js')
DisTube = require('distube')
module.exports = {
  execute: async (client, message, args) => {

    const distube = new DisTube(client, { searchSongs: false, emitNewSongOnly: false });

    client.on("message", async (message) => {
      if (message.author.bot) return;
      if (!message.content.startsWith(config.prefix)) return;
      const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
      const command = args.shift();

      if (command == "play")
        distube.play(message, args.join(" "));
      
      if (command == "stop") {
        distube.stop(message);
        message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Stopped the music!** 
        > If you want me to rejoin, type m!play.`);
      }
      if (command == "queue") {
        let queue = distube.getQueue(message);
        message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Current queue**:
        > ` + queue.songs.map((song, id) => `**${id + 1}**. ${song.name} - \`${song.formattedDuration}\``
        ).slice(0, 10).join("\n"));
      }

      if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`].includes(command)) {
        let filter = distube.setFilter(message, command);
        message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Added filter: **
        > ` + (filter || "off"));
      }
    });

    // DisTube event listeners, more in the documentation page
    distube
      .on("playSong", (message, queue, song) => message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Playing now:**> ${song.name}\` - \`${song.formattedDuration}\``))
      .on("addSong", (message, queue, song) => message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Added: **> ${song.name} - \`${song.formattedDuration}\` **to the queue.**`))
      .on("playList", (message, queue, playlist, song) => message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Playing now:**>` `${song.name}\` - \`${song.formattedDuration}\``))
      .on("addList", (message, queue, playlist) => message.channel.send(`**<:miraimusic:828978156512739378> ⁓ Added: **> ${song.name} - \`${song.formattedDuration}\` **to the queue.**`))
      // DisTubeOptions.searchSongs = true
      .on("searchResult", (message, result) => {
        let i = 0;
        message.channel.send(`**Choose an option from below**\n${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`);
      })
      // DisTubeOptions.searchSongs = true
      .on("searchCancel", (message) => message.channel.send(`Searching canceled`))
      .on("error", (message, e) => {
        console.error(e)
        message.channel.send("An error encountered: " + e);
      })
  }
}