python - 我的不和谐机器人音乐命令似乎不起作用。我导入了 PyNacl 和 youtube_dl,但它仍然不起作用
问题描述
我的代码可能有一些错误,但在这里。我只是希望有办法解决这个问题,因为我一直在尝试制作一些音乐命令,但它们都没有奏效。我不确定为什么这段代码不起作用。它没有给我任何错误。先感谢您。
@client.command(pass_context=True)
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 to end or use the 'stop' command")
return
voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General')
await voiceChannel.connect()
voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': '249/250/251',
'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"))
解决方案
推荐阅读
- powershell - Azure DevOps / Pipelines:设置 NuGet 包中内容文件的“生成操作”和“复制到输出目录”属性
- php - Laravel Controller request array empty for Route with Parameters
- oop - Similiar Object for Different Use
- scala - Spark SQL Dataframes - 在连接的 where 子句中使用 $columnname 在 spark-shell 中工作但不能编译
- r - 使用零长度输入的映射。如何让它跳过?
- amazon-web-services - AWS Cloudwatch 在动态标签上触发 Codepipeline
- scala - 将 2 个 Scala Spark 数据帧和一个 Long 值转换为单个 JSON 字符串
- javascript - Chartjs 1 到 n 关系
- arrays - 很想记住数组中的随机值?
- c - 从指向一大块内存的指针中找到第 n 位