亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為此事件添加冷卻時間或速率限制?不和諧.py

如何為此事件添加冷卻時間或速率限制?不和諧.py

海綿寶寶撒 2023-07-11 13:55:27
@commands.Cog.listener()    async def on_message(self, message):        user_in  = message.content.lower()        if "gn" in  user_in.split(" ") or "good night" in user_in :            if message.author.bot: return            if not message.guild: return            await message.channel.send(f"Good Night, <@{message.author.id}>")我需要知道如何為此事件添加冷卻時間,以便人們dont發送垃圾郵件gn或晚安
查看完整描述

1 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

查看完整回答
反對 回復 2023-07-11
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

async def create_embed(self, ctx, err):

        embed = discord.Embed(title=f"Error Caught!",color=discord.Colour.red())

        embed.add_field(name=f"Info on the error.", value=f"{err}")

        embed.set_thumbnail(url=self.bot.user.avatar_url_as(static_format="png"))

        message_cooldown = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user)

        bucket = message_cooldown.get_bucket(ctx.message)

        retry_after = bucket.update_rate_limit()

        if retry_after:

            return

        else:

            await ctx.send(embed=embed)

這是一個很好的例子,它在函數中創建嵌入,使代碼更干凈,以便捕獲錯誤,并確保它不會被冷卻映射垃圾郵件。


查看完整回答
反對 回復 2023-07-11
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號