首页 > 解决方案 > Pywhatkit查询虚拟文字库助手

问题描述

我正在尝试构建一个基于文本的虚拟助手,但问题是我不知道如何使用 pywhatkit playonyt 和搜索命令,以便用户输入播放......(任何歌曲或视频)和搜索(无论他们想搜索什么)如果可以请帮助:)))

代码:

def take_command():

command = input("Tell me what would you like me to do").format()
song = pywhatkit.playonyt()

if command in ('play', 'search'):

    if command == 'play'+:

标签: python

解决方案


尝试这个:

import pywhatkit

command = input("Tell me what would you like me to do: ").lower()

if "play" in command:
  pywhatkit.playonyt(command.replace("play ",""))
if "search" in command:
  pywhatkit.search(command.replace("search ",""))

它检查命令是否包含该特定单词,如果是,则删除它们并将其余的短语传递给函数。


推荐阅读