Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17389

Py-Cord function not responding when accessing permissions

$
0
0

This is the strangest problem I have ever had with this library. My code works fine, but this command (below) does not respond with anything. However, the program does not output any error.

@admin.command(name = "staffrole", description = "Toggle a role that has permissions to use this bot's admin commands")@guild_only()async def staffrole(ctx, role: discord.Option(Union[discord.Role])):    print('This prints successfully')    admin = ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_server    print("This does not print. I have no idea why.")    if not admin:        return await ctx.respond("You must have \"Manage Server\" or \"Administrator\" permission in this server to use this.", ephemeral=True)    try:        with open(f"StaffRoles/{ctx.guild.id}", 'x') as _:            pass    except FileExistsError:        pass    with open(f"StaffRoles/{ctx.guild.id}", 'r') as file:        filedata = file.readlines()        if f"{role.id}\n" in filedata:            with open(f'StaffRoles/{ctx.guild.id}', 'w') as filew:                filedata = ''.join(filedata)                filedata = filedata.replace(f'{str(role.id)}\n', '')                filew.write(filedata)            await ctx.respond(f"Removed {str(role)} from the Staff List!", ephemeral=True)        else:            with open(f'StaffRoles/{ctx.guild.id}', 'a') as filea:                filea.write(f"{str(role.id)}\n")            await ctx.respond(f"Added {str(role)} to the Staff List!", ephemeral=True)

All necessary variables are defined, and as shown in the code, the first print statement works fine but the second one does not. Given this, I must assume that the issue lies within the permission access. My bot has full intents and works on my test server, but not in a real server not owned by me. If it matters, the bot does not have Administrator access in the server that this test does not work on. It does have mange_server perms, though.

I attempted to change

admin = ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_server

to

perms = [perm[0] for perm in member.guild_permissions if perm[1]]

But I could not even get the list without the same issue.

Any advice?


Viewing all articles
Browse latest Browse all 17389

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>