discord bot删除一个角色但不删除其余角色

时间:2018-03-07 05:01:39

标签: python bots discord discord.py

所以我写这篇文章是为了取消分配角色。如果我分配了多个角色,它将删除它找到的第一个角色,但随后它会以某种方式突破循环。我不确定为什么不删除所有这些。有任何想法吗? role_list只是一个字符串列表。

if message.content.startswith("!unassign"):
    roles_cleared = True

    for r in role_list:
        # Check every role
        role = discord.utils.get(message.server.roles, name=r)
        if role in message.author.roles:
            # If they have the role, get rid of it
            try:
                await client.remove_roles(message.author, role)
            except discord.Forbidden:
                await client.send_message(message.author, "I don't have perms to remove roles.")
                roles_cleared = False
                break

    if roles_cleared:
        await client.send_message(message.author, "Roles successfully cleared.")

2 个答案:

答案 0 :(得分:1)

每次删除角色后都需要添加延迟。只需导入asyncio并添加 NSURL *urlNav = [NSURL URLWithString:@"https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"]; NSData *urlData = [NSData dataWithContentsOfURL:urlNav]; UIImage *imageNav = [UIImage imageWithData:urlData]; UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:NextView]; //navController.navigationBarHidden=YES; [self.navigationController.navigationBar setBackgroundImage:imageNav forBarMetrics:UIBarMetricsDefault]; 即可。您的代码应如下所示:

await asyncio.sleep(1)

答案 1 :(得分:0)

你的代码本身看起来很好,我能想到的唯一问题是role_list只包含一个字符串。您应该检查分配代码的部分。

您是否尝试使用PyCharm之类的调试器进行调试?这听起来像是可以使用它的问题类型。

相关问题