Discord.py 斜线命令权限

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

我目前正在开发一个 Discord Bot,它使用 Discord.py 作为后端,并使用 cogs 来执行斜杠命令,我目前正在尝试实现一个具有斜杠命令权限的工作禁止功能,以不允许没有特定权限的成员查看它,但我无法找到一个万无一失的解决方案来实现这一点。然而,我能够找到一个装饰器,它可以在运行命令之前获得所需的权限,但是,它并不像我预期的那样工作。任何帮助表示赞赏!我找不到任何可以给我预期结果的文档,但是我确实找到了 discord.js 文档来获得我期望的结果。 https://discordjs.guide/slash-commands/permissions.html#member-permissions

我尝试过使用

    @commands.has_permissions(ban_members=True) 

装饰器能够做到这一点,但如果用户没有 ban_members 权限,它没有我期望的隐藏斜线命令的功能,这是我的完整代码:

#cogs / admin/ ban.py
from discord.ext import commands
import discord, typing

class banUser(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.hybrid_command()
    @commands.has_permissions(ban_members=True) 
    @commands.cooldown(1, 10, commands.BucketType.user)
    async def ban_user(self, ctx, member: discord.Member, reason: typing.Optional[str]):
        """
        Ban certain members from your server.
        """
        await member.ban(reason = reason)
        await ctx.reply(f"{member} has been successfully banned from the server.", ephemeral=True)
        em = discord.Embed(color=discord.Color.from_rgb(0,0,255),title=f"**{member} has been banned from the server**.",description=f"{member} has been banned from the server for {reason}.")
        await ctx.send(embed=em)

async def setup(client):
    await client.add_cog(banUser(client))
python discord.py
1个回答
0
投票

我不确定这是否可以在discord.py中实现,但我知道你可以在服务器设置中更改它。

转到服务器设置 -> 集成 -> 你的机器人并在斜杠命令下查看。

您应该看到为特定命令添加用户/卷的能力,一旦您这样做,只有这些用户/卷才能看到或使用该命令。希望这有帮助!

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