【发布时间】:2020-12-10 07:49:30
【问题描述】:
我正在使用on_message 扫描特定关键字的代码,以便机器人可以做出相应的响应,不,我不能使用命令来实现这一点。
我想通过打开冷却时间来防止人们向这些关键字发送垃圾邮件,以便机器人在再次检查之前等待
文档内容:
class SomeCog(commands.Cog):
def __init__(self):
self._cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user)
async def cog_check(self, ctx):
bucket = self._cd.get_bucket(ctx.message)
retry_after = bucket.update_rate_limit()
if retry_after:
# you're rate limited
# helpful message here
pass
# you're not rate limited
我有什么:
class Listener(commands.Cog):
def __init__(self, bot):
self._cd = commands.CooldownMapping.from_cooldown(1.0, 10.0, commands.BucketType.user)
@commands.Cog.listener()
async def on_message(self, message):
async def cog_check(self, message):
bucket = self._cd.get_bucket(message)
retry_after = bucket.update_rate_limit()
if retry_after:
print('test')
pass
elif (message.guild is None):
return '.'
else:
. . . . . #code which tests for the keywords
【问题讨论】:
标签: python python-3.x discord discord.py