我正在尝试制作一个机器人来禁止服务器中的所有成员,但是它不起作用。我知道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'
有人可以帮忙吗?预先感谢!
答案 0 :(得分:0)
传递给命令的第一个参数始终是Context
。在这种情况下,它将作为guild
参数传递。
您可以将Context.guild
属性用于发送命令的公会。
有关更多信息,请参见the documentation for the commands extension。