Not a singlecommand working

I got over 10 commands and they were working perfectly , but then they stopped working after i started using mongodb , could anyone help me?
22 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
what code u need ? command handler
function loadCommands(client) {
const ascii = require("ascii-table");
const fs = require("fs");
const table = new ascii().setHeading("Commands", "Status");

let commandsArray = [];

const commandsFolder = fs.readdirSync("./Commands");
for (const folder of commandsFolder) {
const commandFiles = fs
.readdirSync(`./Commands/${folder}`)
.filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
const commandFile = require(`../Commands/${folder}/${file}`);

const properties = { folder, ...commandFile };
client.commands.set(commandFile.data.name, properties);

commandsArray.push(commandFile.data.toJSON());

table.addRow(file, "loaded");
continue;
}
}

client.application.commands.set(commandsArray);

return console.log(table.toString(), "\n Loaded Commands");
}

module.exports = { loadCommands };
function loadCommands(client) {
const ascii = require("ascii-table");
const fs = require("fs");
const table = new ascii().setHeading("Commands", "Status");

let commandsArray = [];

const commandsFolder = fs.readdirSync("./Commands");
for (const folder of commandsFolder) {
const commandFiles = fs
.readdirSync(`./Commands/${folder}`)
.filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
const commandFile = require(`../Commands/${folder}/${file}`);

const properties = { folder, ...commandFile };
client.commands.set(commandFile.data.name, properties);

commandsArray.push(commandFile.data.toJSON());

table.addRow(file, "loaded");
continue;
}
}

client.application.commands.set(commandsArray);

return console.log(table.toString(), "\n Loaded Commands");
}

module.exports = { loadCommands };
handler
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
y
const {
SlashCommandBuilder,
EmbedBuilder,
PermissionFlagsBits,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("embed")
.setDescription("Cria um embed.")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
.addStringOption((option) =>
option
.setName("titulo")
.setDescription("Titulo do embed.")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("descricao")
.setDescription("Descrição do embed.")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("cor")
.setDescription("Cor do embed , deve estar no modelo HEX Color.")
.setRequired(true)
),



async execute(interaction) {
const {channel, options} = interaction;
const title = options.getString("titulo");
const description = options.getString("descricao");
const color = options.getString("cor");

const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setColor(color);

const EmbedSend = await channel.send({ embeds: [embed] });

interaction.reply({ content: "Embed foi mandado", ephemeral: true });
},
};
const {
SlashCommandBuilder,
EmbedBuilder,
PermissionFlagsBits,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("embed")
.setDescription("Cria um embed.")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
.addStringOption((option) =>
option
.setName("titulo")
.setDescription("Titulo do embed.")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("descricao")
.setDescription("Descrição do embed.")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("cor")
.setDescription("Cor do embed , deve estar no modelo HEX Color.")
.setRequired(true)
),



async execute(interaction) {
const {channel, options} = interaction;
const title = options.getString("titulo");
const description = options.getString("descricao");
const color = options.getString("cor");

const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setColor(color);

const EmbedSend = await channel.send({ embeds: [embed] });

interaction.reply({ content: "Embed foi mandado", ephemeral: true });
},
};
one of my commands
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
const { CommandInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",

async execute(interaction, client) {
const { customId, values, guild, member } = interaction; // you need to destructure values from interaction first to use it below
if (interaction.isChatInputCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) {
return interaction.reply({ content: "outdated command" });
}
command.execute(interaction, client);
} else if (interaction.isButton()) {

if (customId == "verify") {
const role = interaction.guild.roles.cache.get("1011041531114815579");
return interaction.member.roles.add(role).then((member) =>
interaction.reply({
content: `${role} has been assigned to you.`,
ephemeral: true,
})
);
}

} else if(interaction.type == InteractionType.ApplicationCommandAutoComplete){
const {commands} = client;
const {commandName} = interaction;
const command = commands.get(commandName);
if (!command) return;

try {
await command.autocomplete(interaction, client)
} catch (err){
console.error(error);
}
}
},
};
const { CommandInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",

async execute(interaction, client) {
const { customId, values, guild, member } = interaction; // you need to destructure values from interaction first to use it below
if (interaction.isChatInputCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) {
return interaction.reply({ content: "outdated command" });
}
command.execute(interaction, client);
} else if (interaction.isButton()) {

if (customId == "verify") {
const role = interaction.guild.roles.cache.get("1011041531114815579");
return interaction.member.roles.add(role).then((member) =>
interaction.reply({
content: `${role} has been assigned to you.`,
ephemeral: true,
})
);
}

} else if(interaction.type == InteractionType.ApplicationCommandAutoComplete){
const {commands} = client;
const {commandName} = interaction;
const command = commands.get(commandName);
if (!command) return;

try {
await command.autocomplete(interaction, client)
} catch (err){
console.error(error);
}
}
},
};
interactioncreate
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
lemme check it does now when i tried starting the bot i gott an mongodb error
Ashura
AshuraOP2y ago
MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/ at Connection.openUri (C:\Users\luizs\Documents\Discord Bot\node_modules\mongoose\lib\connection.js:824:32) at C:\Users\luizs\Documents\Discord Bot\node_modules\mongoose\lib\index.js:412:10 at C:\Users\luizs\Documents\Discord Bot\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5 at new Promise (<anonymous>) at promiseOrCallback (C:\Users\luizs\Documents\Discord Bot\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10) at Mongoose._promiseOrCallback (C:\Users\luizs\Documents\Discord Bot\node_modules\mongoose\lib\index.js:1265:10) at Mongoose.connect (C:\Users\luizs\Documents\Discord Bot\node_modules\mongoose\lib\index.js:411:20) at Object.execute (C:\Users\luizs\Documents\Discord Bot\Events\Client\ready.js:9:24) at Client.<anonymous> (C:\Users\luizs\Documents\Discord Bot\Handlers\eventHandler.js:24:64) at Object.onceWrapper (node:events:628:26)
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
it is whitelisted , thats the problem imma try removing it and adding it again
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
worked commands still not working
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
yep
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
where i place this in my code?°
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
kk , thx
ReferenceError: InteractionType is not defined
at Object.execute (C:\Users\luizs\Documents\Discord Bot\Events\Interactions\interactionCreate.js:27:35)
at Client.<anonymous> (C:\Users\luizs\Documents\Discord Bot\Handlers\eventHandler.js:25:63)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:489:22)
at WebSocketShard.onMessage (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
at callListener (C:\Users\luizs\Documents\Discord Bot\node_modules\ws\lib\event-target.js:290:14)
at WebSocket.onMessage (C:\Users\luizs\Documents\Discord Bot\node_modules\ws\lib\event-target.js:209:9)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v18.12.1
ReferenceError: InteractionType is not defined
at Object.execute (C:\Users\luizs\Documents\Discord Bot\Events\Interactions\interactionCreate.js:27:35)
at Client.<anonymous> (C:\Users\luizs\Documents\Discord Bot\Handlers\eventHandler.js:25:63)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:489:22)
at WebSocketShard.onMessage (C:\Users\luizs\Documents\Discord Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
at callListener (C:\Users\luizs\Documents\Discord Bot\node_modules\ws\lib\event-target.js:290:14)
at WebSocket.onMessage (C:\Users\luizs\Documents\Discord Bot\node_modules\ws\lib\event-target.js:209:9)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v18.12.1
got this error
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
thx so much ily so much
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server