Bot will not push new commands to server

Cant access commands I make froem the server.
14 Replies
d.js toolkit
d.js toolkit10mo 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!
jibz
jibzOP10mo ago
No errors, command is pushed and printing saying it sucessfully is working. But wont show up when i press /
Mark
Mark10mo ago
show code reload discord
jibz
jibzOP10mo ago
oh still nothing wait
const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed, Collection } = require(`discord.js`);
const fs = require('fs');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers] });

client.commands = new Collection();

require('dotenv').config();

const functions = fs.readdirSync("./functions").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./commands");



(async () => {
for (file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, "./events");
client.handleCommands(commandFolders, "./commands");
})();

client.login(".nonononoonon.bny")
const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed, Collection } = require(`discord.js`);
const fs = require('fs');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers] });

client.commands = new Collection();

require('dotenv').config();

const functions = fs.readdirSync("./functions").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./commands");



(async () => {
for (file of functions) {
require(`./functions/${file}`)(client);
}
client.handleEvents(eventFiles, "./events");
client.handleCommands(commandFolders, "./commands");
})();

client.login(".nonononoonon.bny")
Mark
Mark10mo ago
this does not show how you deploy commands to discord (if it does at all)
jibz
jibzOP10mo ago
what code do u want to see handle commands?
handlecommands.js

const { REST } = require("@discordjs/rest");
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');

const clientId = '1214333260960628817';
const guildId = '1214331914769670154';

module.exports = (client) => {
client.handleCommands = async (commandFolders, path) => {
client.commandArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
console.log(`${command.data.name} pushed`)
client.commands.set(command.data.name, command);
client.commandArray.push(command.data.toJSON());
}
}

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

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

await rest.put(
Routes.applicationCommands(clientId), {
body: client.commandArray
},
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
};
};
handlecommands.js

const { REST } = require("@discordjs/rest");
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');

const clientId = '1214333260960628817';
const guildId = '1214331914769670154';

module.exports = (client) => {
client.handleCommands = async (commandFolders, path) => {
client.commandArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
console.log(`${command.data.name} pushed`)
client.commands.set(command.data.name, command);
client.commandArray.push(command.data.toJSON());
}
}

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

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

await rest.put(
Routes.applicationCommands(clientId), {
body: client.commandArray
},
);

console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
};
};
Mark
Mark10mo ago
don't post your token, even in an image
jibz
jibzOP10mo ago
oh crap this is the code yeah it is
Mark
Mark10mo ago
you should not be deploying commands on every login, you could be hitting a ratelimit for command deployment. do you see one, both, or none of the console.log() statements in the try block
jibz
jibzOP10mo ago
Oh wait.. I had my process.env.token oh my fucking god im an idiot.. i moved from repl forgot to change that lemme see if :/
Mark
Mark10mo ago
you should modify your deployment to not deploy commands on every login
jibz
jibzOP10mo ago
where should i put it its fixed btw ty
Mark
Mark10mo ago
in a separate script that you call manually when you need to send new data to discord
jibz
jibzOP10mo ago
ok thx
Want results from more Discord servers?
Add your server