我想让冷却时间计时器针对运行命令的特定人员,而不是为每个人提供冷却时间。某些命令可以作为每个人的冷却时间,但是我需要一种将其添加到其他命令的方法,以便可以毫无失败地运行它们,但有人不能只是向其发送垃圾邮件。
last_called = None
async def on_ready(self):
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
print('I\'m in the mainframe.')
async def on_message(self, message):
# check if 10 seconds have passed since the last call
if MyClient.last_called and DT.datetime.now() < MyClient.last_called + DT.timedelta(seconds=10): #sets a timer on all commands with MyClient.last_called = DT.datetime.now().
return
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
return
if message.content.startswith('!discord'):
channel = client.get_user(message.author.id)
await channel.send('https://discord.gg/'.format(message))
MyClient.last_called = DT.datetime.now()