python - 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'+:
解决方案
尝试这个:
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 ",""))
它检查命令是否包含该特定单词,如果是,则删除它们并将其余的短语传递给函数。
推荐阅读
- c# - 在 EF 核心中,在一个类中添加实体后,如何在不调用 SaveChanges() 的情况下从不同的类访问实体?
- css - 使用 View Style React Native 创建布局
- json.net - 使用 JsonConvert 将具有德国文化格式的字符串转换为双精度
- c++ - 为什么 rand 每次都给我几乎相同(但略有不同)的数字
- java - 消息队列处理,每条消息都有长时间运行的任务
- macos - Mac 上的安装和设置融合
- android - 在颤动中渲染 SVG 文件不起作用
- django - 在外键 django rest 框架中对字段应用排序
- r - 如何识别一系列 NA 之前和之后的值
- php - 以编程方式创建帖子并添加特色图片,同时跳过上传到媒体库