不和谐语音对象没有属性'play'



嘿,我正试图在我的discord服务器的语音聊天中播放音频,我收到了错误

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'play'

我的代码

import discord
from discord.utils import get
from discord.ext import commands
from discord import FFmpegPCMAudio
from youtube_dl import YoutubeDL
import os
@bot.command('play')
async def jp(ctx, url):
global voice
chan = ctx.message.author.voice.channel
voice = get(bot.voice_clients, guild=ctx.guild)
ydl_op ={
'format':'bestaudio/best',
'postprocessors':[{
'key':'FFmpegExtractAudio',
'preferredcodec':'mp3',
'preferredquality':'256'
}]
}
with YoutubeDL(ydl_op) as ydl:
ydl.download([url])
for file in os.listdir('./'):
if file.endswith('.mp3'):
name = file
os.rename(file,'audio.mp3')
voice.play(FFmpegPCMAudio['audio.mp3'], after=lambda e: print(f"Done playing {name}"))
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.volume = 0.07
nname = name.rsplit('-',2)**

有一个相同的问题,但没有任何经过验证的答案

此代码必须以None的形式返回语音

试试这个

voice = get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected:
await voice.move_to(channel)
else:
voice = await channel.connect()

最新更新