Skip to content

ctx.channel.members is not the same as ctx.guild.get_channel(ctx.channel_id).members #2685

@luxkatana

Description

@luxkatana

Summary

The ctx.channel.members property is not right

Reproduction Steps

I was working on a discord.ui.View that needs ctx.channel.members, however it is giving the wrong result.

So after that I made a test slash command to check if it was a bug, and yeah, turns out that something is wrong, len(ctx.channel.members is giving 712 while I am asking for the length of one private channel, which only 12 people can access that with view_channel and send_messages permissions

Minimal Reproducible Code

This is the snippet of code in production:

  def is_a_normal_member(user: discord.Member):
      return # had some conditions
  interaction: discord.Interaction # from a button callback
  users = tuple(filter(is_a_normal_member, interaction.channel.members))

Expected Results

To give the members that have access to the current channel

Actual Results

It gave the members of the whole guild

Intents

discord.Intents.all() # all

System Information

- Python v3.12.3-final
- py-cord v2.6.1-final
- aiohttp v3.11.11
- system info: Linux 6.8.0-1019-oem #19-Ubuntu SMP PREEMPT_DYNAMIC Mon Dec  9 06:30:03 UTC 2024

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

I went to the discord server and asked for this problem, and here are some snippets I got

@bot.slash_command(name="some")
async def some(ctx: discord.ApplicationContext):
    channel = ctx.guild.get_channel(1325911264941314059)

    await ctx.respond(str(ctx.channel == channel))

This assertion gave me True

@bot.slash_command(name="some")
async def some(ctx: discord.ApplicationContext):
    channel: discord.TextChannel = await bot.fetch_channel(1325911264941314059)
    mystr = str(len(ctx.channel.members))
    channel = ctx.guild.get_channel(1325911264941314059)
    await ctx.respond(f"{mystr}   {len(channel.members)}")

This gave me 711 12

By the way, when I use ctx.guild.get_channel(...).members, it gives the correct result of 12

Metadata

Metadata

Assignees

No one assigned

    Labels

    unconfirmed bugA bug report that needs triaging

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions