【问题标题】:Making a Slash Command visible only to the owner in Nextcord.py使斜线命令仅对 Nextcord.py 中的所有者可见
【发布时间】:2022-07-10 22:16:31
【问题描述】:

我正在尝试使一些斜线命令仅对机器人所有者可见,例如加载/卸载我的 cog 的命令等。

以下是我的代码:

@client.slash_command(name="load", description="Cog Loader",guild_ids=[937755377901133896])
@commands.is_owner()
async def load(interaction: Interaction, cog: str = nextcord.SlashOption(name="cogs", description="Name of the Cog.")):
    try:
        await client.load_extension(cog)
        await interaction.response.send_message(f"Loaded: {cog}")
    except Exception as e:
        await interaction.response.send_message(f"Error: {e}")

@client.slash_command(name="unload", description="Cog Unloader",guild_ids=[937755377901133896])
@commands.is_owner()
async def unload(interaction: Interaction, cog: str = nextcord.SlashOption(name="cogs", description="Name of the Cog.")):
    try:
        await client.unload_extension(cog)
        await interaction.response.send_message(f"Unloaded: {cog}")
    except Exception as e:
        await interaction.response.send_message(f"Error: {e}")

【问题讨论】:

  • 不,你不能这样做。您只能在 guilds_ids 中将您的 slash cmd 指定为您想要的服务器。您可以使用if interaction.user == youruserid 来阻止其他人使用此命令,但它仍然对所有人可见。希望这可以帮助你。
  • 猜猜我将不得不为这些特定命令建立一个私人服务器,Thnx 的评论:)

标签: python discord bots nextcord


【解决方案1】:

你可以让它只有管理员可以访问

    if not interaction.user.guild_permissions.administrator:
        await interaction.response.send_message("You are not authorized to run this command.", ephemeral=True)
    else:
        #do your admin command here

【讨论】:

    猜你喜欢
    • 2021-06-09
    • 2022-08-09
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 2019-03-05
    • 2022-01-25
    • 2021-06-11
    • 2022-11-09
    相关资源
    最近更新 更多