命令引发异常:AttributeError:“上下文”对象没有属性“成员”

时间:2020-01-21 17:39:11

标签: python discord.py

我正在尝试制作一个机器人来禁止服务器中的所有成员,但是它不起作用。我知道ctx出了点问题,但我不知道怎么办。这是无效的代码:

@client.command()
async def mpbga(guild):
    for member in guild.members:
        try:
            await member.ban(reason="vibe check", delete_message_days=0)
        except discord.Forbidden:
            pass

我收到此错误消息:

Ignoring exception in command mpbga:
Traceback (most recent call last):
  File "C:\Users\name\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 79, in wrapped
    ret = await coro(*args, **kwargs)
  File "death2.py", line 20, in mpbga
    for member in guild.members:
AttributeError: 'Context' object has no attribute 'members'

有人可以帮忙吗?预先感谢!

1 个答案:

答案 0 :(得分:0)

传递给命令的第一个参数始终是Context。在这种情况下,它将作为guild参数传递。 您可以将Context.guild属性用于发送命令的公会。

有关更多信息,请参见the documentation for the commands extension