Python 使用后台任务时破坏我的命令

Python 使用后台任务时破坏我的命令,python,discord,discord.py,bots,python-asyncio,Python,Discord,Discord.py,Bots,Python Asyncio,我正在使用python开发一个discord bot,它每天在非常特定的时间在服务器上发送一条预定消息以及其他功能。实现计划消息后,bot命令不再工作-因此用户不能使用任何命令,但计划消息可以工作 我已设置bot,以便它在UTC 12:00、19:00、21:00、22:00、23:00发送消息。现在唯一的问题是“help”等命令不起作用 import discord import datetime import asyncio from discord.ext import commands

我正在使用python开发一个discord bot,它每天在非常特定的时间在服务器上发送一条预定消息以及其他功能。实现计划消息后,bot命令不再工作-因此用户不能使用任何命令,但计划消息可以工作

我已设置bot,以便它在UTC 12:00、19:00、21:00、22:00、23:00发送消息。现在唯一的问题是“help”等命令不起作用

import discord
import datetime
import asyncio
from discord.ext import commands
from discord.utils import get

client = commands.Bot(command_prefix = ';',help_command=None) #prefix

race_times_utc = [12,19,21,22,23]
time = datetime.datetime.now
    
async def timer():

  await client.wait_until_ready()

  msg_sent = False

  while not client.is_closed():
    if any(time().hour == race for race in race_times_utc) and time().minute == 0:
      if not msg_sent:
        channel = client.get_channel(838626115326636022)
        racer_role = get(channel.guild.roles, name = 'Racers')

        embed = discord.Embed(
          title = 'Race Time',
          description = 'Scheduled reminder for everyone that race starts soon.',
          colour = discord.Colour.blue()
        )
    
        await channel.send(f'{racer_role.mention}',embed=embed)
        msg_sent = True
    else:
      msg_sent = False

  await asyncio.sleep(1)

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name=' ;help'))
    client.loop.create_task(timer())
    print('Bot is alive')

#Functions such as this no longer working
@client.command()
async def help(ctx):
...
您应该使用,因为您的部分代码似乎被阻塞了

导入不一致
导入日期时间
导入异步
从discord.ext导入任务、命令
从discord.utils导入获取
client=commands.Bot(command_prefix=';',help_command=None)#前缀
比赛时间utc=[12,19,21,22,23]
time=datetime.datetime.now
@任务。循环(秒=1.0)#代替睡眠
异步定义计时器():
msg_sent=False
如果有(time().hour==race\u times\u utc)和time().minute==0:
如果未发送消息:
通道=客户端获取通道(83862615326636022)
racer_role=get(channel.guild.roles,name='Racers')
嵌入=不和谐。嵌入(
标题='比赛时间',
description='比赛即将开始,所有人的预定提醒',
颜色=不和谐。颜色。蓝色()
)
等待channel.send(f'{racer_role.notice}',embed=embed)
msg_sent=True
其他:
msg_sent=False
@客户端事件
_ready()上的异步定义:
等待客户端。更改状态(activity=discord.activity(type=discord.ActivityType.waiting,name=';help'))
打印('机器人处于活动状态')
timer.start()

代码不是真正的阻塞,他只是没有让事件循环空闲,他一直让它忙碌,其他协同路由无法调度您是否知道
asyncio.sleep
在while循环之外?