0

我最近在尝试使用 distube 播放 url 时遇到问题,它似乎每次都在搜索,我希望它能够区分 youtube url 和搜索查询!

这是我的 Distube 选项;

const distube = new DisTube.default(client, {
  searchSongs: 10,
  searchCooldown: 30,
  emitNewSongOnly: true,
  leaveOnEmpty: true,
  emptyCooldown: 20,
  leaveOnFinish: true,
  youtubeDL: false,
  leaveOnStop: true,
  plugins: [new SpotifyPlugin({
    emitEventsAfterFetching: true
  }), new SoundCloudPlugin(), new YtDlpPlugin()],
})

这是我的播放命令:

const prefix = ";"

exports.run = async (client, message, args, distube) => {
  args = message.content.slice(prefix.length).trim().split(' ')

  const voiceChannel = message.member.voice.channel;
  if (!voiceChannel) {
    return message.channel.send({ content: "You are not in a voice channel! Please join one and play a song using `;play`! If you think this is an error please report it immediately!" }).catch((O_o) => { });
  }
  try {
    const string = args.join(' ')
    if (!string) {
      const embed = {
          "description": "Seems to get an error here\nTry again but put in a search query",
      };
      return message.channel.send({ embeds: [embed] });
    }
    return distube.play(message.member.voice.channel, string, {
      member: message.member,
      textChannel: message.channel,
      message
    }).catch((O_o) => { 
      message.channel.send({ content: 'An error encountered while playing `song`! Please report this to the developers as soon as you can! Make sure this is not a permissions issue! Check if the bot has access to join and talk inside of a voice channel!' })
    });
  } catch (e) {
    return console.log(e);
  }
}

以下是所有事件:

distube
  .on("playSong", (queue, song) => {
    const embed = {
      "title": `${song.name}`,
      "url": `${song.url}`,
      "color": 9152956,
      "thumbnail": {
        "url": `${song.thumbnail}`
      },
      "author": {
        "name": "Now Playing",
        "url": "https://discordapp.com",
        "icon_url": client.user.avatarURL()
      },
      "fields": [
        {
          "name": "Views Amount",
          "value": `${song.views}`,
          "inline": true
        },
        {
          "name": "Song Duration",
          "value": `${song.formattedDuration}`,
          "inline": true
        },
        {
          "name": "Requested By",
          "value": `${song.user}`,
          "inline": true
        }
      ]
    };
    queue.textChannel.send({ embeds: [embed] }).catch((O_o) => { });

  })
  .on("addSong", (queue, song) => {

    queue.textChannel.send('Added `' + song.name + '` by `' + song.uploader.name + '` to the queue').catch((O_o) => { });
  })
  .on("playList", (queue, playlist, song) => {
    const embed = {
      "title": `${song.name}`,
      "url": `${song.url}`,
      "color": 9152956,
      "thumbnail": {
        "url": `${song.thumbnail}`
      },
      "author": {
        "name": "Now Playing",
        "url": "https://discordapp.com",
        "icon_url": client.user.avatarURL()
      },
      "fields": [
        {
          "name": "Views Amount",
          "value": `${song.views}`,
          "inline": true
        },
        {
          "name": "Song Duration",
          "value": `${song.formattedDuration}`,
          "inline": true
        },
        {
          "name": "Requested By",
          "value": `${song.user}`,
          "inline": true
        }
      ]
    };
    queue.textChannel.send({ embeds: [embed] }).catch((O_o) => { });
  })

  .on("addList", (queue, playlist) => queue.textChannel.send(
    `Importing ${playlist.songs.length} songs from playlist!`
  ))
  .on('error', (textChannel, e) => {
    console.error(e)
    textChannel.send('An error encountered while playing `song`! Please report this to the developers as soon as you can! Make sure this is not a permissions issue! Check if the bot has access to join and talk inside of a voice channel!').catch((O_o) => { });
  })
  .on('disconnect', queue => {
    queue.textChannel.send({ content: "We have left your voice channel! Hope you enjoyed our music!" }).catch((O_o) => { });
  })
  .on('empty', queue => {
    queue.textChannel.send('The queue is finished! I have left your voice channel! Hope you enjoyed our music!').catch((O_o) => { });
  })
  .on("searchNoResult", (message, query) => message.channel.send({ content: "No result found for `" + query + "`!"}))
  .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 30 seconds to cancel*`
      )
  })
  .on("searchCancel", message => message.channel.send(`Searching canceled`))
  .on("searchInvalidAnswer", message => message.channel.send(`Invalid number of result.`))
  .on("searchDone", () => {})

我曾尝试修改 distube 的设置,但它似乎无法正常工作!

如果需要,这里是 distube 文档:https ://distube.js.org/#/docs/DisTube/stable/general/welcome

4

0 回答 0