0

我使用 distube NPM 模块为我的不和谐机器人制作了音乐命令。我面临的问题是有时(这并不总是发生)并且它不是特定的命令,它随机发生在 distube 下的任何音乐命令中。

这是我面临的错误。

26.08 00:11:45 [Bot] Startup wasm://wasm/0010d1fa:1
26.08 00:11:45 [Bot] Startup ^
26.08 00:11:45 [Bot] Startup RuntimeError: memory access out of bounds
26.08 00:11:45 [Bot] Startup at <anonymous>:wasm-function[268]:0x2177a
26.08 00:11:45 [Bot] Startup at <anonymous>:wasm-function[267]:0x21732
26.08 00:11:45 [Bot] Startup at OpusScriptHandler$_decode [as _decode] (eval at Db (/node_modules/opusscript/build/opusscript_native_wasm.js:1:1), <anonymous>:11:10)
26.08 00:11:45 [Bot] Startup at OpusScript.decode (/node_modules/opusscript/index.js:80:28)
26.08 00:11:45 [Bot] Startup at Decoder._decode (/node_modules/prism-media/src/opus/Opus.js:64:25)
26.08 00:11:45 [Bot] Startup at Decoder._transform (/node_modules/prism-media/src/opus/Opus.js:189:20)
26.08 00:11:45 [Bot] Startup at Decoder.Transform._read (internal/streams/transform.js:205:10)
26.08 00:11:45 [Bot] Startup at Decoder.Transform._write (internal/streams/transform.js:193:12)
26.08 00:11:45 [Bot] Startup at writeOrBuffer (internal/streams/writable.js:358:12)
26.08 00:11:45 [Bot] Startup at Decoder.Writable.write (internal/streams/writable.js:303:10)
26.08 00:11:45 [Bot] Startup at Encoder.ondata (internal/streams/readable.js:719:22)
26.08 00:11:45 [Bot] Startup at Encoder.emit (events.js:315:20)
26.08 00:11:45 [Bot] Startup at addChunk (internal/streams/readable.js:309:12)
26.08 00:11:45 [Bot] Startup at readableAddChunk (internal/streams/readable.js:284:9)
26.08 00:11:45 [Bot] Startup at Encoder.Readable.push (internal/streams/readable.js:223:10)
26.08 00:11:45 [Bot] Startup at Encoder.Transform.push (internal/streams/transform.js:166:32)
26.08 00:11:45 [Bot] Startup npm ERR! code ELIFECYCLE
26.08 00:11:45 [Bot] Startup npm ERR! errno 1
26.08 00:11:45 [Bot] Startup npm ERR! index@1.0.0 start: `node index.js`
26.08 00:11:45 [Bot] Startup npm ERR! Exit status 1
26.08 00:11:45 [Bot] Startup npm ERR! 
26.08 00:11:45 [Bot] Startup npm ERR! Failed at the index@1.0.0 start script.
26.08 00:11:45 [Bot] Startup npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
26.08 00:11:45 [Bot] Startup npm ERR! A complete log of this run can be found in:
26.08 00:11:45 [Bot] Startup npm ERR!     /tmp/npm/_logs/2021-08-26T04_11_45_714Z-debug.log
26.08 00:11:46 [PebbleHost] Server shut down (running)
26.08 00:11:46 [PebbleHost] Server stopped
26.08 00:11:58 [PebbleHost] Received start command
26.08 00:11:58 [PebbleHost] Starting server!

这是音乐命令的代码。

const DisTube = require('distube'),
  config = {
    prefix: "x",
  };

// Create a new DisTube
const distube = new DisTube(client, {
  searchSongs: true,
  emitNewSongOnly: true
});

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

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 (["repeat", "loop"].includes(command))
    distube.setRepeatMode(message, parseInt(args[0]));

  if (command == "loop" || command == "repeat") {
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Current Song has been Looped!')

    message.channel.send(exampleEmbed);
  }

  if (command == "stop") {
    distube.stop(message);
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Bot has left the voice channel!')

    message.channel.send(exampleEmbed);
  }
  if (command == "skip") {
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Song has been skipped!')

    message.channel.send(exampleEmbed);
  }

  if (command == "skip")
    distube.skip(message);

  if (command == "volume")
    distube.setVolume(message, args[0]);
  if (command == "volume") {
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle(`Volume has been set to ${args[0]}% `)

    message.channel.send(exampleEmbed);
  }

  if (command == "jump")
    distube.jump(message, parseInt(args[0] - 1));

  if (command == "shuffle")
    distube.shuffle(message);

  if (command == "shuffle") {
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle(`Queue has been shuffled!`)

    message.channel.send(exampleEmbed);
  }

  if (command == "pause")
    distube.pause(message);


  if (command == "pause") {
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle(`Current Song has been paused!`)

    message.channel.send(exampleEmbed);
  }


  if (command == "resume")
    distube.resume(message);

  if (command == "resume") {
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle(`Current Song has been resumed!`)

    message.channel.send(exampleEmbed);
  }

  if (command == "queue") {
    let queue = distube.getQueue(message);
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Current Queue')
      .setDescription(queue.songs.map((song, id) =>
        `**${id + 1}**) ${song.name} - \`${song.formattedDuration}\``).slice(0, 10).join("\n"))

    message.channel.send(exampleEmbed);
  }

  if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`, `reverse`, `surround`, `earwax`].includes(command)) {
    let filter = distube.setFilter(message, command);
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Current Filter')
      .setDescription(filter || 'Off')

    message.channel.send(exampleEmbed);
  }
});

// Queue status template
const status = (queue) => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filter || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode == 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``;

// DisTube event listeners, more in the documentation page
distube

  .on("playSong", (message, queue, song) =>
    message.channel.send(
      `Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}\n${status(queue)}`
    ))
  .on("addSong", (message, queue, song) => message.channel.send(
    `Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`
  ))
  .on("playList", (message, queue, playlist, song) => message.channel.send(
    `Play \`${playlist.name}\` playlist (${playlist.songs.length} songs).\nRequested by: ${song.user}\nNow playing \`${song.name}\` - \`${song.formattedDuration}\`\n${status(queue)}`
  ))
  .on("addList", (message, queue, playlist) => message.channel.send(
    `Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to queue\n${status(queue)}`
  ))
  // DisTubeOptions.searchSongs = true
  .on("searchResult", (message, result) => {
    let i = 0;
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Choose an option from below')
      .setDescription(`${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")}\n\n*Enter anything else or wait 60 seconds to cancel*`)
    message.channel.send(exampleEmbed);

  })
  // 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);
  });
4

2 回答 2

0

由于opusscript包裹。卸载它并安装@discordjs/opus

npm uninstall opusscript
npm install @discordjs/opus
于 2022-02-11T17:41:18.030 回答
0

我不太确定我的答案,但您似乎内存不足,如第 3 行所示,

26.08 00:11:45 [Bot] Startup RuntimeError: memory access out of bounds

因此,也许尝试获得一个具有更多内存的更好的主机来处理您的机器人!

于 2021-08-26T10:33:23.423 回答