I'm developing a bot for a discord with some specific features. In some of them there is a command that is /aviso and /initiar and they are working, or they were...
I made a modification to the /aviso command and now a synchronization error appears in the log and I don't know what to do to fix it, I have already entered several synchronization commands such as:
@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}")
But this error still appears in the log:
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.
Can anyone give me some light on what to do to solve this problem?
I've already tried synchronizing the bot's commands so that the command works, but nothing works. I've already updated the discord.py library, if I add another command, for example, I can't get it to be recognized as an interaction command. I don't know what to do anymore.
Also, I tried to do manual synchronization using the channel ID:
@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}!')
I tried this other command as well to try to remove the old command and add the new one, but without success:
@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}!')
complete command:
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="📢 Aviso",
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
/avisocommand.