R
R
RitteF2021-08-25 14:32:44
Python
RitteF, 2021-08-25 14:32:44

Error in code, why?

I am writing a bot, and I can’t fix it, help, here is the code and the error itself:

channel_chat = client.get_channel(879035346015359023)
    message = await channel_chat.send(embed = discord.Embed(title="Внимание! Идёт установка ролей..", description="Ожидайте...", colour=discord.Colour.from_rgb(255, 0, 0)))
    getrole = discord.utils.get(ctx.guild.roles, id=879035345969217558)
    guild = ctx.guild
    for member in guild:
        if role not in member.roles:
            await member.add_roles(getrole)
            await message.edit(embed = discord.Embed(title="Установка завершилась!",description=f"Ролей выдано :: {ctx.guild.member_count}", colour=discord.Colour.from_rgb(0, 255, 0)))
            await message.add_reaction("✅")
            return
    return


Error:
Ignoring exception in command setup_roles:
Traceback (most recent call last):
File "C:\Users\Asus\AppData\Local\Programs\Python\Python39\lib\site-packages\discord.py-0.16.3-py3 .9.egg\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Asus\Desktop\GGDPS Manager\bot.py ", line 21, in setup_roles
for member in guild:
TypeError: 'Guild' object is not iterable

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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2021-08-27
@RitteF

As already mentioned in the comments - you are trying to iterate the guild object itself, not its members.

for member in ctx.guild.members:  # зачем делать переменную, которая будет использоваться один раз?
    if role not in member.roles:
        await member.add_roles(getrole)
        await message.edit(embed = discord.Embed(title="Установка завершилась!",description=f"Ролей выдано :: {ctx.guild.member_count}", colour=discord.Colour.from_rgb(0, 255, 0)))
        await message.add_reaction("✅")
        return

A
Artem Imaev, 2021-08-26
@AIRC24

I heard that discord.py does not work in 3.9 version of python, try using (3.8) in another version of the intopritor. and if this version is not 3.9, then I don’t know.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question