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

User/Role specific channel permissions aren't properly reflected from channel options #1312

Closed
3 tasks done
argo0n opened this issue May 1, 2022 · 2 comments · Fixed by #1365
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@argo0n
Copy link
Contributor

argo0n commented May 1, 2022

Summary

When I parse an application command's channel option's user/role permissions, the permissions returned are not accurate.

Reproduction Steps

  • Create a slash command with a TextChannel option, with the ability to default back to ctx.channel, and return the permissions in some way. (I only tested TextChannel when creating this issue.)

  • Deny a role or a member the ability to view Channel A, or deny all the permissions listed on Channel A's permissions in the client.

  • Run the slash command with Channel A as the channel option.

  • Run the slash command again in Channel A, while having the channel option/argument empty so it defaults to context Channel A.

  • Both commands will show different permissions for channel A.

Minimal Reproducible Code

import discord
from discord.ext import commands

intents = discord.Intents(guilds = True, members = True, presences = True, messages = True, reactions = True, emojis = True, invites = True, voice_states = True, message_content = True)

bot = commands.Bot(command_prefix="!", intents=intents)

def replace_bool(arg: bool):
    """
    Adding this just so that it'll be easy to read the output and differentiate the permissions
    """
    if arg is True:
        return "✅"
    elif arg is False:
        return "❌"
    else:
        return "❔"

GUILD_IDS = [...]
@bot.slash_command(name="permissions", guild_ids=GUILD_IDS)
async def slash_permissions(ctx: discord.ApplicationContext, channel: discord.Option(discord.TextChannel) = None, member: discord.Option(discord.Member) = None, role: discord.Option(discord.Role) = None):
    if channel is None:
        channel = ctx.channel
    arg = member or role
    if arg is None:
        return await ctx.respond("Provide a member or role to check permissions for.")
    strings = []
    for p in channel.permissions_for(arg):
        strings.append(f"{replace_bool(p[1])} {p[0]}")
    await ctx.respond(embed = discord.Embed(description="\n".join(strings)))

bot.run("TOKEN")

Expected Results

I expected to see the same permissions returned for both commands.

Actual Results

When the channel object is retrieved from the context (discord.ApplicationContext), the permissions are accurate.

However when the channel object is retrieved from the channel option, the permissions are inaccurate. All of the inaccurate permissions are assigned True when they are actually False. The ones that are inaccurate during my testing include:

  • create_instant_invite
  • add_reactions
  • view_channel
  • send_messages
  • embed_links
  • attach_files
  • read_message_history
  • external_emojis
  • change_nickname
  • use_slash_commands
  • request_to_speak
  • create_public_threads
  • create_private_threads
  • external_stickers
  • send_messages_in_threads

image | image

On the left is when I run the slash command with channel as an option (inaccurate permissions),
On the right is when I run the slash command with the channel from ctx.channel. (correct permissions)

Intents

intents = discord.Intents(guilds = True, members = True, presences = True, messages = True, reactions = True, emojis = True, invites = True, voice_states = True, message_content = True)

System Information

  • Python v3.9.2-final
  • py-cord v2.0.0-beta
    • py-cord pkg_resources: v2.0.0b7
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.22000

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

Just like this similar issue regarding members from slash commands, I can get the channel again as a workaround

@argo0n argo0n added the unconfirmed bug A bug report that needs triaging label May 1, 2022
@plun1331
Copy link
Member

plun1331 commented May 1, 2022

Looks like a duplicate of #1283, should be left open though as it contains more details.

@plun1331 plun1331 added bug Something isn't working and removed unconfirmed bug A bug report that needs triaging labels May 1, 2022
@argo0n
Copy link
Contributor Author

argo0n commented May 2, 2022

Looks like a duplicate of #1283, should be left open though as it contains more details.

Aaah, I somehow didn't notice that existing issue, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants