【问题标题】:Changing permissions for more than one role更改多个角色的权限
【发布时间】:2018-06-04 20:24:14
【问题描述】:

我刚接触 Python 和通用编程,我已经开始编写自己的机器人,但现在我在使用机器人命令更改权限时遇到问题,更准确地说,我想更改权限超过一个角色,这是我知道的,我知道这很混乱,我非常感谢一些帮助!

@bot.command(pass_context=True)
@commands.has_role("botadmin")
async def giveperm(ctx, *rankName: str):
    rank = discord.utils.get(ctx.message.server.roles, name=' '.join(rankName))
    await bot.say("Give me a moment! Giving permissions to post in " + str(ctx.message.channel))
    perms = discord.PermissionOverwrite(send_messages=True)
for rankName in str(rank):
    await bot.edit_channel_permissions(channel=ctx.message.channel, target=rankName, overwrite=perms)
if ctx.message.channel == "suggestions":
    await bot.say("Suggestions are now open again for a week! \n\n Please only post suggestions here to prevent any chaos, with that said, have fun and happy suggesting!")
else:
    await bot.say("Permissions granted to " + rankName + " to post in " + str(ctx.message.channel))

提前致谢!

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    utils.get 将从server.roles 返回一个role。相反,我们可以使用converterdiscord.py 直接通过解析命令给我们角色

    @bot.command(pass_context=True)
    @commands.has_role("botadmin")
    async def giveperm(ctx, *roles: discord.Role):
        await bot.say("Give me a moment! Giving permissions to post in " + str(ctx.message.channel))
        perms = discord.PermissionOverwrite(send_messages=True)
    
        for role in roles:
            await bot.edit_channel_permissions(channel=ctx.message.channel, target=rankName, overwrite=perms)
    
        if ctx.message.channel == "suggestions":
            await bot.say("Suggestions are now open again for a week! \n\n Please only post suggestions here to prevent any chaos, with that said, have fun and happy suggesting!")
        else:
            await bot.say("Permissions granted to " + rankName + " to post in " + str(ctx.message.channel))
    

    【讨论】:

    • 我稍后会尝试!感谢您的快速答复! :)
    猜你喜欢
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 2017-01-16
    • 2011-12-02
    相关资源
    最近更新 更多