简体   繁体   English

Discord.py 成员角色检查命令

[英]Discord.py member roles check command

So I tried to code a command that will outputs members that don't have a specific role but I am having some errors.因此,我尝试编写一个命令,该命令将输出没有特定角色的成员,但我遇到了一些错误。

The Code编码

@client.command()
@commands.has_permissions(ban_members=True)
async def check(ctx):
    guild = ctx.guild
    for member in guild.members:
        if discord.utils.get(guild.roles, name='Free Customers') not in member.roles:
            for guild.members in range(10):
                await ctx.send(guild.members)

and the error和错误

  File "C:\Users\Archie Baloch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Archie Baloch\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: can't set attribute

Hope I can get some help over here:)希望我能在这里得到一些帮助:)

The problem in your program is in the for loop, you do for guild.members in range(10): where you try to set the guild.members value to 0 as part of your loop, then do await ctx.send(guild.members) which would be 0, then you set it to 1 and send 1, etc until you reach 9. Setting the ctx.guild.members is blocked though as it is not something you are supposed to change您的程序中的问题出在 for 循环中,您for guild.members in range(10):您尝试将 guild.members 值设置为 0 作为循环的一部分,然后执行await ctx.send(guild.members)这将是 0,然后将其设置为 1 并发送 1,等等,直到达到 9。设置 ctx.guild.members 被阻止,因为它不应该更改

I suppose that isnt what you want to do, honestly I cant figure out what you are trying to do.我想这不是你想要做的,老实说我无法弄清楚你想要做什么。

To make it clear:说清楚:

for x in range(10):
    await ctx.send(str(x))

would send:会发送:

0
1
2
3
4
5
6
7
8
9

And that clearly isnt what you want your loop in your program to do这显然不是您希望程序中的循环执行的操作

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

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