【问题标题】:Permissions with discord.py without using ctx不使用 ctx 的 discord.py 权限
【发布时间】:2020-05-02 18:29:57
【问题描述】:

所以,我想为 discord.py 设置一个清除命令,但每个人都可以使用它。我显然只希望拥有管理消息权限的人使用它。我还不太了解ctx 命令,所以我现在想避免这种情况,我能找到的唯一答案是使用ctx,并将其设置为@bot.command。我现在拥有的是:

    elif message.content.startswith ('jb!purge'):
        searchargs = message.content.split(" ")
        if(len(searchargs) > 1):
            if(len(searchargs) > 2):
                await message.channel.send("Too many numbers! Please try `jb!purge <number>`")
            elif(len(searchargs) == 2):
                if has_permissions(manage_messages = True):
                    try:
                        output = int(searchargs[1])
                        await message.channel.purge(limit=output)
                    except ValueError:
                        await message.channel.send("That's not a number, silly!")
                else:
                    await message.channel.send("Go get the perms first, then try again.")

【问题讨论】:

    标签: python discord.py python-3.8


    【解决方案1】:

    您可以使用来自Message.channelTextChannel 对象来使用TextChannel.permissions_for。您可以简单地将Member 对象从Message.author 传递给它。
    使用Permissions 对象,您可以简单地检查Permissions.manage_messages

    不过,您确实应该考虑使用 commands extension

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-21
      • 2021-05-03
      • 2020-12-22
      • 2020-08-06
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 2021-03-12
      相关资源
      最近更新 更多