我无法让我的不和谐音乐机器人工作,这是我运行它的代码。当我尝试播放音乐时出现错误。请帮忙
async def play(ctx, url: str):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("Wait for the current playing music end or use the 'stop' command")
return
await ctx.send("Getting everything ready, playing audio soon")
print("Someone wants to play music let me get that ready for them...")
voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, 'song.mp3')
voice.play(discord.FFmpegPCMAudio("song.mp3"))
voice.volume = 100
voice.is_playing()
答案 0 :(得分:0)
我认为这与没有正确设置语音对象有关,因为您没有将任何频道名称/ID 传递给它。我认为你应该试试这个:
voice = discord.utils.get(ctx.guild.voice_channels, name=channel.name)