Мое приложение работает на сервере < /p>
Однако, когда я переключаюсь на DMS, ни одна из моих команд (
Код: Выделить всё
activity
Команды отсутствуют в dms
мой каталог проектов структурирован следующим образом:
Код: Выделить всё
commands/
└── utility/
├── ping.js
├── check_activity.js
├── user.js
server/
├── api.js
├── models/
└── activity.js
deploy-commands.js
index.js
< /code>
Команды работают нормально на сервере, но не функционируют в DMS, и я не могу понять, почему. < /p>
index.js
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits, MessageFlags } = require('discord.js');
const { token } = require('./config.json');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
],
});
client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.warn(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
const errorMessage = 'There was an error while executing this command!';
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: errorMessage, flags: MessageFlags.Ephemeral });
} else {
await interaction.reply({ content: errorMessage, flags: MessageFlags.Ephemeral });
}
}
});
client.login(token);
< /code>
Я пытался: < /p>
Поиск в Интернете для аналогичных проблем, но я не смог найти ничего полезного. Функции , которые не работают в DMS? Если да, то что я должен изменить, чтобы поддержать как серверы, так и DMS? Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/794 ... e-server-b