Код: Выделить всё
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)
)
),
};
Код: Выделить всё
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