更改多个角色的权限

时间:2018-06-04 20:24:15

标签: python-3.x discord.py

我刚刚进入Python,一般编程,我已经开始编写我自己的机器人,但现在我遇到了使用bot命令更改权限的问题,更确切地说我想更改权限超过一个角色,这是我得到的东西,直到知道,我知道它的一切都很混乱,我非常感谢一些帮助!

@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))

提前致谢!

1 个答案:

答案 0 :(得分:0)

utils.get将从role返回一个server.roles。相反,我们可以使用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))
相关问题