Members in A Guild

  discord, discord.py, discord.py-rewrite, python

I have this code that is supposed to send a list of members in a server that the bot is in, only with a guild id. Here is my code:

@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!")

But it doesn’t seem to be working and I can’t figure out why. I’m seriously stupid sometimes.
Here is the error I’m getting:

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

Source: Python Questions

One Reply to “Members in A Guild”

  • try with

    “`
    @client.command(name=’members’)
    async def _members(ctx, guild_id: int):
    guild = client.get_guild(guild_id)
    async for m in guild.fetch_members(limit=None):
    await ctx.send(f”{m}”)
    await ctx.send(“Done!”)

    “`

    Clearly the message ` TypeError: ‘MemberIterator’ object is not iterable` is not too friendly. How it is possible that a class named `MemberIterator` is not iterable?

LEAVE A COMMENT