Ниже я предоставил небольшой пример кода Python с обычной командой слэша (
Код: Выделить всё
bot.tree
Код: Выделить всё
import discord
from discord.ext import commands
# Setup
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", intents=intents)
# Simple login confirmation
@bot.event
async def on_ready():
await bot.tree.sync()
print(f"{bot.user} is online!")
# @discord.app_commands.guild_only() hides the command if the user try's to use it in DMs.
@bot.tree.command(name="hidden-test", description="This command can only be used in guilds!")
@discord.app_commands.guild_only()
async def hidden_command(interaction: discord.Interaction):
await interaction.response.send_message("This command can only be used in guilds!", ephemeral=True)
# This is a discord slash command group, I tried testing "@discord.app_commands.guild_only()" here, it doesn't work.
class TestGroup(discord.app_commands.Group):
def __init__(self):
super().__init__(name="hidden", description="These command can only be used in guilds!")
@discord.app_commands.command(name="true", description="This command can only be used in guilds!")
@discord.app_commands.guild_only()
async def true_command(self, interaction: discord.Interaction):
await interaction.response.send_message("This command can only be used in guilds! (not really :d)", ephemeral=True)
bot.tree.add_command(TestGroup())
# Replace with your bot token, if you're going to test it.
bot.run("YOUR-TOKEN")
Результат: в моем личном сообщении с ботом появилась команда Slash.< /p>
Ожидаемый результат: команда Slash не отображается в моих личных сообщениях с ботом, как и команда «скрытый тест».>
Подробнее здесь: https://stackoverflow.com/questions/791 ... nds-in-dms