python 简单的discord.pymp3机器人不播放音乐

p5cysglq  于 2023-04-19  发布在  Python
关注(0)|答案(3)|浏览(115)

不和谐机器人dosent播放任何类型的音乐,无论是我的还是其他机器人的代码工作,他只是dosent播放音乐。idk也许我只是愚蠢,但它确实工作为什么

import discord
import time
import os
from discord.ext import commands

BOT_TOKEN = "" # put token here

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

bot = commands.Bot(command_prefix=";;", intents = intentss)

OPUS_LIBS = ['libopus-0.x86.dll', 'libopus-0.x64.dll', 'libopus-0.dll', 'libopus.so.0', 'libopus.0.dylib']

@bot.command()
async def join(ctx):
    channelVC = ctx.author.voice.channel
    await channelVC.connect()

@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()

@bot.command()
async def play(ctx):
    voice = ctx.guild.voice_client
    mloc = 'C:/Users/Lukas/Desktop/Bot Bethoven/Youtube/test.mp3'
    voice.play(discord.FFmpegPCMAudio(executable = "C:/ffmpeg/bin/ffmpeg.exe", source = mloc))

bot.run(BOT_TOKEN)

它只是给予错误代码:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Not connected to voice.
INFO     discord.player ffmpeg process 22896 has not terminated. Waiting to terminate...
INFO     discord.player ffmpeg process 22896 should have terminated with a return code of 1.

有趣的事情,当我把加入和播放在同一个命令它dosent显示未连接到语音错误,实际上它dosent显示任何东西,既不播放mp3文件
我尝试重新安装:PyNaCl,FFmpeg,Visual Code,updating python. nothing helps.这个问题开始后,我做了1个月的休息,从编码机器人,在此之前,它工作正常。
我想问题是我的电脑的东西,也许路径或dosent工作的东西(因为它工作了一个月前,我没有做任何代码),我试着检查,但一切似乎正常,

qv7cva1a

qv7cva1a1#

对我来说,这是与不同版本的python的东西,我用,他们做了一些事情,以eatch其他soo它刚刚打破
对我来说,修复是删除与Python相关的所有内容(包括模块)并重新安装它。

h43kikqp

h43kikqp2#

我觉得这句台词之后:

voice.play(discord.FFmpegPCMAudio(executable = "C:/ffmpeg/bin/ffmpeg.exe", source = mloc))

Python完成了这个过程,所以不能正常执行这一行,试着把这个放在后面

while voice.is_playing():
     await asyncio.sleep(1)
voice.disconnect()

其次,正如我所知道的,“ctx.guild.voice_client”是一个VoiceProtocol,你不能使用play(),pause()等方法,但首先尝试使用我说的行,你应该有一个属性不存在的异常。

nukf8bse

nukf8bse3#

你的问题在这里:

channelVC = ctx.author.voice.channel

看看调试返回什么,应该返回一个VocalGuildChannel对象。但情况并非如此,所以你必须确保“ctx.author.voice”发生的事情,因为它可能返回None,确保你的配置文件在语音通道中是有效的。

相关问题