首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RuntimeError:托管在数字海洋上的Discord.JS中的内存越界错误

RuntimeError:托管在数字海洋上的Discord.JS中的内存越界错误
EN

Stack Overflow用户
提问于 2021-09-02 05:36:43
回答 1查看 501关注 0票数 0

我使用distube库编写了一个不和谐的音乐机器人,该库工作正常,没有在本地主机或heroku上显示此错误,但当我转到数字海洋时,它开始顺利工作,但过了一段时间,我开始收到与wasm-functionRuntimeError: memory access out of bounds相关的错误。我增加了屏幕截图和下面错误的代码,并提供了我为这个机器人编写的代码。我对wasm函数和内存访问越界错误几乎一无所知,所以如果有人能帮我解决这个问题,将会有很大的帮助。

不和谐机器人代码

代码语言:javascript
复制
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const {
  AutoPoster
} = require('topgg-autoposter')
const DisTube = require('distube'),
  config = {
    prefix: "b.",
  };


AutoPoster("Top.gg TOKEN", client)
  .on('posted', () => {
    console.log('Posted stats to Top.gg!')
  })

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")
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
  if (message.member.voice.channel) {
    distube.play(message, args.join(" "));
  }



  if (command == "loop" || command == "repeat") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      distube.setRepeatMode(message, parseInt(args[0]));
      const exampleEmbed = new Discord.MessageEmbed()
        .setColor('#9966CC')
        .setTitle('Current Song has been Looped!')

      message.channel.send(exampleEmbed);
    }

  }

  if (command == "stop") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      distube.stop(message);
      const exampleEmbed = new Discord.MessageEmbed()
        .setColor('#9966CC')
        .setTitle('Bot has left the voice channel!')

      message.channel.send(exampleEmbed);
    }

  }
  if (command == "skip") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      distube.skip(message);
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      const exampleEmbed = new Discord.MessageEmbed()
        .setColor('#9966CC')
        .setTitle('Song has been skipped!')

      message.channel.send(exampleEmbed);
    }

  }



  if (command == "volume") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      distube.setVolume(message, args[0]);
      const exampleEmbed = new Discord.MessageEmbed()
        .setColor('#9966CC')
        .setTitle(`Volume has been set to ${args[0]}% `)

      message.channel.send(exampleEmbed);
    }

  }

  if (command == "jump") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      distube.jump(message, parseInt(args[0] - 1));
    }

  }


  if (command == "shuffle") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      distube.shuffle(message);
      const exampleEmbed = new Discord.MessageEmbed()
        .setColor('#9966CC')
        .setTitle(`Queue has been shuffled!`)

      message.channel.send(exampleEmbed);
    }

  }

  if (command == "pause") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      distube.pause(message);
      const exampleEmbed = new Discord.MessageEmbed()
        .setColor('#9966CC')
        .setTitle(`Current Song has been paused!`)

      message.channel.send(exampleEmbed);
    }

  }


  if (command == "resume") {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      let queue = distube.getQueue(message);
      if (!queue) return message.channel.send("There is no queue.")
      distube.resume(message);
      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);
    if (!queue) return message.channel.send("There is no queue.")
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Current Queue')
      .setDescription(queue.songs.map((song, id) =>
        `**${id + 1}**) ${song.name} - \`${song.formattedDuration}\``).slice(0, 40).join("\n"))

    message.channel.send(exampleEmbed);
  }

  if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`, `reverse`, `surround`, `earwax`].includes(command)) {
    if (!message.member.voice.channel) {
      message.channel.send("You are not in a voice channel.")
    }
    if (message.member.voice.channel) {
      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) => {
    const exampleEmbed = new Discord.MessageEmbed()
      .setColor('#9966CC')
      .setTitle('Currently Playing')
      .addFields({
        name: 'Song Name',
        value: song.name
      }, {
        name: 'Duration',
        value: song.formattedDuration,
        inline: true
      }, {
        name: 'Requested By',
        value: song.user,
        inline: true
      }, {
        name: 'Status',
        value: status(queue)
      }, )
    message.channel.send(exampleEmbed);
  })

  .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) => {
    if (!message.member.guild.me.hasPermission(["CONNECT"])) return message.channel.send("I don't have the permissions to join the voice channel.")
    if (!message.member.guild.me.hasPermission(["SPEAK"])) return message.channel.send("I don't have the permissions to speak in the voice channel.")
    if (!message.member.guild.me.hasPermission(["SEND_MESSAGES"])) return console.log("I don't have the permissions to send messages.")
    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);
  });


client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler => {
  require(`./handlers/${handler}`)(client, Discord);
})

client.once('ready', () => {
  client.user.setActivity("BlurryBot | b.help");
});



client.login("BOT_TOKEN");

控制台中的错误消息

代码语言:javascript
复制
0|.        |     at Decoder.Transform._read (internal/streams/transform.js:205:10)
0|.        |     at Decoder.Transform._write (internal/streams/transform.js:193:12)
0|.        |     at writeOrBuffer (internal/streams/writable.js:358:12)
0|.        |     at Decoder.Writable.write (internal/streams/writable.js:303:10)
0|.        | RuntimeError: memory access out of bounds
0|.        |     at <anonymous>:wasm-function[268]:0x2177a
0|.        |     at <anonymous>:wasm-function[267]:0x21732
0|.        |     at OpusScriptHandler$_decode [as _decode] (eval at Db (/root/BlurryBot/node_modules/opusscript/build/opusscript_native_wasm.js:1:1), <anonymous>:11:10)
0|.        |     at OpusScript.decode (/root/BlurryBot/node_modules/opusscript/index.js:80:28)
0|.        |     at Decoder._decode (/root/BlurryBot/node_modules/prism-media/src/opus/Opus.js:64:25)
0|.        |     at Decoder._transform (/root/BlurryBot/node_modules/prism-media/src/opus/Opus.js:189:20)
0|.        |     at Decoder.Transform._read (internal/streams/transform.js:205:10)
0|.        |     at Decoder.Transform._write (internal/streams/transform.js:193:12)
0|.        |     at writeOrBuffer (internal/streams/writable.js:358:12)
0|.        |     at Decoder.Writable.write (internal/streams/writable.js:303:10)

不和谐上的错误消息

当我转移到数字海洋时,我才开始收到这个错误,而在此之前它并没有发生。

EN

回答 1

Stack Overflow用户

发布于 2021-09-02 08:48:49

有几件事你可以支配:

  • 确保您的数字海洋环境支持web组装(很可能是因为您说它最初运行得很好,但是如果不考虑这样要求的话:
代码语言:javascript
复制
var encoder = new OpusScript(samplingRate, channels, OpusScript.Application.AUDIO, {
  wasm: false
});
  • 根据我的判断(通过研究控制台中的错误),它主要发生在opusscript依赖项中,您可能希望切换到另一个操作系统引擎(如@discordjs/opus ),其中ytdl核/不和谐播放器是它的替代品,并且完全放弃distube作为依赖项。
  • 如果错误不退出您的流程,并且一切正常运行,则完全抑制和忽略这些错误。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69024680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档