Я внес изменения в /aviso команду и теперь в журнале появляется ошибка синхронизации и я не знаю, что делать, чтобы это исправить, я уже ввел несколько команд синхронизации, таких как:
@bot.event
async def on_ready():
try:
await bot.tree.sync()
print("Comandos sincronizados com sucesso.")
except Exception as e:
print(f"Erro ao sincronizar comandos: {e}")
Но эта ошибка все равно появляется в журнале:
2024-10-14 12:22:43 ERROR discord.app_commands.tree Ignoring exception in command 'aviso'
Traceback (most recent call last):
File "C:\Users\Rezend3\Desktop\VILAO\.venv\Lib\site-packages\discord\app_commands\tree.py", line 1310, in _call
await command._invoke_with_namespace(interaction, namespace)
File "C:\Users\Rezend3\Desktop\VILAO\.venv\Lib\site-packages\discord\app_commands\commands.py", line 882, in _invoke_with_namespace
transformed_values = await self._transform_arguments(interaction, namespace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Rezend3\Desktop\VILAO\.venv\Lib\site-packages\discord\app_commands\commands.py", line 846, in _transform_arguments
raise CommandSignatureMismatch(self) from None
discord.app_commands.errors.CommandSignatureMismatch: The signature for command 'aviso' is different from the one provided by Discord. This can happen because either your code is out of date or you have not synced the commands with Discord, causing the mismatch in data. It is recommended to
sync the command tree to fix this issue.
Может ли кто-нибудь подсказать мне, что делать, чтобы решить эту проблему?
Я уже пробовал синхронизировать команды бота, чтобы команда работает, но ничего не работает. Я уже обновил библиотеку discord.py, если я добавлю, например, еще одну команду, я не смогу распознать ее как команду взаимодействия. Я больше не знаю, что делать.
Также я попробовал выполнить ручную синхронизацию по идентификатору канала:
@bot.event
async def on_ready():
# Syncs only for the specified guild
guild = discord.Object(id=1285939558738825306)
await bot.tree.sync(guild=guild)
print(f'Logged in as {bot.user}!')
Я попробовал и эту другую команду, чтобы попытаться удалить старую команду и добавить новую, но безуспешно:
@bot.event
async def on_ready():
# Remove the command if it already exists
bot.tree.remove_command('aviso', type=discord.AppCommandType.chat_input)
# Synchronizes tree commands
await bot.tree.sync()
print(f'Logged in as {bot.user}!')
полная команда:
import asyncio
import discord
from discord.ext import commands
from discord.ui import Button, View
# Configurações de intents
intents = discord.Intents.default()
intents.members = True
intents.messages = True
intents.guilds = True
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
# Sincroniza apenas para o guild especificado
# Substitua pelo seu guild ID
guild = discord.Object(id=1285939558738825306)
await bot.tree.sync(guild=guild)
print(f'Logged in as {bot.user}!')
@bot.tree.command(name='aviso', description='Envia um aviso para o canal específico.')
@discord.app_commands.describe(mensagem='A mensagem que será enviada.')
async def aviso(interaction: discord.Interaction, mensagem: str):
# ID do canal onde o comando pode ser usado
canal_permitido_id = 1290828710844305481
# Verifica se o comando foi usado no canal permitido
if interaction.channel.id != canal_permitido_id:
await interaction.response.send_message('Este comando só pode ser usado no canal específico da staff.', ephemeral=True)
return
# Pergunte ao executor do comando qual canal deve receber a mensagem
canal_id = interaction.data.get('options')[0]['value'] # Altere para coletar o ID do canal
canal = bot.get_channel(canal_id)
# Mensagens de depuração
print(f'Canal permitido: {canal_permitido_id}, Canal atual: {interaction.channel.id}')
if canal is not None:
# Criando um embed para a mensagem
embed = discord.Embed(
title="
description=mensagem,
color=discord.Color.red(), # Você pode mudar a cor aqui
)
embed.set_footer(text="Equipe Vila Brasil, Community.")
await canal.send(embed=embed) # Enviar a mensagem embed
await interaction.response.send_message('Aviso enviado com sucesso!', ephemeral=True)
else:
print('Canal não encontrado.')
await interaction.response.send_message('Canal não encontrado.', ephemeral=True)
#rest of the code
Подробнее здесь: https://stackoverflow.com/questions/790 ... -in-python