【发布时间】:2020-09-13 03:51:44
【问题描述】:
我希望机器人每天在特定时间完成一项工作,我知道我可以按计划完成,这也很简单。我试过了,效果很好,但现在我试图把它安排成齿轮并反复出错。
齿轮:
import discord
from discord.ext import commands, tasks
import discord.utils
from discord.utils import get
import schedule
import asyncio
import time
class SmanageCog(commands.Cog, name='Manager') :
def __init__(self,bot):
self.bot = bot
def job(self):
print("HEY IT'S TIME!")
schedule.every().day.at("10:00").do(job)
while True:
schedule.run_pending()
time.sleep(1)
def setup(bot):
bot.add_cog(SmanageCog(bot))
print("Manager is loaded!")
根据上面的代码,bot 会在每天上午 10 点打印 hey 它的时间。但这不起作用。它在上午 10 点向我抛出错误。 错误是这样的:
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\bot.py", line 653, in load_extension
self._load_from_module_spec(spec, name)
File "C:\Users\Rohit\AppData\Roaming\Python\Python37\site-packages\discord\ext\commands\bot.py", line 599, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.smanage' raised an error: TypeError: job() missing 1 required positional arguments: 'self'
我不知道我应该从 def job 传递什么参数,我不能在 cog 中留空,而且 self 也会出错,所以我真的不知道要传递什么。
【问题讨论】:
标签: python discord discord.py schedule