N
N
Nyxoy2021-11-21 19:06:26
Python
Nyxoy, 2021-11-21 19:06:26

Allban discord python. Where is the mistake?

My code:

@client.command()
async def allban(ctx):
    for member in guild.fetch_members(limit=None):
        await member.ban(reason=None)
        print(member)


Mistake:
Ignoring exception in command allban:
Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\Admin\Desktop\bethce\anti-lavan-new.py", line 37, in allban
    for member in guild.fetch_members(limit=None):
NameError: name 'guild' is not defined

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

Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\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: NameError: name 'guild' is not defined

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2021-11-21
@Nyxoy

async for member in ctx.guild.fetch_members(limit=None):

Z
Zagir Majidov, 2021-11-21
@Zagir-vip

lol man learn discord.py...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question