如何限制我的命令垃圾邮件的数量(discord.py)

问题描述 投票:0回答:2

我想限制可以作为

spam
命令参数输入的数量。我怎样才能做到这一点?这是我正在使用的代码:

@client.command()
async def spam(ctx, message=None,* ,amount : int):
  for _ in range(amount):
    await ctx.send(message)
command discord.py limit
2个回答
0
投票

一个简单的 if 语句就可以做到。此外,您的命令参数排序不正确。下面的代码是比较理想的。尝试一下并相应地修改垃圾邮件限制数量:

@client.command()
async def spam(ctx, amount : int, *, message=None):
    limit = 5
    if amount > limit:
        await ctx.send("exceeds spam limit")
        return
    else:
        for _ in range(amount): 
            await ctx.send(message)

要运行此程序,您必须执行

spam <amount> <message>
。例如,
!spam 4 hello this is a spam


0
投票

从discord.ext导入命令

自定义检查以验证金额参数

def is_valid_spam_amount(金额): 返回 1 <= amount <= 10 # Set the desired range for the amount (1 to 10 in this example)

@client.command()
async def spam(ctx, message=None, *, amount: int):
    if is_valid_spam_amount(amount):
        for _ in range(amount):
            await ctx.send(message)
    else:
        await ctx.send("Invalid amount. Please provide a value between 1 and 10.")
© www.soinside.com 2019 - 2024. All rights reserved.