使用命令禁用某些公会的某些命令

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

我希望某些公会不会显示斜杠命令。我不知道该怎么做。我正在使用混合命令,因此我也希望文本命令不响应。我想要一个仅适用于公会所有者的命令,可以为特定公会切换特定命令。

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

文档参考:https://discordpy.readthedocs.io/en/stable/interactions/api.html#decorators:~:text=%40discord.app_commands.guilds,it%20as%20a%20global%20command.

我使用这个问题/示例作为我的discord.py示例的基础: 如何在discord.py中创建有效的斜杠命令

我不使用discord.py,我的机器人使用disnake.py。我尝试使用在discord.py 中找到的内容为您收集最佳答案。

import discord
import discord.ext

intents = discord.Intents.all() 
client = discord.Client(intents=intents)
tree = discord.app_commands.CommandTree(client)

@client.event
async def on_ready():
    await tree.sync(guild=discord.Object(id=Your guild ID here))
    # print "ready" in the console when the bot is ready to work
    print("ready")

# make the slash command (but it only works in guilds on the allowed_guilds list.
allowed_guilds = [111111111111111111, 222222222222222222, 333333333333333333]
@tree.command(name="name", description="description", guild_ids=allowed_guilds)
async def slash_command(interaction: discord.Interaction):    
    await interaction.response.send_message("command")

# run the bot
client.run("token")

然后您还拥有 ctx 命令,因为您有一个混合机器人。所以像...

@client.command
async def tester(ctx):
    if ctx.author.guild.id in allowed_guilds:
        await ctx.send("Allowed guild")
    else:
        pass

希望这有帮助!快乐编码!

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