播放列表播放错误。Discordpy。Youtubedl。
创始人
2024-12-23 08:30:21
0

此问题的常见原因是与Youtube dl库的版本问题有关。尝试升级或降级此库版本,以便与Discord py库兼容。以下是一个示例代码片段,显示如何在Discord.py中使用最新版本的Youtube dl:

import discord
from discord.ext import commands
import youtube_dl

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

class Music(commands.Cog):
    def __init__(self, client):
        self.client = client

        self.voice = None
        self.queue = []

    async def join_voice_channel(self, ctx):
        if ctx.author.voice:
            self.voice = await ctx.author.voice.channel.connect()
        else:
            await ctx.send("You need to be in a voice channel to use this command.")

    @commands.command()
    async def play(self, ctx, *, url):
        await self.join_voice_channel(ctx)

        player = await YTDLSource.from_url(url, loop=self.client.loop, stream=True, ytdl_options=ytdl_options)
        self.queue.append(player)

        if not self.voice.is_playing():
            await self.play_next()

    async def play_next(self):
        if len(self.queue) > 0:
            player = self.queue.pop(0)
            self.voice.play(player, after=lambda e: print(f'Player error: {e}') if e else None)
        else:
            await self.voice.disconnect()

client = commands.Bot(command_prefix='!', case_insensitive=True)
client.add_cog(Music(client))
client.run('token')

此代码片段使用了discord.py和youtube_dl库,以创建一个可以播放从YouTube链接获取

相关内容

热门资讯

二分钟脚本免费!epoker底... 二分钟脚本免费!epoker底牌透视,红龙poker有辅助吗,详细教程(有挂详情)1、这是跨平台的e...
5分钟透视挂!德普之星辅助软件... 5分钟透视挂!德普之星辅助软件(透视辅助软件)详细辅助教程(竟然教程)一、德普之星辅助软件软件透明挂...
3分钟线上大神!epoker透... 3分钟线上大神!epoker透视,哈糖大菠萝有挂吗5个常用方法,详细教程(有挂详情);运epoker...
二分钟透视软件!德扑圈透视,德... 二分钟透视软件!德扑圈透视,德扑圈透视挂,详细教程(有挂软件);1、下载好德扑圈透视挂辅助软件之后点...
五分钟开辅助!德扑圈透视,德普... 五分钟开辅助!德扑圈透视,德普辅助器辅助器怎么用,详细教程(有挂秘籍)德扑圈透视辅助器中分为三种模型...
1分钟开挂教程!werplan... 1分钟开挂教程!werplan怎么作弊,竞技联盟透视,详细教程(有挂透视);1、任何竞技联盟透视ai...
二分钟方法!拱趴游戏破解器,p... 二分钟方法!拱趴游戏破解器,pokemmo辅助工具,详细教程(有挂软件);1、拱趴游戏破解器ai机器...
九分钟辅助器app!德普之星透... 九分钟辅助器app!德普之星透视辅助软件是真的吗(透视辅助)详细辅助模拟器(本来模拟器);1、每一步...
1分钟辅助软件!德普之星辅助工... 1分钟辅助软件!德普之星辅助工具如何打开(透视辅助软件)详细辅助挂(都是挂)1、构建自己的辅助插件;...
一分钟正品!pokemmo手机... 一分钟正品!pokemmo手机版透视脚本(透视脚本辅助器)详细辅助挂(原来挂);1、构建自己的pok...