'Discord py nickname, on_member_update

@bot.event
async def on_member_update(before, after):   
if before == bannedwords:
        await after.edit(nick=before.nick)
        if before == bannedwords:
            await after.edit(nick=before.nick)
        else:
            await after.edit(nick=before.nick)
    print("old nick: ", before.nick)
    print("new nick: ", after.nick)

My Code look like this.

My goal is to change the name whenever the nickname is changed, AND when it includes bad words.

for ex) /nick (cursing words) bot changes name into temporary name

IT WORKS FINE if we change our name like enter image description here

BUT NOT LIKE enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source