tate.b
tate.b
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
It works now
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
You are amazing!! Thanks for helping me!
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
It is run mostly on objects
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
const { REST, Routes } = require('discord.js');
const { devs, testServer, clientId } = require("../../../config.json");
const getLocalCommands = require("../../utils/getLocalCommands");

module.exports = async (client, interaction) => {


// Register commands on startup
/*if (!client.commandsRegistered) {
const localCommands = getLocalCommands();

const commands = localCommands.map((cmd) => ({
name: cmd.name,
description: cmd.description,
options: cmd.options || [],
default_permission: true,
}));

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(clientId), // For global commands
// Routes.applicationGuildCommands(clientId, testServer), // Uncomment this for guild-specific commands
{ body: commands }
);

console.log('Successfully reloaded application (/) commands.');
client.commandsRegistered = true; // Mark as registered to avoid re-registering
} catch (error) {
console.error('Error registering commands globally:', error);
}
}*/

// Handle modals and select menus


// Handle slash commands
if (!interaction.isChatInputCommand()) return;

const localCommands = getLocalCommands();

try {
const commandObject = localCommands.find(
(cmd) => cmd.name === interaction.commandName
);

if (!commandObject) return;

if (commandObject.devOnly) {
if (!devs.includes(interaction.member.id)) {
interaction.reply({
content: "Only developers are allowed to run this command.",
ephemeral: true,
});
return;
}
}

if (commandObject.testOnly) {
if (!(interaction.guild.id === testServer)) {
interaction.reply({
content: "This command cannot be ran here.",
ephemeral: true,
});
return;
}
}

if (commandObject.permissionsRequired?.length) {
for (const permission of commandObject.permissionsRequired) {
if (!interaction.member.permissions.has(permission)) {
interaction.reply({
content: "Not enough permissions.",
ephemeral: true,
});
return;
}
}
}

if (commandObject.botPermissions?.length) {
for (const permission of commandObject.botPermissions) {
const bot = interaction.guild.members.me;

if (!bot.permissions.has(permission)) {
interaction.reply({
content: "Designy doesn't have enough permissions to run this command.",
ephemeral: true,
});
return;
}
}
}


await commandObject.callback(client, interaction);

} catch (error) {
console.log(`There was an error running this command: ${error}.`);
}
};
const { REST, Routes } = require('discord.js');
const { devs, testServer, clientId } = require("../../../config.json");
const getLocalCommands = require("../../utils/getLocalCommands");

module.exports = async (client, interaction) => {


// Register commands on startup
/*if (!client.commandsRegistered) {
const localCommands = getLocalCommands();

const commands = localCommands.map((cmd) => ({
name: cmd.name,
description: cmd.description,
options: cmd.options || [],
default_permission: true,
}));

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

try {
console.log('Started refreshing application (/) commands.');

await rest.put(
Routes.applicationCommands(clientId), // For global commands
// Routes.applicationGuildCommands(clientId, testServer), // Uncomment this for guild-specific commands
{ body: commands }
);

console.log('Successfully reloaded application (/) commands.');
client.commandsRegistered = true; // Mark as registered to avoid re-registering
} catch (error) {
console.error('Error registering commands globally:', error);
}
}*/

// Handle modals and select menus


// Handle slash commands
if (!interaction.isChatInputCommand()) return;

const localCommands = getLocalCommands();

try {
const commandObject = localCommands.find(
(cmd) => cmd.name === interaction.commandName
);

if (!commandObject) return;

if (commandObject.devOnly) {
if (!devs.includes(interaction.member.id)) {
interaction.reply({
content: "Only developers are allowed to run this command.",
ephemeral: true,
});
return;
}
}

if (commandObject.testOnly) {
if (!(interaction.guild.id === testServer)) {
interaction.reply({
content: "This command cannot be ran here.",
ephemeral: true,
});
return;
}
}

if (commandObject.permissionsRequired?.length) {
for (const permission of commandObject.permissionsRequired) {
if (!interaction.member.permissions.has(permission)) {
interaction.reply({
content: "Not enough permissions.",
ephemeral: true,
});
return;
}
}
}

if (commandObject.botPermissions?.length) {
for (const permission of commandObject.botPermissions) {
const bot = interaction.guild.members.me;

if (!bot.permissions.has(permission)) {
interaction.reply({
content: "Designy doesn't have enough permissions to run this command.",
ephemeral: true,
});
return;
}
}
}


await commandObject.callback(client, interaction);

} catch (error) {
console.log(`There was an error running this command: ${error}.`);
}
};
This is my command handler file, the callback is at the bottom.
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
Okay!
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
Would it be easier if I were to say I have many subcommand commands and it always works, this is an odd case or do you need to see it?
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
yes
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
20.18.03
14 replies
DIAdiscord.js - Imagine an app
Created by tate.b on 10/28/2024 in #djs-questions
I am getting this error when the snippet is right.
14.16.3
14 replies