Команда возврат; «Приложение не ответило», но ошибки не обнаружилисьJavascript

Форум по Javascript
Ответить
Anonymous
 Команда возврат; «Приложение не ответило», но ошибки не обнаружились

Сообщение Anonymous »

config-suggestion.js

Код: Выделить всё

const { SlashCommandBuilder, ChatInputCommandInteraction, ChannelType } = require('discord.js');
const GuildConfiguration = require('../../models/GuildConfiguration');

module.exports = {
run: async ({ interaction }) => {
try {
if (!interaction.memberPermissions.has('Administrator')) {
await interaction.reply({ content: 'You need administrator permissions to use this command.', ephemeral: true });
return;
}

await interaction.deferReply({ ephemeral: true }); // Defer reply to give more time for processing

let guildConfiguration = await GuildConfiguration.findOne({ guildId: interaction.guildId });

if (!guildConfiguration) {
guildConfiguration = new GuildConfiguration({ guildId: interaction.guildId });
}

const subcommand = interaction.options.getSubcommand();
const channel = interaction.options.getChannel('channel');

if (subcommand === 'add') {
if (guildConfiguration.suggestionChannelIds.includes(channel.id)) {
await interaction.editReply(`${channel} is already a suggestion channel.`);
return;
}

guildConfiguration.suggestionChannelIds.push(channel.id);
await guildConfiguration.save();
await interaction.editReply(`Successfully added ${channel} as a suggestion channel.`);
return;
}

if (subcommand === 'remove') {
if (!guildConfiguration.suggestionChannelIds.includes(channel.id)) {
await interaction.editReply(`${channel} is not a suggestion channel.`);
return;
}

guildConfiguration.suggestionChannelIds = guildConfiguration.suggestionChannelIds.filter(
(id) => id !== channel.id
);

await guildConfiguration.save();
await interaction.editReply(`Successfully removed ${channel} from suggestion channels.`);
return;
}
} catch (error) {
console.error('Error in config-suggestion command:', error);
if (!interaction.replied) {
await interaction.editReply('An error occurred while processing your command.');
}
}
},
options: {
userPermissions: ['Administrator']
},
data: new SlashCommandBuilder()
.setName('config-suggestion')
.setDescription('Configure suggestion channels for this server.')
.setDMPermission(false)
.addSubcommand(subcommand => subcommand
.setName('add')
.setDescription('Add a suggestion channel')
.addChannelOption(option => option`your text`
.setName('channel')
.setDescription('The channel to add for suggestions')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true)
)
)
.addSubcommand(subcommand => subcommand
.setName('remove')
.setDescription('Remove a suggestion channel')
.addChannelOption(option => option
.setName('channel')
.setDescription('The channel to remove from suggestions')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true)
)
),
};
register-command.js

Код: Выделить всё

const { testServer } = require('../../../config.json');
const areCommandsDifferent = require('../../utils/commandDifferent');
const getApplicationCommands = require('../../utils/getApplicationCommand');
const getLocalCommands = require('../../utils/getLocalCommand');

module.exports = async (client) =>  {
try {
const localCommands = getLocalCommands();
const applicationCommands = await getApplicationCommands(client, testServer);

for (const localCommand of localCommands) {
// Extract command data from localCommand.data (SlashCommandBuilder)
const commandData = localCommand.data || localCommand;

// Serialize SlashCommandBuilder correctly
const commandPayload = commandData.toJSON ? commandData.toJSON() : {
name: commandData.name,
description: commandData.description,
options: commandData.options || [],
};

const { name, description, options } = commandPayload;

if (!name || !description) {
console.log(`Skipping invalid command: ${JSON.stringify(localCommand)}`);
continue;
}

const existingCommand = await applicationCommands.cache.find(
(cmd) => cmd.name === name
);

if (existingCommand) {
if (localCommand.deleted) {
await applicationCommands.delete(existingCommand.id);
console.log(`🗑 Deleted command "${name}".`);
continue;
}

if (areCommandsDifferent(existingCommand, commandPayload)) {
await applicationCommands.edit(existingCommand.id, {
description,
options,
});
console.log(`🔁 Edited command "${name}".`);
}
} else {
if (localCommand.deleted) {
console.log(`⏩ Skipping registering command "${name}" as it's set to delete.`);
continue;
}

await applicationCommands.create({
name,
description,
options,
});
console.log(`👍 Registered command "${name}".`);
}
}
} catch (error) {
console.log(`There was an error: ${error}`);
}
};
< /code>

По какой -то причине, когда я запускаю команду, это возвращение  приложение не отвечало < /strong> по какой -то причине. Я проверил, и он успешно связан с MongoDB.let guildConfiguration = await GuildConfiguration.findOne({ guildId: interaction.guildId });
console.log('guildConfiguration ');
, который не дал результата, хотя я пытался запустить команду.

Подробнее здесь: https://stackoverflow.com/questions/795 ... ror-detect
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»