Пытаясь закодировать бота disord musi c, и я получаю не могу преобразовать "ноль" в int - PullRequest
0 голосов
/ 25 марта 2020

Я отладил процесс и понял, что он имеет отношение к opusscript_native_wasm. js, он присоединяется и уходит из канала просто отлично, но когда дело доходит до фактического прослушивания песни, я не могу ее услышать. Когда он присоединяется к каналу, окружающая область даже загорается зеленым, как будто он издает звук, лично я его просто не слышу.

Вот код:

const {Client, MessageEmbed} = require('discord.js');
const bot = new Client();

const ytdl = require("ytdl-core");

const queue = new Map();

const token = 'HIDDEN FOR PRIVACY';

const PREFIX = '!';

var version = "1.0.0"

bot.on('ready', () =>{
    console.log('Krum has started');
    bot.user.setActivity(`!help | Krums Bot`);
})



//ATTEMPT AT PLAYING MUSIC--LOOKING FOR FIX--NOT WORKING CURRENTLY
bot.on("message", async message => {

  if (message.author.bot) return;
    if (!message.content.startsWith(PREFIX)) return;

    const serverQueue = queue.get(message.guild.id);

    if (message.content.startsWith(`${PREFIX}play`)) {
      execute(message, serverQueue);
      return;
    } else if (message.content.startsWith(`${PREFIX}skip`)) {
      skip(message, serverQueue);
      return;
    } else if (message.content.startsWith(`${PREFIX}stop`)) {
      stop(message, serverQueue);
      return;
    } else {
      message.channel.send("You need to enter a valid command!");
    }
  });

  async function execute(message, serverQueue) {
    const args = message.content.split(" ");

    const voiceChannel = message.member.voice.channel;
    if (!voiceChannel)
      return message.channel.send(
        "You need to be in a voice channel to play music!"
      );
    const permissions = voiceChannel.permissionsFor(message.client.user);
    if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
      return message.channel.send(
        "I need the permissions to join and speak in your voice channel!"
      );
    }

    const songInfo = await ytdl.getInfo(args[1]);
    const song = {
      title: songInfo.title,
      url: songInfo.video_url
    };

    if (!serverQueue) {
      const queueContruct = {
        textChannel: message.channel,
        voiceChannel: voiceChannel,
        connection: null,
        songs: [],
        volume: 5,
        playing: true
      };

      queue.set(message.guild.id, queueContruct);

      queueContruct.songs.push(song);

      try {
        var connection = await voiceChannel.join();
        queueContruct.connection = connection;
        play(message.guild, queueContruct.songs[0]);
      } catch (err) {
        console.log(err);
        queue.delete(message.guild.id);
        return message.channel.send(err);
      }
    } else {
      serverQueue.songs.push(song);
      return message.channel.send(`${song.title} has been added to the queue!`);
    }
  }

  function skip(message, serverQueue) {
    if (!message.member.voice.channel)
      return message.channel.send(
        "You have to be in a voice channel to stop the music!"
      );
    if (!serverQueue)
      return message.channel.send("There is no song that I could skip!");
    serverQueue.connection.dispatcher.end();
  }

  function stop(message, serverQueue) {
    if (!message.member.voice.channel)
      return message.channel.send(
        "You have to be in a voice channel to stop the music!"
      );
    serverQueue.songs = [];
    serverQueue.connection.dispatcher.end();
  }

  function play(guild, song) {
    const serverQueue = queue.get(guild.id);
    if (!song) {
      serverQueue.voiceChannel.leave();
      queue.delete(guild.id);
      return;
    }

    const dispatcher = serverQueue.connection
      .play(ytdl(song.url))
      .on("finish", () => {
        serverQueue.songs.shift();
        play(guild, serverQueue.songs[0]);
      })
      .on("error", error => console.error(error));
    dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
    serverQueue.textChannel.send(`Start playing: **${song.title}**`);
  }

ОШИБКА:

TypeError: Невозможно преобразовать «ноль» в int TypeError: Невозможно преобразовать «ноль» в int

C: \ Users \ Пользователь \ Рабочий стол \ Discord Bot \ node_modules \ opusscript \ build \ opusscript_native_wasm. js: 8 var Module = typeof Module! == "undefined"? Module: {}; var moduleOverrides = {}; ключ var; for (ключ в модуле) {if (Module.hasOwnProperty (key)) { moduleOverrides [ключ] = Модуль [ключ]}} Модуль [ "аргументы"] = []; Модуль [ "Thisprogram"] = "./ this.program " модуль [" бросить курить"] = функция (состояние, toThrow) { throw toThrow}; Модуль ["preRun"] = []; Модуль ["postRun"] = []; var ENVIRONMENT_IS_WEB = false; var ENVIRONMENT_IS_WORKER = false; var ENVIRONMENT_IS_NODE = false; var ENVIRONMENT_HAS_NODE = false; var ENVIR = false; var ENVIRVS = false; var ENVIR = false; var_VIR_VER = typeof window === "object"; ENVIRONMENT_IS_WORKER = typeof importScripts === "function"; ENVIRONMENT_HAS_NODE = typeof p rocess === "объект" && TYPEOF process.versions === "объект" && TypeOf process.versions.node === "строка"; ENVIRONMENT_IS_NODE = ENVIRONMENT_HAS_NODE && && ENVIRONMENT_IS_WEB ENVIRONMENT_IS_WORKER;!!!! ENVIRONMENT_IS_SHELL = ENVIRONMENT_IS_WEB && && ENVIRONMENT_IS_NODE ENVIRONMENT_IS_WORKER; вар scriptDirectory = ""; функция locateFile (path) {if (Модуль прерывается (TypeError: Невозможно преобразовать "null" в int). Сборка с -s ASSERTIONS = 1 для получения дополнительной информации. (Используйте node --trace-uncaught ..., чтобы показать, где было сгенерировано исключение)

...