【问题标题】:Different roles have different cooldowns discord.py不同的角色有不同的冷却时间 discord.py
【发布时间】:2021-01-29 06:40:15
【问题描述】:

目前我有这个:

@client.command()
async def test(ctx):
    if ctx.message.author.has_role(803952153496256512):
        @commands.cooldown(3, 60, commands.BucketType.user)
    elif ctx.message.author.has_role(803952219694432326 ):
        @commands.cooldown(5, 60, commands.BucketType.user)
    elif ctx.message.author.has_role(803952282198212668 ):
        @commands.cooldown(7, 60, commands.BucketType.user)
    else:
        return

我想要它,所以如果用户具有特定角色,命令的冷却时间会有所不同

【问题讨论】:

    标签: python discord discord.py discord.py-rewrite


    【解决方案1】:

    我在配置冷却时间方面从来都不是最好的,但我可以帮助你的是你的角色检测。为了判断一个成员是否有角色,我们需要一些东西;成员对象和角色 ID。似乎您的命令上下文中包含所有这些,所以我们应该很好地编写一些代码。我只是把你的代码改成这样。

    @client.command()
    async def test(ctx):
        if any([discord.utils.get(ctx.author.roles, id = 803952153496256512)]):
            pass
        elif any([discord.utils.get(ctx.author.roles, id = 803952219694432326)]):
            pass
        elif any([discord.utils.get(ctx.author.roles, id = 803952282198212668)]):
            pass
    

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 1970-01-01
      • 2021-05-15
      • 2022-08-02
      • 2021-10-15
      • 2021-07-05
      • 2021-05-02
      • 1970-01-01
      相关资源
      最近更新 更多