我有一个问题,当我试图建立一个冷却处理程序"在一个discord.py cog中,它发送消息等,但冷却时间消息仍然发送,冷却时间也不起作用。
我什么都试过了,但就是不能再进一步了。
希望有人有解决办法!
Thanks in advance
import discord
from discord.ext import commands
import asyncio
import time
import json
import random
import typing
from colorama import Fore, init
from datetime import timedelta
from discord.ext.commands.cooldowns import BucketType
from discord_components import DiscordComponents, Button, ButtonStyle, Select, SelectOption
init()
with open('config.json', 'r') as f:
config = json.load(f)
prefix = config["prefix"]
token = config["token"]
class Fish(commands.Cog):
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.message.delete()
sec = round(error.retry_after)
td = str(timedelta(seconds=sec))
x = td.split(':')
em = discord.Embed(title=f"Yo, chill and wait {x[0]}h, {x[1]}m, {x[2]}s!", color=0xf1c40f)
em.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
await ctx.send(embed=em, delete_after=30)
@commands.cooldown(1, 60, commands.BucketType.user)
@commands.guild_only()
@commands.command(aliases=["f"], description='Fish some fishes', help="f")
async def fish(self, ctx):
#code
def setup(client):
client.add_cog(Fish(client))```
我知道答案!在on_message方法中有
await self.client.process_commands(message)
因此,机器人每次发送2条消息!