【问题标题】:I want to add a cooldown to a bot. I want them to choose the cooldown. PYTHON DISCORD我想为机器人添加冷却时间。我希望他们选择冷却时间。蟒蛇不和谐
【发布时间】:2021-09-02 02:27:33
【问题描述】:

Ex 某人在 100 秒内向某人发送了大量文本。我希望他们有 100 秒的冷却时间,因为他们发送了 100 条短信。我收到此错误:

@commands.cooldown(1,{time}, commands.BucketType.user)
    ^
IndentationError: expected an indented block
@client.command()
async def text(ctx, ip, port, time, method):
@commands.cooldown(1,f'{time}', commands.BucketType.user)
    url = f'N/A'
    response = requests.get(url)
    embed = discord.Embed()

    embed.title = 'Launched'
    print(f'{ip}')
    print(f'{port}')
    print(f'{time}')        
    print(f'{method}')
    embed.add_field(name = 'IP', value = ip, inline=False)
    embed.add_field(name = 'PORT', value = port, inline=False)
    embed.add_field(name = 'TIME', value = f'{time}', inline=False)
    embed.add_field(name = 'METHOD', value = method, inline=False)
    print(ctx.author, 'in', ctx.guild)

    embed.set_author(name="Proll's Bot", icon_url=client.user.avatar_url)
    await ctx.send(embed = embed)

【问题讨论】:

  • 我是 python 新手,主要是 java 脚本中的代码
  • 改变async def@commands.cooldown的位置
  • def 之后,以下行需要缩进。在你的情况下,它不是。请阅读基本的 Python 语法。
  • 就像我说的,如果你能修复代码并发送它,我是新手。会很棒的。

标签: python python-3.x timer discord discord.py


【解决方案1】:

按照bdbd的说法改变async def和@commands.cooldown的位置

@client.command()
@commands.cooldown(1,f'{time}', commands.BucketType.user)
async def text(ctx, ip, port, time, method):


    url = f'N/A'
    response = requests.get(url)
    embed = discord.Embed()

    embed.title = 'Launched'
    print(f'{ip}')
    print(f'{port}')
    print(f'{time}')        
    print(f'{method}')
    embed.add_field(name = 'IP', value = ip, inline=False)
    embed.add_field(name = 'PORT', value = port, inline=False)
    embed.add_field(name = 'TIME', value = f'{time}', inline=False)
    embed.add_field(name = 'METHOD', value = method, inline=False)
    print(ctx.author, 'in', ctx.guild)

    embed.set_author(name="Proll's Bot", icon_url=client.user.avatar_url)
    await ctx.send(embed = embed)

【讨论】:

  • 那么 {time} 将是未定义的
  • 您必须以秒为单位定义时间限制
猜你喜欢
  • 2022-12-10
  • 2021-08-01
  • 2021-04-21
  • 1970-01-01
  • 1970-01-01
  • 2017-07-08
  • 2021-05-15
  • 1970-01-01
  • 2020-11-18
相关资源
最近更新 更多