【发布时间】:2021-02-18 15:17:08
【问题描述】:
我有这段代码,它应该在机器人所在的服务器中发送成员列表,只有公会 ID。这是我的代码:
@client.command(name='members')
async def _members(ctx, guild_id: int):
guild = client.get_guild(guild_id)
for m in guild.fetch_members(limit=None):
await ctx.send(f"{m}")
await ctx.send("Done!")
但它似乎不起作用,我不知道为什么。有时我真的很愚蠢。 这是我得到的错误:
172.18.0.1 - - [05/Nov/2020 20:59:40] "HEAD / HTTP/1.1" 200 -
Ignoring exception in command members:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 154, in _members
for m in guild.fetch_members(limit=None):
TypeError: 'MemberIterator' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/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: TypeError: 'MemberIterator' object is not iterable
另外,有没有办法从列表中删除所有机器人?
【问题讨论】:
标签: python discord discord.py discord.py-rewrite