我试图设置的冷却我的命令但是,当我重新启动机器人的冷却时间丢失。 我试图找到一种方式储存的冷却时间和重新使用它们但我不可能实现它通过查看文档
import discord
from discord.ext import commands
cooldown_info_path = "cd.pkl"
class Bot(commands.Bot):
async def start(self, *args, **kwargs):
import os, pickle
if os.path.exists(cooldown_info_path): # on the initial run where "cd.pkl" file hadn't been created yet
with open(cooldown_info_path, 'rb') as f:
d = pickle.load(f)
for name, func in self.commands.items():
if name in d: # if the Command name has a CooldownMapping stored in file, override _bucket
self.commands[name]._buckets = d[name]
return await super().start(*args, **kwargs)
async def logout(self):
import pickle
with open(cooldown_info_path, 'wb') as f:
# dumps a dict of command name to CooldownMapping mapping
pickle.dump({name: func._buckets for name, func in self.commands.items()}, f)
return await super().logout()
client = Bot(command_prefix=">")
@client.event
async def on_ready():
print("Ready!")
@client.command()
@commands.cooldown(1, 3600, commands.BucketType.user)
async def hello(ctx):
await ctx.send("HEY")
class ACog(commands.Cog):
def __init__(self, client):
self.bot = client
@commands.command()
@commands.cooldown(1, 600, commands.BucketType.user)
async def ping(self, ctx):
msg = "Pong {0.author.mention}".format(ctx)
await ctx.send(msg)
client.add_cog(ACog(client))
client.run(token)
找到这段代码堆栈上的但是它不工作... 任何帮助将可以理解的