NextCord,为什么可以在 @tasks.loop中执行此操作?
NextCord接受DateTime.Time的列表。Timein @tasks.loop中,但我需要更改列表。我试图这样做:
class peter_teste(commands.Cog):
def __init__(self, bot):
super().__init__()
self.bot = bot
self.peter.start()
def peter_times(self):
peter_hours = []
#change the default list
return peter_hours
@tasks.loop(time=self.peter_times())
async def peter(self):
#do something
我在 @tasks.loop(time = self.peter_times())中遇到错误“未定义”错误
Nextcord accepts a list of datetime.time in @tasks.loop but i need to change the list. I tried to do this:
class peter_teste(commands.Cog):
def __init__(self, bot):
super().__init__()
self.bot = bot
self.peter.start()
def peter_times(self):
peter_hours = []
#change the default list
return peter_hours
@tasks.loop(time=self.peter_times())
async def peter(self):
#do something
I get the error "self is not defined" in @tasks.loop(time=self.peter_times())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在装饰器中使用
peter_times
,它不能在班级中进行处理,因为在班级初始化之前对装饰器进行了处理,(Soself
在那里未定义) 。您可以在班级外设置这些时间,也可以在a tre_loop 并更改那里的间隔。<用于在执行中间改变时间。
To use
peter_times
in the decorator, it can't a method of the class, as the decorators are processed before the class is initialized, (soself
is not defined there). You can set up those times outside the class, or set them up in a before_loop and change the interval there.change_interval can be used to change the times in the middle of execution.