【问题标题】:How would i add cooldown on my discord bot using python我将如何使用 python 在我的不和谐机器人上添加冷却时间
【发布时间】:2021-08-01 12:09:12
【问题描述】:
import discord
from discord.ext import commands

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    channel = client.get_channel('channel ID')
    if message.guild is None and message.author != client.user:
        await message.channel.send('Hi')   

client.run(<TOKEN>)

这是我的代码我将如何添加冷却时间我想制作一个机器人在另一个用户 dm 时自动回复

【问题讨论】:

  • 删除机器人令牌!你应该保守秘密,否则每个人都可以创建一个机器人并假装它是你的。 "我们以 T UN G#4887 身份登录"
  • 谢谢我忘记了
  • 冷却时间是什么意思?是机器人可以响应消息之间的时间吗? (例如:如果用户发送消息,您希望机器人响应,然后等待一定时间才能再次响应?)
  • @Astros 是的,我想在用户发送消息并且我的机器人响应然后等待 30 分钟再次响应时进行冷却

标签: python


【解决方案1】:

最好的方法是使用装饰器

# cooldown(rate, per, type=<BucketType.default: 0>)
@command.cooldown(1, 30, commands.BucketType.user)

这将限制每位用户每 30 秒使用 1 次。 reference

【讨论】:

  • 我必须把它放在哪里?
  • @client.event @command.cooldown(1, 30, commands.BucketType.user) async def on_message(message):
  • 得到错误“NameError: name 'command' is not defined”
  • 你应该导入from discord.ext import commands
  • 我想这对你有帮助stackoverflow.com/a/65753439/10956192
猜你喜欢
  • 1970-01-01
  • 2022-12-10
  • 2020-11-18
  • 2019-06-28
  • 2021-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-08
相关资源
最近更新 更多