I haven't fully figured out subcommands yet

const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName('bot')
.setDescription('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.') // Короткое описание
.setNameLocalizations({
ru: 'настройки'
})
.addSubcommand(subcommand =>
subcommand
.setName ('settings')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
.setNameLocalizations({
ru: 'бота'
})
),

async execute(interaction) {
const userRoles = interaction.member.roles.cache;
const requiredRole = '1199044634987462708';

if (!userRoles.has(requiredRole)) {
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('У вас нет прав на использование данной команды')
.setThumbnail(interaction.user.displayAvatarURL().toString());
return await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}

const embedOptions = {
color: 0x2d2d31,
title: `Настройка бота`,
description: `Здесь вы можете выбрать интересующие вас настройки.`,
thumbnail: {url: guild.displayAvatarURL().toString()},
}
await interaction.reply({embeds: [embedOptions]});
}
}
const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName('bot')
.setDescription('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.') // Короткое описание
.setNameLocalizations({
ru: 'настройки'
})
.addSubcommand(subcommand =>
subcommand
.setName ('settings')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
.setNameLocalizations({
ru: 'бота'
})
),

async execute(interaction) {
const userRoles = interaction.member.roles.cache;
const requiredRole = '1199044634987462708';

if (!userRoles.has(requiredRole)) {
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('У вас нет прав на использование данной команды')
.setThumbnail(interaction.user.displayAvatarURL().toString());
return await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}

const embedOptions = {
color: 0x2d2d31,
title: `Настройка бота`,
description: `Здесь вы можете выбрать интересующие вас настройки.`,
thumbnail: {url: guild.displayAvatarURL().toString()},
}
await interaction.reply({embeds: [embedOptions]});
}
}
This code of my command command wont show in server, could this be due to the fact that I do not have a file with the main command, but only with a subcommand?
9 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
mallusrgreat
mallusrgreat9mo ago
did you deploy the commands
RushPlayz
RushPlayz9mo ago
yes
/|ĶÎŦÃŖŮ|\
/|ĶÎŦÃŖŮ|\OP9mo ago
What do you mean? If you are wondering whether it is uploaded to the server as an application, then yes.
RushPlayz
RushPlayz9mo ago
do u have main command file?
d.js docs
d.js docs9mo ago
Suggestion for @/|ĶÎŦÃŖŮ|: :guide: Creating Your Bot: Registering slash commands The command deployment script, to register your slash commands with Discord so they appear in the interface. read more
/|ĶÎŦÃŖŮ|\
/|ĶÎŦÃŖŮ|\OP9mo ago
The bot logs its upload as successful. I don’t fully understand how subcommands work, should I have a file with a main command and a subcommand, or can this be implemented in one file. Or the main command file is not required when building subcommands. Maybe there is some example so that I can fully understand how it works?
d.js docs
d.js docs9mo ago
:guide: Slash Commands: Advanced command creation - Subcommands read more
/|ĶÎŦÃŖŮ|\
/|ĶÎŦÃŖŮ|\OP9mo ago
@Qjuh I didn’t understand almost anything in the documentation, it says to combine previous already created commands, I tried creating a command in another file and specifying it as a subcommand in another, but the result is the same. The problem is that it is deployed on the server, according to the console. I just rebooted again, I'll give it time @Qjuh Ok
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) {
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] У команды ${filePath} не найдено "data" или "execute" параметры`);
}
}
}
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) {
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] У команды ${filePath} не найдено "data" или "execute" параметры`);
}
}
}
const rest = new REST().setToken(token);
(async () => {
try {
console.log(`[Log] Начата загрузка ${commands.length} приложения (/) команд.`);
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log(`[Log] Загрузка ${commands.length} приложения (/) команд завершена.`);
} catch (error) {
console.error(error);
}
})();
const rest = new REST().setToken(token);
(async () => {
try {
console.log(`[Log] Начата загрузка ${commands.length} приложения (/) команд.`);
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log(`[Log] Загрузка ${commands.length} приложения (/) команд завершена.`);
} catch (error) {
console.error(error);
}
})();
loging and console output 09.02 15:24:34 [Bot] [Log] Начата загрузка 6 приложения (/) команд. 09.02 15:24:35 [Bot] [Log] Загрузка 6 приложения (/) команд завершена.
const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName ('bot')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
.setNameLocalizations({
ru: 'бота'
}),
async execute(interaction){
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('Данная команда используется только в связке с другой коммандой.')
.setThumbnail(interaction.user.displayAvatarURL().toString());
await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}
}
const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName ('bot')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
.setNameLocalizations({
ru: 'бота'
}),
async execute(interaction){
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('Данная команда используется только в связке с другой коммандой.')
.setThumbnail(interaction.user.displayAvatarURL().toString());
await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}
}
first command file
const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName('settings')
.setDescription('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.') // Короткое описание
.setNameLocalizations({
ru: 'настройки'
})
.addSubcommand(subcommand =>
subcommand
.setName ('bot')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
),
async execute(interaction) {
const userRoles = interaction.member.roles.cache;
const requiredRole = '1199044634987462708';

if (!userRoles.has(requiredRole)) {
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('У вас нет прав на использование данной команды')
.setThumbnail(interaction.user.displayAvatarURL().toString());
return await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}

const embedOptions = {
color: 0x2d2d31,
title: `Настройка бота`,
description: `Здесь вы можете выбрать интересующие вас настройки.`,
thumbnail: {url: guild.displayAvatarURL().toString()},
}
await interaction.reply({embeds: [embedOptions]});
}
}
const {ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Events, SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ModalBuilder, ModalSubmitInteraction, TextInputBuilder, TextInputStyle } = require('discord.js');
const sqlite3 = require('sqlite3').verbose();

module.exports = {
data: new SlashCommandBuilder()
.setName('settings')
.setDescription('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.') // Короткое описание
.setNameLocalizations({
ru: 'настройки'
})
.addSubcommand(subcommand =>
subcommand
.setName ('bot')
.setDescription ('Комнда для настройки бота на сервере, данная команда может быть использована только владельцем.')
),
async execute(interaction) {
const userRoles = interaction.member.roles.cache;
const requiredRole = '1199044634987462708';

if (!userRoles.has(requiredRole)) {
const errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setTitle('Ошибка!')
.setDescription('У вас нет прав на использование данной команды')
.setThumbnail(interaction.user.displayAvatarURL().toString());
return await interaction.reply({embeds: [errorEmbed], ephemeral: true});
}

const embedOptions = {
color: 0x2d2d31,
title: `Настройка бота`,
description: `Здесь вы можете выбрать интересующие вас настройки.`,
thumbnail: {url: guild.displayAvatarURL().toString()},
}
await interaction.reply({embeds: [embedOptions]});
}
}
seccond comand file Success i repair that
Want results from more Discord servers?
Add your server