Python discord.py忽略机器人程序(client.command)

Python discord.py忽略机器人程序(client.command),python,discord,discord.py,Python,Discord,Discord.py,我想用我调用的p!roleall,但它并没有忽视机器人,我需要帮助。没有提供任何错误。谢谢 @client.command() 异步def roleall(ctx,角色:discord.role): 对于ctx.guild.members中的i: 如果i==i.bot: ctx.send('e') 尝试: 等待i.add_角色(角色) 除discord.errors.probled外: 等待ctx.send(f'`我没有角色{i.name}`的权限) 通过 试着放一个 else: 在尝试之前

我想用我调用的
p!roleall
,但它并没有忽视机器人,我需要帮助。没有提供任何错误。谢谢

@client.command()
异步def roleall(ctx,角色:discord.role):
对于ctx.guild.members中的i:
如果i==i.bot:
ctx.send('e')
尝试:
等待i.add_角色(角色)
除discord.errors.probled外:
等待ctx.send(f'`我没有角色{i.name}`的权限)
通过
试着放一个

else:
在尝试之前

另外,将
ctx.send('e')
更改为
wait ctx.send('e')
尝试放置一个

else:
在尝试之前


另外,将
ctx.send('e')
更改为
wait ctx.send('e')
您的代码存在一些问题。首先,每个ctx.send()都需要等待。对于i.bot,它返回一个布尔值,因此无需对其进行比较。 it不忽略机器人的问题源于您没有指示程序跳过其余代码。一个
continue
语句将为您完成此操作

@client.command()
async def roleall(ctx, role: discord.Role):
  for i in ctx.guild.members:
    if i.bot:
        await ctx.send('e')
        continue
    try:
      await i.add_roles(role)
    except discord.errors.Forbidden:
      await ctx.send(f'`i do not have permissions to role {i.name}`')
      pass

您的代码存在一些问题。首先,每个ctx.send()都需要等待。对于i.bot,它返回一个布尔值,因此无需对其进行比较。 it不忽略机器人的问题源于您没有指示程序跳过其余代码。一个
continue
语句将为您完成此操作

@client.command()
async def roleall(ctx, role: discord.Role):
  for i in ctx.guild.members:
    if i.bot:
        await ctx.send('e')
        continue
    try:
      await i.add_roles(role)
    except discord.errors.Forbidden:
      await ctx.send(f'`i do not have permissions to role {i.name}`')
      pass

也许你应该在
中添加代码,否则:
好的,我会试试看,不,它仍然在向机器人添加角色;-;我认为这是
I=I.bot:
的问题所在。因为它没有发送“e”,所以首先使用
print()
查看
i
i.bot
中的内容。也许你比较了完全错误的值,如果i.bot是真的,可能应该是
或者更短的
如果i.bot:
也许你应该把代码放在
中,否则:
好的,我会试试看。不,它仍然在向bots添加角色;-;我认为这是
I=I.bot:
的问题所在。因为它没有发送“e”,所以首先使用
print()
查看
i
i.bot
中的内容。也许你比较了完全错误的值,如果i.bot是真的,可能应该是
或者如果i.bot是短的
非常感谢!非常感谢你!是的,我会的,谢谢!是的,我会的,谢谢!