python - Discord Python Bot 播放音乐 - url 是缺少的必需参数
问题描述
我目前正在使用 python 编写一个不和谐的机器人并遇到了一个问题。我尝试让我的机器人使用“播放”命令播放音乐。
我的代码:
@bot.command(name='play')
async def play(self, ctx, url : str):
if ctx.author.voice is None:
embed = discord.Embed(title=f'> Du musst in einem Voice Channel sein, um diesen Befehl zu verwenden.', description='Diese Nachricht wird nach 15 Sekunden automatisch gelöscht.', color=embed_color, timestamp=datetime.now().astimezone(tz=de))
embed.add_field(name='⠀', value='⠀')
embed.set_footer(text=f'Angefordert von {ctx.author.name} • {ctx.author.id}', icon_url=ctx.author.avatar_url)
bot_msg = await ctx.send(embed=embed)
await asyncio.sleep(15)
await bot_msg.delete()
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
await voice_channel.connect()
else:
await ctx.voice_client.moce_to(voice_channel)
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
YDL_OPTIONS = {'format':"bestaudio"}
vc = ctx.voice_client
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)
vc.play(source)
但是在运行命令时出现以下错误:
discord.ext.commands.errors.MissingRequiredArgument:url 是缺少的必需参数。
这是为什么?
PS:我在不和谐频道中输入的内容:“.play https://www.youtube.com/watch?v=V0woPCb5xk8” 所以我显然给了它一个可以使用的网址......:c
解决方案
推荐阅读
- amp-html - 创建一个 Google AMP 项目有多难?
- node.js - 节点 js 错误:监听 EADDRNOTAVAIL 52.**.**.***:1122
- java - 使用 Java 解析数组中的嵌套 JSON 对象时出错
- javascript - 孩子总高度溢出时如何自动延长父母高度?
- python - 我如何比较两个字典列表
- windows - 使用批处理脚本从字符串中提取数字部分
- angular - Nx 工作区 + 本地存储
- reactjs - 从我的 Electron 应用程序访问本地 Sqlite3 DB 的正确方法是什么?
- python - Python set.update 和 set.add 在代码中做完全不同的事情
- python - ModuleNotFoundError:即使存在 numpy,Flask 应用程序中也没有名为“numpy”的模块错误。