【问题标题】:Keeping track of how many times uses a command in discord.py跟踪在 discord.py 中使用命令的次数
【发布时间】:2018-03-10 20:08:11
【问题描述】:

我一直试图弄清楚如何跟踪用户使用命令的次数。我希望能够在每次键入命令时递增并显示他们使用命令的次数。 这是我的一个命令的一些代码: 忽略选择语句

@client.command(pass_context=True)
async def pick(ctx):
    author = ctx.message.author.id
    if 1 <= giftRate <= 2:
        if (1 <= lowFishRange <= 20):
            oneto5 = str(5)
            await client.say("<@%s>" % (author) + " recived " + oneto5 + " 
            fish")

        else:
            oneto5 = str(1)
            await client.say("<@%s>" % (author) + " recived " + oneto5 + " 
            fish")
     else:
        await client.say("<@%s>" % (author) + " seemed to have missed the mark, the only way to gurantee fish is by "
                     "waiting for a cool pant cate to give you some.")

【问题讨论】:

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


    【解决方案1】:

    您可以有一个全局字典来跟踪它。键是用户 ID,值是他们执行该特定命令的次数。您将需要多个字典,每个命令一个,或者您可以将 dict 值设为一个列表,其中每个索引都有不同命令的计数。

    commandCounts = {}
    commandCounts[user.id] = [command1, command2, command3]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-14
      • 2014-10-29
      • 1970-01-01
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 2021-01-24
      相关资源
      最近更新 更多