Fusion Insanity
Fusion Insanity

Reputation: 15

discord.py - channel.members not giving members in a channel

For a command, I am trying to move every member from every channel within a specific category to another channel and the delete all the channels in that category. I have tested the code and it all works apart from the channel.members part. The print(channel.members) returns an empty list [] every time I run the command. Any idea what I'm doing wrong?

I know fetching the guild ID prevents this from working but I'm not doing that anywhere in the code.

#Delete all channels in Ongoing Matches
@client.command()
async def comm(ctx):
    general = discord.utils.get(ctx.guild.channels, name='Vibing')
    category = discord.utils.get(ctx.guild.categories, name='Ongoing Matches')
    channels = category.channels
    for channel in channels:
        print(channel.members)
        for member in channel.members:
            print(member)
            await member.move_to(general)
        await channel.delete()

Upvotes: 1

Views: 1027

Answers (1)

kubaki18
kubaki18

Reputation: 26

It's all about discord.Intents() Head to your developer portal > your project > Bot and toggle "SERVER MEMBERS INTENT" on. Then in your project add the intents to your bot with

# create intents before creating bot/client instance
intents = discord.Intents().default()
intents.members = True
# create the instance
client = discord.Client(intents=intents)

If you're using discord.ext.commands.Bot the process is similar, just add intents=intents to the constructor.

Upvotes: 1

Related Questions