Miro Pletscher
Miro Pletscher

Reputation: 7

How do you give every member in a discord server a role at one time discord.py

I'm trying to give all members in my server a role with this command, but it doesn't seem to work. It doesn't give the role to all the members, but just to the client. It also doesn't show any errors in the console.

@client.command()
async def assignall(ctx, *, role: discord.Role):
    await ctx.reply("Attempting to assign all members that role...")
    for member in ctx.guild.members:
        await member.add_roles(role)
    await ctx.reply("I have successfully assigned all members that role!")

Upvotes: 0

Views: 674

Answers (2)

Shweta K
Shweta K

Reputation: 249

•Go to https://discord.com/developers/applications

•Select your bot

•Go to the bot section

•Scroll down and enable all the intents(Technically you need only server members' intent but if you do all it will help you)

enter image description here

•Replace your client=commands.Bot(command_prefix="your_prefix") to

intents = discord.Intents.default()
intents.message_content = True
client=commands.Bot(command_prefix="your_prefix",intents=intents)

Upvotes: 0

StarbuckBarista
StarbuckBarista

Reputation: 1318

Ensure that you have enabled the GUILD_MEMBERS Intent from your Discord Developer Portal and initialized your client with the proper intents.

from discord import Intents
from discord.ext.commands import Bot

client = Bot(intents=Intents.all())

Server Members Intent

Upvotes: 1

Related Questions