【发布时间】:2021-08-23 22:12:48
【问题描述】:
我有问题。我认为这段代码写得很好,机器人启动了一切,但是当我去执行逗号play时,我得到了一个错误。
@bot.command(name='play', aliases=['sing','p'], description="streams music")
async def play_(ctx, self, *, search: str):
#async def play_(ctx, message, self, *, search: str):
"""Request a song and add it to the queue.
This command attempts to join a valid voice channel if the bot is not already in one.
Uses YTDL to automatically search and retrieve a song.
Parameters
------------
search: str [Required]
The song to search and retrieve using YTDL. This could be a simple search, an ID or URL.
"""
await ctx.trigger_typing()
vc = ctx.voice_client
if not vc:
await ctx.invoke(self.connect_)
player = self.get_player(ctx)
# If download is False, source will be a dict which will be used later to regather the stream.
# If download is True, source will be a discord.FFmpegPCMAudio with a VolumeTransformer.
source = await YTDLSource.create_source(ctx, search, loop=self.bot.loop, download=False)
await player.queue.put(source)
错误如下:
discord.ext.commands.errors.MissingRequiredArgument: search is a required argument that is missing.
而且我不知道该怎么做,因为我已经尝试改变位置,但是如果有人知道它是什么,就会不断出现错误,请告诉我
【问题讨论】:
-
如果命令不在类中,为什么要将
self作为参数传递?
标签: python discord discord.py bots