我在做一个Python机器人来解决不和。它根据玩家的指令创建一个删除通道。 我想创建一个垃圾收集器来测试服务器.channels删除过时的。在
我知道:
async def waitTimer():
while True:
await asyncio.sleep(10)
regex = re.compile(r"[0-9]*_[a-z0-9]*-[0-9]*") #nom des channels de raid
for cCurrent in client.get_all_channels():
if regex.match(cCurrent.name):
numRaid = int(cCurrent.name[0])
cRaidCurrent = cRaids[numRaid]
date = datetime.datetime.now()
print (cRaidCurrent.raid.fin.timestamp())
print (date.timestamp())
if cRaidCurrent.raid.fin < date:
if cRaidCurrent.retirerRaid():
cId = cRaidCurrent.com.id
await removeFromListe(cRaidCurrent)
await client.delete_channel(client.get_channel(cId))
cCurrent = 0
有时它会过去,有时我会得到这样的错误:
^{pr2}$如果我清楚地理解它,client.get_all_channels
是一个字典,我不能在迭代过程中删除通道。。。所以问题是我还有什么其他的方法可以移除这些频道?在
感谢Patrick Haugh你的回答非常好。在
删除操作需要在最后完成2次。下面是代码,如果有人需要的话:
相关问题 更多 >
编程相关推荐