I
I
Igor Krupsky2021-08-13 17:12:44
Python
Igor Krupsky, 2021-08-13 17:12:44

How to display each invite from the guild.invites list in discord.py?

I need to send each invite from the list of server invites to the chat. I tried to do this with "for i in guild.invites" but when I ran the command (not on the initial run) I got an error:

Ignoring exception in command gl:
Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "<string>", line 18, in gl
TypeError: 'coroutine' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/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: 'coroutine' object is not iterable
/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.8/asyncio/events.py:81: RuntimeWarning: coroutine 'Guild.invites' was never awaited
  self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Here is the command code:
@bot.command()
async def gl(ctx):
  il = ctx.guild.invites() #Берем список инвайтов в сервере и посещаем в il
  for i in il:
    emb = discord.Embed(title="IL", type="rich", colour=discord.Color.dark_blue()) #Создаем эмбед для красоты вывода
    emb.add_field(name="SCR:",value=f"{i}")
    await ctx.send(embed=emb) #Отправляем сообщение

Please tell me how to fix it!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-08-22
@cyz

await lost
il = await ctx.guild.invites()

A
Alan Gibizov, 2021-08-13
@phaggi

By the rules of the language, it tries to iterate the method object itself, not what it returns. Maybe you should: Maybe that's not the point - I don't know what the method returns there. But from what you have shown, I can only assume this. for i in guild.invites:
for i in guild.invites():

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question