发送WhatsApp消息时出现错误,使用pywhatkit。

huangapple go评论108阅读模式
英文:

Error while sending whatsapp message using pywhatkit

问题

我的程序应该使用pywhatkit库发送WhatsApp消息,通过语音识别从用户那里获取输入。

这是发送消息的函数。

def WhatsApp():
    speak("要发消息给谁")
    Contacts = {
        '妈妈' : 63XXXXXXX,   # 这些是号码(已隐藏)
        '卡尔蒂克' : 75XXXXXXx,
        '我' : 81XXXXXXX,
        '杰拉姆' : 99XXXXXXXX
    }
    to = takeCommand() #使用语音识别获取我的语音输入
    speak("要发送什么消息")
    msg = takeCommand()
    speak(f"发送消息给{to}")
    try:
        pwt.sendwhatmsg_instantly(f"+91{Contacts[to]}", msg, 5, True, 15)
    except Exception as e:
        speak("发送消息时出错")
        print(e)

当我说要给我的语音助手发送WhatsApp消息时,它会问我要发给谁以及发送什么消息。

我使用了pywhatkit的sendwhatmsg_instantly函数,以便消息能够快速发送,但它只是打开WhatsApp网页然后返回。

我的问题:

  • WhatsApp网页会打开,转到联系人号码,我的消息已经准备好发送,但不会发送我的消息,然后在一段时间后关闭标签。

注意:

  • 我还尝试在pwt.sendWhatmsg_instantly函数参数中更改关闭标签时间,但没有用,结果仍然一样。

请帮我找到一个更好的方法来通过pywhatkit立即发送消息,并解决错误。

英文:

My Program should send whatsapp message using pywhatkit library by taking input from user by speech recognition.

This is the function that send message.

def WhatsApp():
    speak("For Whom should i send message")
    Contacts = {
        'mom' : 63XXXXXXX,   # these are numbers (hidden)
        'karthik' : 75XXXXXXx,
        'me' : 81XXXXXXX,
        'jayaram' : 99XXXXXXXX
    }
    to = takeCommand() #takes my voice input using speech_recognition
    speak("what message should i send")
    msg = takeCommand()
    speak(f"sending message to {to}")
    try:
        pwt.sendwhatmsg_instantly(f"+91{Contacts[to]}",msg,5,True,15)
    except Exception as e:
        speak(f"error sending message")
        print(e) 

When i say send whatsapp message to my Voice assistant it will ask me for whom to send and what msg it should send.

I used pywhatkit send whatsapp msg instantly function so that msg could send fastly but its just opening whatsapp web and returning back.

My Problem :

  • Whatsapp web is opening and goes to contact number and my message will be there ready to be sent but it wont send my msg and closes the tab after some time.

Note:

  • i also tried to change the close tab time in function parameter of pwt.sendWhatmsg_instantly(a,b,c,d,closetab time) but no use the result was same.

Please help me find a better way to do this sending message instantly through pywhatkit and to solve the error.

答案1

得分: 0

尝试使用pyautogui模块。在pwt.sendwhatmsg_instantly(f"+91{Contacts[to]}", msg, 5, True, 15)之后添加pyautogui.press("enter")

此外,如果您使用多个显示器可能会出现问题。

英文:

Try to use pyautoguit module. Add pyautogui.press(“enter”) after
pwt.sendwhatmsg_instantly(f"+91{Contacts[to]}",msg,5,True,15)

Also, there is can be issues if you use multiple displays.

huangapple
  • 本文由 发表于 2023年2月27日 16:38:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定