Im essayant de définir le temps de recharge pour mes commandes, mais lorsque je redémarre le bot le temps de recharge sont perdus. J'essaie de trouver un moyen de stocker les temps de récupération et de réutilisation, mais je ne pouvais pas l'atteindre en regardant 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)
trouvé ce code sur la Pile, mais il ne fonctionne pas... toute aide sera appréciée