YouTube-DL和FFMPEG

发布于 2025-02-10 07:53:28 字数 3844 浏览 1 评论 0原文

我已经用Discord.py制作了一个音乐机器人,但是我得到了此信息,它不再起作用错误[YouTube] qxydbvb8soy:下载WebPage 985104597242773505 [20222-06-25 076-25 07:45:51] .Player:准备终止FFMPEG流程37580。[2022-06-25 07:45:51] [info] discord.player.player:ffmpeg Process 37580尚未终止。 1。的返回代码终止

import discord
import os
import asyncio
import youtube_dl
from discord import *

token = "token is here"
prefix = "j!"
blocked_words = ["blocked words are here"]

voice_clients = {}

yt_dl_opts = {'format': 'bestaudio/best'}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)

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

intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)


programmer_role = "987018590152699964"
            


@client.event
async def on_ready():
    print(f"Bot logged in as {client.user}")

@client.event
async def on_message(msg):
    if msg.author != client.user:
        if msg.content.lower().startswith(f"{prefix}info"):
            await msg.channel.send(f"Hi, Im JoksysBot Made By Joksy!")

        for text in blocked_words:
            if text in str(msg.content.lower()):
                await msg.delete()
                await msg.channel.send("Hey, Dont Say That!")
                return
        if msg.content.startswith(f"{prefix}play"):

            try:
                voice_client = await msg.author.voice.channel.connect()
                voice_clients[voice_client.guild.id] = voice_client
            except:
                print("error")

            try:
                url = msg.content.split()[1]

                loop = asyncio.get_event_loop()
                data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))

                song = data['url']
                player = discord.FFmpegPCMAudio(song, **ffmpeg_options, executable="C:\\Users\\jonas\\Documents\\ffmpeg-2022-06-16-git-5242ede48d-full_build\\ffmpeg-2022-06-16-git-5242ede48d-full_build\\bin\\ffmpeg.exe")

                voice_clients[msg.guild.id].play(player)

            except Exception as err:
                print(err)

        if msg.content.startswith(f"{prefix}pause"):
            try:
                voice_clients[msg.guild.id].pause()
            except Exception as err:
                print(err)

        if msg.content.startswith(f"{prefix}resume"):
            try:
                voice_clients[msg.guild.id].resume()
            except Exception as err:
                print(err)

        if msg.content.startswith(f"{prefix}stop"):
            try:
                voice_clients[msg.guild.id].stop()
                await voice_clients[msg.guild.id].disconnect()
            except Exception as err:
                print(err)

client.run(token)

等待终止... [2022-06-25 07:45:51] [info] discord.player:ffmpeg Process 37580应该以 我的bot中的其他代码像!info命令一样工作正常,因此YouTube-DL或FFMPEG必须是错误。但是再说一次,它不会首先加入语音调用,因此可能是错误。我在路径上添加了ffmpeg,但我仍然在这里写下了路径player = discord.ffmpegpcmaudio(song,** ffmpeg_options,eperutable,eperutable =“ c:\\ users \\ uders \\ jonas \ \\ document -16-GIT-5242EDE48D-FULL_BUILD \\ FFMPEG-2022-06-16-GIT-5242EDE48D-FULL_BUILD \\ bin \\ ffmpeg.exe”)。 i followed this tutorial for the bot https://www.youtube.com/watch ?v = q8wxin72h50&amp; t = 1040s 我做了他所做的一切,但它没有起作用。我的discord.py版本是2.0.0我的python版本是3.10.5,而我的youtube_dl版本是2021.12.17我的ffmpeg下载是<代码> FFMPEG-2022-06-16-GIT-5242EDE48D-FULL_BUILD 。我在discord.py 1.73上对其进行了测试,并且效果很好。这是在Intellij中,尽管我的主要程序是在Visual Studio Code中,但是我看不到它带来了任何巨大的差异,因此可能是使程序无法正常工作的目的。我看不到代码中的任何错误,但我对不和谐是新的错误。 py,youtube_dl和ffmpeg的东西,所以除非Visual Studio代码向我展示了我做错了什么,否则我不会注意到。但是我做错了什么,我该如何解决呢?

