Discord musi c бот - проблема с пропуском песни - PullRequest
1 голос
/ 10 июля 2020

У меня проблема при пропуске песни. При передаче! Skip бот зависает без каких-либо ошибок.

Это модуль, принимающий два параметра, то есть msg send как все сообщение и agrs, который представляет собой массив, содержащий переданную строку, преобразованную в массив. например:! play url даст url в args с индексом 0.

Передача! skip не выдаст ошибок, но после! skip, если я попробую! stop, выдает ошибку как:

D:\nodeCode\discord\node_modules\opusscript\build\opusscript_native_wasm.js:8
var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module["arguments"]=[];Module["thisProgram"]="./this.program";Module["quit"]=function(status,toThrow){throw toThrow};Module["preRun"]=[];Module["postRun"]=[];var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_HAS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]
abort(TypeError: Cannot read property 'end' of null). Build with -s ASSERTIONS=1 for more info.
npm ERR! code ELIFECYCLE
npm ERR! errno 7
npm ERR! discord@1.0.0 start: `node src/index.js`
npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the discord@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jaspr\AppData\Roaming\npm-cache\_logs\2020-07-10T06_44_56_465Z-debug.log
const ytdl = require('ytdl-core');
const queue = new Map();


const play = (guild, song) => {
    const serverQueue = queue.get(guild.id);
    console.log(serverQueue.songs);
    if (!song) {
        serverQueue.voiceChannel.leave();
        queue.delete(guild.id);
        return;
    }
    const dispatcher = serverQueue.connection
        .play(ytdl(song.url, { filter: "audioonly" }))
        .on('end', () => {
            dispatcher = null;
            serverQueue.songs.shift();
            play(guild, serverQueue.songs[0]);
        })
        .on('error', error => console.error(error));
    dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
    serverQueue.textChannel.send(`playing: **${song.title}**`);
};

const skip = (msg, serverQueue) => {
    if (!serverQueue)
        return msg.channel.send("There is no song to skip");
    serverQueue.connection.dispatcher.end();
}

const stop = (msg, serverQueue) => {
    serverQueue.songs = [];
    serverQueue.connection.dispatcher.end();
    serverQueue.voiceChannel.leave();
    queue.delete(serverQueue.voiceChannel.guild.id);

}

module.exports = async (msg, args) => {
    const serverQueue = queue.get(msg.guild.id);
    const voiceChannel = msg.member.voice.channel;
    if (!voiceChannel) return msg.channel.send(`you need to be in voice channel ${msg.author.username}`);
    const permissions = voiceChannel.permissionsFor(msg.client.user);
    if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
        return msg.channel.send(
            'I need the permissions to join and speak in your voice channel!'
        );
    }
    if (msg.content.toLowerCase() === '!skip') return skip(msg, serverQueue);
    if (msg.content.toLowerCase() === '!stop') return stop(msg, serverQueue);
    const songInfo = await ytdl.getInfo(args[0]);
    const song = {
        title: songInfo.videoDetails.title,
        url: songInfo.videoDetails.video_url
    };



    if (!serverQueue) {
        const queueContract = {
            textChannel: msg.channel,
            voiceChannel: voiceChannel,
            connection: null,
            songs: [],
            volume: 5,
            playing: true,
        };
        queue.set(msg.guild.id, queueContract);
        queueContract.songs.push(song);
        try {
            let connection = await voiceChannel.join();
            queueContract.connection = connection;
            play(msg.guild, queueContract.songs[0]);
        } catch (err) {
            console.log(err);
            queue.delete(msg.guild.id);
            return msg.channel.send('something went wrong');
        }
    } else {
        serverQueue.songs.push(song);
        console.log(serverQueue.songs);
        return msg.channel.send(`${song.title} has been added to the queue!`);
    }
};
...