简体   繁体   中英

Please help me with my python discord bot

I want to make a discord bot in python that searches if a member has some specific words/characters in their name (like "hello" or "ЯΛY") and if they do, they will get kicked. I have already attempted to first completely print out all user names in the server, but from then on I couldn't progress further as I didn't know how to add these names to a variable/list where from then on I could just scan it. If anyone is interested in my code that I made already:

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
client = commands.Bot(intents=intents, command_prefix='?')

@client.command()
async def members(ctx):
    for guild in client.guilds:
        for member in guild.members:
            print(member)


client.run("funny token")

You're gonna want their username so grab that from member.name Then check if there is a substring in their name and if it includes your blacklisted text then call the kick method on member. check out the API refrence. so:

if "someText" in member.name:
    member.kick(reason)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM