Discord.py RuntimeWarning: coroutine 'Command.__call__' was never awaited

Viewed 54

I'm creating a bot that controls a command panel, but am currently running into some issues I don't know how to fix. I've also looked at some questions with similar titles, but it seems like they are running into a different issue.

from pyautogui import *
import pyautogui
import win32gui
import time
import clipboard
import discord
from discord.ext import commands

botToken = "No"
client = commands.Bot(command_prefix='!', help_command=None)

fileLocation = "C:/Users/Admin/Downloads/Program.exe"

def screenshot():
    with open("hwnd.txt", "r") as file:
        hwnd = int(file.read())
    win32gui.SetForegroundWindow(hwnd)
    x, y, x1, y1 = win32gui.GetClientRect(hwnd)
    x, y = win32gui.ClientToScreen(hwnd, (x, y))
    x1, y1 = win32gui.ClientToScreen(hwnd, (x1 - x, y1 - y))
    pyautogui.screenshot("screenshot.png",region=(x, y-27, x1, y1+27))

@client.command()
async def start(ctx):
    if clipboard.paste != fileLocation:
        clipboard.copy(fileLocation)
    pyautogui.hotkey('winleft', 'r')
    time.sleep(0.5)
    pyautogui.hotkey('ctrl', 'v')
    pyautogui.press("enter")
    time.sleep(0.5)
    with open("hwnd.txt","w") as file:
        hwnd = win32gui.FindWindow(None, fileLocation.replace("/","\\"))
        file.write(str(hwnd))
    time.sleep(0.1)
    screenshot()
    time.sleep(0.1)
    await ctx.channel.send("Screenshot:", file=discord.File("screenshot.png"))

client.run(botToken)

Error message:

RuntimeWarning: coroutine 'Command.__call__' was never awaited
  screenshot()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Edit: The issue was a screenshot command I didn't include in the snippet.

1 Answers

Please remember that time.sleep(5) is blocking, and asyncio.sleep(5) is non-blocking. Therefore when you are in an "async def" function it is advised to use asyncio.sleep so the asynchronous actions can better blend together.

P.S. have you tried to put the key phrase "await" infront of screenshot()? I am refering to the 3rd to last line of the start() function definition?

Related