не работают слеш команды на серверах в лс с ботом работают в discord.py
import discord
from discord import app_commands
from discord.ext import commands
PREFIX = ''
intents = discord.Intents().all()
intents.message_content = True
test_guilds = [1120440318643425492]
bot = commands.Bot(command_prefix=PREFIX, intents=intents, guilds=test_guilds)
@bot.event
async def on_ready():
print("Bot ready for work!")
try:
synced = await bot.tree.sync()
print(f'Synced {len(synced)} command(s)')
except Exception as e:
print(e)
@bot.tree.command(name='hello')
async def hello(interaction: discord.Interaction):
await interaction.response.send_message(f'Hey! :){interaction.user.mention}! This is a slash command!', ephemeral=True)
@bot.tree.command(name='say')
@app_commands.describe(thing_to_say='what should i say?')
async def say(interaction: discord.Interaction, thing_to_say: str):
await interaction.response.send_message(f'{interaction.user.mention} said: `{thing_to_say}`')
bot.run('Тут токен')
Ответы (1 шт):
Автор решения: adolf_two
→ Ссылка
Вместо этого вы можете использовать bot.application_commands для синхронизации ваших команд.
import discord
from discord.ext import commands
...
@bot.slash_command(name='hello')
async def hello(interaction: discord.Interaction):
await interaction.response.send_message(f'Hey! {interaction.user.mention}! This is a slash command!', ephemeral=True)
@bot.slash_command(name='say')
async def say(interaction: discord.Interaction, thing_to_say: str):
await interaction.response.send_message(f'{interaction.user.mention} said: `{thing_to_say}`')
...