Py-Cord 功能在访问权限时没有响应

问题描述 投票:0回答:1

这是我在这个库中遇到的最奇怪的问题。我的代码工作正常,但是这个命令(如下)没有任何响应。但是,程序不会输出任何错误。

@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)

定义了所有必要的变量,如代码所示,第一个 print 语句工作正常,但第二个则不行。鉴于此,我必须假设问题出在权限访问范围内。我的机器人具有完整的意图,并且可以在我的测试服务器上运行,但不能在不属于我的真实服务器中运行。如果重要的话,该机器人在该测试不起作用的服务器中没有管理员访问权限。不过,它确实有

mange_server
烫发功能。

我尝试改变

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

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

但我什至无法获得没有同样问题的列表。

有什么建议吗?

python discord discord.py pycord
1个回答
0
投票

ctx.author.guild_permissions.manage_server
会引发错误,因为
manager_server
不存在,这意味着以下代码将不会运行。

您应该使用

manage_guild
来代替。

您没有收到错误,因为您在

on_application_command_error
事件中处理错误的方式不正确。

© www.soinside.com 2019 - 2024. All rights reserved.