简体   繁体   English

不使用 ctx 的 discord.py 权限

[英]Permissions with discord.py without using ctx

So, I wanted to set up a purge command for discord.py, but everyone is able to use it.所以,我想为 discord.py 设置一个清除命令,但每个人都可以使用它。 I obviously want it just for people who have the manage messages permission.我显然只希望拥有管理消息权限的人使用它。 I don't really understand ctx commands yet, so I'd like to avoid that for now, and the only answers I can find to this involve using ctx , and setting it up as @bot.command .我还不太了解ctx命令,所以我现在想避免这种情况,我能找到的唯一答案涉及使用ctx ,并将其设置为@bot.command What I have right now is:我现在拥有的是:

    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.")

You can use TextChannel.permissions_for using the TextChannel object you have from Message.channel .您可以使用TextChannel.permissions_for使用Message.channelTextChannel对象。 You can simply pass it the Member object from Message.author .您可以简单地将来自Message.authorMember对象传递给它。
With the Permissions object, you can then simply check Permissions.manage_messages .使用Permissions对象,您可以简单地检查Permissions.manage_messages

You should really look into using the commands extension though.不过,您应该真正考虑使用命令扩展名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM