discord bot无法播放音乐流(playStream)(打字稿)

时间:2019-12-30 20:34:34

标签: typescript discord.js

它完美地完成了所有工作,直到应该播放为止(与playStream对齐)。

import { BaseCommand } from "../BaseCommand";
import { Message } from "discord.js";
import { SnowcaloidClient } from "../../client/SnowcaloidClient";
import { getParameters } from "../../utils";
import * as ytdl from "ytdl-core";

export class Play extends BaseCommand {

  constructor(client: SnowcaloidClient) {
    super(client);
    this.name = 'play';
    this.description = 'Plays the requested song. Parameters: song name or url';
  }

  public async run(message: Message): Promise<boolean> {
    var result: boolean = await super.run(message);
    if (result) {
      if (!message.guild.voiceConnection) {
        await this.client.commands.find('join').run(message);
      }
      var params: string = getParameters(message).join(' ');
      if (/^(https:\/\/)?(www\.)?youtu\.?be(.com)?\/(watch\?v=)?[^ ]{11}$/.test(params.trim())) {
        console.log(params);
        message.guild.voiceConnection.playStream(ytdl(params, { filter: 'audioonly' }));
      } else {
        // find
      }
    }
    return result;
  }
}

当我调试它创建的调度程序对象中的内容时,我得到了:

StreamDispatcher {
  _events:
   [Object: null prototype] { end: [Function], error: [Function], speaking: [Function] },
  _eventsCount: 3,
  _maxListeners: undefined,
  _volume: 1,
  player:
   AudioPlayer {
     _events:
      [Object: null prototype] { debug: [Function], error: [Function] },
     _eventsCount: 2,
     _maxListeners: undefined,
     voiceConnection:
      VoiceConnection {
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        voiceManager: [ClientVoiceManager],
        client: [SnowcaloidClient],
        prism: [Prism],
        channel: [VoiceChannel],
        status: 2,
        speaking: false,
        receivers: [],
        authentication: {},
        player: [Circular],
        ssrcMap: Map {},
        sockets: {},
        connectTimeout:
         Timeout {
           _called: false,
           _idleTimeout: 15000,
           _idlePrev: [TimersList],
           _idleNext: [TimersList],
           _idleStart: 5025,
           _onTimeout: [Function],
           _timerArgs: undefined,
           _repeat: null,
           _destroyed: false,
           [Symbol(unrefed)]: false,
           [Symbol(asyncId)]: 348,
           [Symbol(triggerId)]: 0 } },
     prism: Prism { transcoder: [MediaTranscoder] },
     streams: Collection [Map] {},
     currentStream:
      { transcoder: [FfmpegProcess],
        output: [Socket],
        input: [PassThrough],
        dispatcher: [Circular] },
     streamingData:
      { channels: 2,
        count: 0,
        sequence: 0,
        timestamp: 0,
        pausedTime: 0,
        length: 20,
        missed: 0 },
     opusEncoder:
      NodeOpusEngine {
        ctl: [Object],
        samplingRate: 48000,
        channels: 2,
        bitrate: 48,
        options: [Object],
        encoder: OpusEncoder {} } },
  stream:
   Socket {
     connecting: false,
     _hadError: false,
     _handle:
      Pipe {
        onread: [Function: onStreamRead],
        reading: true,
        [Symbol(owner)]: [Circular] },
     _parent: null,
     _host: null,
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: BufferList { head: null, tail: null, length: 0 },
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: false,
        ended: false,
        endEmitted: false,
        reading: true,
        sync: false,
        needReadable: true,
        emittedReadable: false,
        readableListening: true,
        resumeScheduled: false,
        paused: true,
        emitClose: false,
        autoDestroy: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: true,
     _events:
      [Object: null prototype] {
        end: [Array],
        close: [Function],
        error: [Array],
        readable: [Function] },
     _eventsCount: 4,
     _maxListeners: undefined,
     _writableState:
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        destroyed: false,
        decodeStrings: false,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: true,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        emitClose: false,
        autoDestroy: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: false,
     allowHalfOpen: false,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server: null,
     _server: null,
     [Symbol(asyncId)]: 360,
     [Symbol(lastWriteQueueSize)]: 0,
     [Symbol(timeout)]: null,
     [Symbol(kBytesRead)]: 0,
     [Symbol(kBytesWritten)]: 0 },
  streamOptions: { seek: 0, volume: 1, passes: 1, opus: undefined },
  paused: false,
  destroyed: false,
  _opus: undefined }

我觉得可能是因为Readablestate.paused:true。我找不到其他线索。

我也尝试等待机器人开始玩,但即使20分钟后它也什么也没做。还尝试使用npm i --save ytdl-core安装ytdl-core软件包(因为我在here上找到了该软件包),但也没有用。我的所有软件包都是最新的,根据npm的介绍,我没有丢失任何依赖项。

更新:我尝试在“启动”事件上记录调度程序,但从未发生。

0 个答案:

没有答案