【问题标题】:Discord py - creating my own music bot - error codeDiscord py - 创建我自己的音乐机器人 - 错误代码
【发布时间】:2020-10-29 21:42:30
【问题描述】:

大家好,

我现在正在尝试创建自己的音乐机器人。

但是我有一些问题,希望你能帮助我:)

我的代码是什么样的:

from discord import Game, Intents
from discord.ext import commands
from os import environ, listdir

from pafy import new
from discord import FFmpegPCMAudio

import asyncio
import urllib.parse, urllib.request, re

intents = Intents.all()
client = commands.Bot(command_prefix='?', intents=intents)

@client.event
async def on_ready():
    print(f'Bot is ready to go!')

@client.command(pass_context=True)
async def play(ctx, url):
    ffmpeg_opts = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}

    if not ctx.message.author.voice:
        await ctx.send("**Please connect to a voice channel!**")
        return
    
    channel = ctx.author.voice.channel
    voice = await channel.connect()
        
    await ctx.send(f':pushpin: Music bot connected to {channel}\n:mag_right: **Searching for** ``' + url + "``")
    video = new(url)
    audio = video.getbestaudio().url
    voice.play(FFmpegPCMAudio(audio, **ffmpeg_opts))
    voice.is_playing()

@client.command()
async def join(ctx):

    if not ctx.message.author.voice:
        await ctx.send("You are not connected to a voice channel!")
        return
    else:
        channel = ctx.message.author.voice.channel
        await ctx.send(f'Connected to ``{channel}``')

    await channel.connect()

@client.command()
async def leave(ctx):
    voice_client = ctx.message.guild.voice_client
    user = ctx.message.author.mention
    await voice_client.disconnect()
    await ctx.send(f'Disconnected from {user}')

client.run(TOKEN)

所以现在我遇到了两个主要问题:

  • Youtube-dl 不再受支持,所以我切换到 pafy

但我仍然收到此错误

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OSError: ERROR: Unable to extract JS player URL; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

有趣的是,我每次使用机器人时都不会收到此错误:(

第二个问题是每次我想更改歌曲时都需要断开机器人的连接。

如何使用队列之类的东西? - 我不想每次都断开机器人...

谢谢!

【问题讨论】:

    标签: python discord discord.py discord.py-rewrite


    【解决方案1】:

    youtube-dl 不再是一个东西。作为替代方案,我建议将lavalinkwavelink 库一起使用。它有更多的功能。

    【讨论】:

      【解决方案2】:

      首先卸载youtube-dl:

      pip uninstall youtube-dl
      

      现在我是怎么做到的:

      Github 上有一个新的 Youtube-dl

      如果您在 Windows 上使用此命令安装它:

      pip install -U git+https://github.com/l1ving/youtube-dl
      

      你已经完成了 - 有时我会收到类似的错误

      错误:无法提取 JS 播放器 URL

      但如果发生这种情况,您只需要重新启动机器人,它就会再次工作

      【讨论】:

        猜你喜欢
        • 2018-07-24
        • 2022-01-21
        • 2021-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-27
        • 2020-06-20
        • 2019-04-30
        相关资源
        最近更新 更多