Estoy tratando de configurar el tiempo de reutilización para mi comandos, pero cuando reinicio el bot el tiempo de reutilización se pierden. Estoy tratando de encontrar una manera de almacenar los tiempos de reutilización y la reutilización de ellos, pero no pude lograr que buscando en google docs
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)
encontré este código en la Pila, pero no funciona... cualquier ayuda será apreciada