不和谐音乐机器人队列

时间:2020-03-31 01:27:44

标签: discord.py

我正在使用Python 3.7,Discord.py 1.3.2

import discord
import re
import asyncio
import random
import openpyxl
import datetime
import pytz
import youtube_dl
import os

youtube_dl.utils.bug_reports_message = lambda: ''


ytdl_format_options = {
    'format': 'bestaudio/best',
    'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
    'restrictfilenames': True,
    'noplaylist': True,
    'nocheckcertificate': True,
    'ignoreerrors': False,
    'logtostderr': False,
    'quiet': True,
    'no_warnings': True,
    'default_search': 'auto',
    'source_address': '0.0.0.0' # bind to ipv4 since ipv6 addresses cause issues sometimes
}

ffmpeg_options = {
    'options': '-vn'
}

ytdl = youtube_dl.YoutubeDL(ytdl_format_options)


class YTDLSource(discord.PCMVolumeTransformer):
    def __init__(self, source, *, data, volume=0.2):
        super().__init__(source, volume)

        self.data = data

        self.title = data.get('title')
        self.url = data.get('url')

    @classmethod
    async def from_url(cls, url, *, loop=None, stream=False):
        loop = loop or asyncio.get_event_loop()
        data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))

        if 'entries' in data:
            data = data['entries'][0]

        filename = data['url'] if stream else ytdl.prepare_filename(data)
        return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)    

client = discord.Client()
que = {}
playerlist = {}
playlist = list()

def queue(id):
    if que[id] != []:
        player = que[id].pop(0)
        playerlist[id] = player
        del playlist[0]
        player.start()

@client.event
async def on_message(message):
    if message.content.lower().startswith("-mqueue"):
        msg = message.content.split(" ")
        url = message.content.replace("-mqueue ", '')
        guild = message.guild
        voice_client = guild.voice_client
        player = await YTDLSource.from_url(url)
        emb = discord.Embed(title=None, description=f"Now Playing {player.title}" + "** [" + "<@" + str(message.author.id) + ">" + "]**", color=0x049e46)
        await message.channel.send(content=None, embed=emb)
        if guild.id in que:
            que[guild.id].append(player)
        else:
            que[guild.id] = [player]

错误:

[matroska,webm @ 000001ae3f348700]文件在pos提前结束。 267761(0x415f1)

我想在输入中将que保存为-mqueue,然后在用-mplay运行的歌曲结束时播放注册为que的歌曲。
有谁知道该怎么做,甚至不知道其他解决方案?

0 个答案:

没有答案