主要目标: 每周三08:00向频道发送消息
这是我当前的代码:
import schedule
import time
import discord
import asyncio
from discord.ext import commands, tasks
from discord.ext.tasks import loop
client = discord.Client()
# IMPORTANT
channel =
botToken = ""
async def sendloop():
while True:
schedule.run_pending()
await asyncio.sleep(1)
@client.event
async def on_ready():
general_channel = client.get_channel(channel)
print('ready')
schedule.every(2).seconds.do(lambda:loop.create_task(general_channel.send('TEST')))
client.run(botToken)
到目前为止,没有错误,只是停留在“准备就绪”。我是使用VS代码的初学者。
我不建议使用scheduler,因为discord扩展
task
与您试图在代码中实现的功能相同:如果您要在希望重复的时间运行此代码,它将完成您想要的。另一种方法是检查
before()
函数,如果您不想等待并在希望运行该函数的当天运行代码,则检查该函数是否适合运行但是如果您真的想使用schedule模块,请发布我的帮助:Discord.py Time Schedule
相关问题 更多 >
编程相关推荐