Issue
So I have been trying to make a bot command that can change all the members names in my server with one command, but everything I have tried didn't work, I have also tried to research this but could not find where someone asked or made this. I apologize if this isn't possible ...
@client.command()
async def change_nicks(guild_id, new_nick):
guild = client.get_guild(827704596620115968)
new_nickname = test
async for member in guild.fetch_members():
await member.edit(nick=new_nickname) #change their nickname to the new one
Solution
from discord.ext import commands
import discord
...
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='<your_prefix>', intents=intents)
...
@bot.command(name="nickall")
async def change_all_nicknames(ctx, nickname):
for member in ctx.guild.members:
if member.guild_permissions.administrator:
continue
await member.edit(nick=nickname)
...
<prefix>nickall "desired_nickname"
note: the members intent is a privileged intent, meaning that if your bot is in 75 servers or more, you will have to apply for bot verification.
To enable the guild members intent for "small bots" (bots in less than 75 servers), go to your Bot tab in the developer portal and enable the guild members intent ( and any other intents you require for your bot to function)
Answered By - henry groves
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.