簡體   English   中英

不使用 ctx 的 discord.py 權限

[英]Permissions with discord.py without using ctx

所以,我想為 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.")

您可以使用TextChannel.permissions_for使用Message.channelTextChannel對象。 您可以簡單地將來自Message.authorMember對象傳遞給它。
使用Permissions對象,您可以簡單地檢查Permissions.manage_messages

不過,您應該真正考慮使用命令擴展名

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM