Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
luxkatana opened this issue Jan 6, 2025 · 1 comment
Open
3 tasks done
Labels
unconfirmed bug A bug report that needs triaging

Comments

@luxkatana
Copy link

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

@luxkatana luxkatana added the unconfirmed bug A bug report that needs triaging label Jan 6, 2025
@Icebluewolf
Copy link
Contributor

This has something to do with the fact that ctx.channel (which can be traced back to Interaction.channel does not have any overwrites set. This leads me to believe that this only affects private channels or other channels with permission overwrites.

@luxkatana luxkatana changed the title len(ctx.channel.members) is not right ctx.channel.members is not the same as ctx.guild.get_channel(ctx.channel_id).members Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

2 participants