i have made a music bot with discord.py, but i get this info thing and it doesnt work anymoreerror [youtube] QxYdBvB8sOY: Downloading webpage 985104597242773505 [2022-06-25 07:45:51] [INFO ] discord.player: Preparing to terminate ffmpeg process 37580. [2022-06-25 07:45:51] [INFO ] discord.player: ffmpeg process 37580 has not terminated. Waiting to terminate... [2022-06-25 07:45:51] [INFO ] discord.player: ffmpeg process 37580 should have terminated with a return code of 1. this is my code

import discord
import os
import asyncio
import youtube_dl
from discord import *

token = "token is here"
prefix = "j!"
blocked_words = ["blocked words are here"]

voice_clients = {}

yt_dl_opts = {'format': 'bestaudio/best'}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)

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

intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)


programmer_role = "987018590152699964"
            


@client.event
async def on_ready():
    print(f"Bot logged in as {client.user}")

@client.event
async def on_message(msg):
    if msg.author != client.user:
        if msg.content.lower().startswith(f"{prefix}info"):
            await msg.channel.send(f"Hi, Im JoksysBot Made By Joksy!")

        for text in blocked_words:
            if text in str(msg.content.lower()):
                await msg.delete()
                await msg.channel.send("Hey, Dont Say That!")
                return
        if msg.content.startswith(f"{prefix}play"):

            try:
                voice_client = await msg.author.voice.channel.connect()
                voice_clients[voice_client.guild.id] = voice_client
            except:
                print("error")

            try:
                url = msg.content.split()[1]

                loop = asyncio.get_event_loop()
                data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))

                song = data['url']
                player = discord.FFmpegPCMAudio(song, **ffmpeg_options, executable="C:\\Users\\jonas\\Documents\\ffmpeg-2022-06-16-git-5242ede48d-full_build\\ffmpeg-2022-06-16-git-5242ede48d-full_build\\bin\\ffmpeg.exe")

                voice_clients[msg.guild.id].play(player)

            except Exception as err:
                print(err)

        if msg.content.startswith(f"{prefix}pause"):
            try:
                voice_clients[msg.guild.id].pause()
            except Exception as err:
                print(err)

        if msg.content.startswith(f"{prefix}resume"):
            try:
                voice_clients[msg.guild.id].resume()
            except Exception as err:
                print(err)

        if msg.content.startswith(f"{prefix}stop"):
            try:
                voice_clients[msg.guild.id].stop()
                await voice_clients[msg.guild.id].disconnect()
            except Exception as err:
                print(err)

client.run(token)

its weird since all the other code in my bot works fine like the !info command, so it must be an error with either youtube-dl or ffmpeg. But then again it doesnt join the voice call in the first place so that might be the error. i added ffmpeg to path but i still wrote the path to it here player = discord.FFmpegPCMAudio(song, **ffmpeg_options, executable="C:\\Users\\jonas\\Documents\\ffmpeg-2022-06-16-git-5242ede48d-full_build\\ffmpeg-2022-06-16-git-5242ede48d-full_build\\bin\\ffmpeg.exe"). i followed this tutorial for the bot https://www.youtube.com/watch?v=Q8wxin72h50&t=1040s i did everything he did but it didnt work. My discord.py version is 2.0.0 my Python version is 3.10.5 and my youtube_dl version is 2021.12.17 my ffmpeg download is ffmpeg-2022-06-16-git-5242ede48d-full_build. I tested it on discord.py 1.73 and it worked fine. This was in intellij though whilst my main program is in Visual Studio Code but i couldnt see it making any big difference so it could be the intents that makes the program not work.I couldnt see any mistakes in the code but im new to discord.py, youtube_dl and ffmpeg stuff so unless visual studio code showed me what i did wrong, i wouldnt notice. But what did i do wrong and how can i fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情 2025-02-17 07:53:28

因此,对于任何在这里有这个问题的人,您要去:所以问题是连接到语音通话。 确保您有这些意图

intents = discord.Intents.default()
intents.message_content = True
intents.voice_states = True

如果它仍然不起作用请确保已安装 pynacl已安装。您可以在终端中使用此代码pip install pynacl 进行此操作,但是您需要为此安装python 。那应该是修复

So for anybody having this issue here ya go: So the issue was connecting to the voice call. Make sure you have these intents

intents = discord.Intents.default()
intents.message_content = True
intents.voice_states = True

if it still doesnt work make sure you have PyNaCl installed. you can do it in a terminal with this code pip install pynacl you need to have python installed for this though. and that should be the fix

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文