Phoenix
Phoenix

Reputation: 45

discord.py how to make the bot ban someone if they have a certain word in their name

I was wondering how I could ban someone if they had someone in their name. For example, I have people who join with the n word in their name and I wanted to know how I could ban them for having that in their name.

Upvotes: 2

Views: 797

Answers (1)

duckboycool
duckboycool

Reputation: 2455

You can use the discord.Member object given by on_member_join to get the user's name, and filter names that way.

import discord

intents = discord.Intents.default()
intents.members = True #So you can use on_member_join event

client = discord.Client(intents=intents)

banlist = []

@client.event
async def on_member_join(member):
    if any(banned in member.name for banned in banlist):
        await member.ban()
        return

Upvotes: 3

Related Questions