因此,我的问题是如何将变量url设置为在yt之后键入的内容?例如!yt [youtbube link] makes url = [youtube link]
这是我目前的代码,感谢您的帮助

@client.command(pass_context=True)
async def yt(ctx):
    url = 'https://www.youtube.com/watch?v=rPOUewuNKFE'

    author = ctx.message.author
    voice_channel = author.voice_channel
    vc = await client.join_voice_channel(voice_channel)

    player = await vc.create_ytdl_player(url)
    player.start()

最佳答案

实际上,这很简单。只需将其添加为函数的参数即可。

@client.command(pass_context=True)
async def yt(ctx, url):

    author = ctx.message.author
    voice_channel = author.voice_channel
    vc = await client.join_voice_channel(voice_channel)

    player = await vc.create_ytdl_player(url)
    player.start()

如果愿意,您还可以使用标准函数注释(async def yt(ctx, url: str):)指定参数的类型,但这并不是很有用,因为默认情况下无论如何都将它们作为字符串传递。

10-08 18:02