Discord.py 运行时警告:从未等待协程'Command.__call__'



我正在创建一个控制命令面板的机器人,但我目前遇到了一些问题,我不知道如何修复。我也看了一些类似标题的问题,但似乎他们遇到了不同的问题。

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)

错误信息:

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

编辑:问题是我没有在代码片段中包含一个截图命令。

请记住time.sleep(5)是阻塞的,而asyncio.sleep(5)是非阻塞的。因此,当你在"async "函数,建议使用asyncio。休眠,这样异步动作可以更好地融合在一起。

注:你有没有试过把关键词"等待"盈方的截图()?我指的是第三到最后一行的start()函数定义?

相关内容

最新更新