warden
warden

Reputation: 25

Discord banall command not working | discord.py

Hello I am creating a banall command for discord on a bot but it doesn't work for some reason please correct the code or give me a working command for ban all or mass ban

The Code:

    for users in ctx.guild.user:
        try:
            await user.ban(reason=reason)
            print(f"[-] BAN : Banned {user}") 
        except:
            pass

Upvotes: 0

Views: 120

Answers (1)

thegigabyte
thegigabyte

Reputation: 131

The guild object doesn't have a user attribute, so it will raise an AttributeError. This is supressed because it is inside a try-except block. You should loop through ctx.guild.members instead.

so your code should look like this:

@client.command()
async def ban_everyone(ctx):
    for member in ctx.guild.members:
        await ctx.ban(member)

Upvotes: 1

Related Questions