Registration Request on Startup

I've asked AI as well and for some reason my bot just isn't launching properly. I'm not sure if it's related to discord.js but I'm learning so I might just be stupid. Below is my debug from the console output [DEBUG] Initializing Discord REST client... [DEBUG] Connecting to MongoDB... Connected to MongoDB [DEBUG] Loading commands... [DEBUG] Loading commands from: /home/container/commands [DEBUG] Found command files: aea.js, probationList.js, profile.js, recruit.js, stafftickets.js, training.js [DEBUG] Loading command file: aea.js [DEBUG] Registering command: aea Successfully loaded command: aea [DEBUG] Loading command file: probationList.js [DEBUG] Registering command: probation Successfully loaded command: probation [DEBUG] Loading command file: profile.js [DEBUG] Registering command: profile Successfully loaded command: profile [DEBUG] Loading command file: recruit.js [DEBUG] Registering command: recruit Successfully loaded command: recruit [DEBUG] Loading command file: stafftickets.js [DEBUG] Registering command: ticket Successfully loaded command: ticket [DEBUG] Loading command file: training.js [DEBUG] Registering command: training Successfully loaded command: training [DEBUG] Loaded 6 commands. Preparing for Discord registration... [DEBUG] Using Client ID: [redacted] [DEBUG] Using Guild ID: [redeacted] [DEBUG] Testing Discord API connection... [DEBUG] Discord API test successful [DEBUG] Beginning command registration... [DEBUG] Starting command registration process... [DEBUG] Preparing command registration payload... [DEBUG] Command data being sent: ["aea","probation","profile","recruit","ticket","training"] [DEBUG] Sending registration request to Discord...
53 Replies
d.js toolkit
d.js toolkit2d 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!
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Well that's the thing, I'm not 100% sure. The bot launched fine a day or two ago, then I added a few commands and updated the index.js, and now it just isn't launching properly. [DEBUG] Sending registration request to Discord... it just gets stuck here, when it's fully launched it's meant to say 'Logged into 13th MEU#XXXX' but it doesn't, and my new commands arent registering properly, specifically my promote.js I'm not sure if it's an issue with my index.js or my promote.js
d.js docs
d.js docs2d ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
client
.on("debug", console.log)
.on("warn", console.log)
- Note: if you initialize your Client as bot or other identifiers you need to use these instead of client - If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
VeebS
VeebSOP2d ago
Put this into my index.js, still getting the same output no changes
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
require('dotenv').config();
const path = require('path');
const { Client, GatewayIntentBits, Collection, Partials } = require('discord.js');
const { REST, Routes } = require('discord.js');
const fs = require('fs');
const mongoose = require('mongoose');
const joinHandler = require('./join.js');

// Add debugging
const DEBUG = true;
function debug(msg) {
if (DEBUG) console.log(`[DEBUG] ${msg}`);
}

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});

// Initialize commands collection
client.commands = new Collection();

client
.on("debug", console.log)
.on("warn", console.log);
require('dotenv').config();
const path = require('path');
const { Client, GatewayIntentBits, Collection, Partials } = require('discord.js');
const { REST, Routes } = require('discord.js');
const fs = require('fs');
const mongoose = require('mongoose');
const joinHandler = require('./join.js');

// Add debugging
const DEBUG = true;
function debug(msg) {
if (DEBUG) console.log(`[DEBUG] ${msg}`);
}

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});

// Initialize commands collection
client.commands = new Collection();

client
.on("debug", console.log)
.on("warn", console.log);
I added it under my first few lines, still the same output
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
This output in the console when the bot starts
[DEBUG] Initializing Discord REST client...
[DEBUG] Connecting to MongoDB...
Connected to MongoDB
[DEBUG] Loading commands...
[DEBUG] Loading commands from: /home/container/commands
[DEBUG] Found command files: aea.js, probationList.js, profile.js, recruit.js, stafftickets.js, training.js
[DEBUG] Loading command file: aea.js
[DEBUG] Registering command: aea
Successfully loaded command: aea
[DEBUG] Loading command file: probationList.js
[DEBUG] Registering command: probation
Successfully loaded command: probation
[DEBUG] Loading command file: profile.js
[DEBUG] Registering command: profile
Successfully loaded command: profile
[DEBUG] Loading command file: recruit.js
[DEBUG] Registering command: recruit
Successfully loaded command: recruit
[DEBUG] Loading command file: stafftickets.js
[DEBUG] Registering command: ticket
Successfully loaded command: ticket
[DEBUG] Loading command file: training.js
[DEBUG] Registering command: training
Successfully loaded command: training
[DEBUG] Loaded 6 commands. Preparing for Discord registration...
[DEBUG] Using Client ID: [redacted]
[DEBUG] Using Guild ID: [redeacted]
[DEBUG] Testing Discord API connection...
[DEBUG] Discord API test successful
[DEBUG] Beginning command registration...
[DEBUG] Starting command registration process...
[DEBUG] Preparing command registration payload...
[DEBUG] Command data being sent: ["aea","probation","profile","recruit","ticket","training"]
[DEBUG] Sending registration request to Discord...
[DEBUG] Initializing Discord REST client...
[DEBUG] Connecting to MongoDB...
Connected to MongoDB
[DEBUG] Loading commands...
[DEBUG] Loading commands from: /home/container/commands
[DEBUG] Found command files: aea.js, probationList.js, profile.js, recruit.js, stafftickets.js, training.js
[DEBUG] Loading command file: aea.js
[DEBUG] Registering command: aea
Successfully loaded command: aea
[DEBUG] Loading command file: probationList.js
[DEBUG] Registering command: probation
Successfully loaded command: probation
[DEBUG] Loading command file: profile.js
[DEBUG] Registering command: profile
Successfully loaded command: profile
[DEBUG] Loading command file: recruit.js
[DEBUG] Registering command: recruit
Successfully loaded command: recruit
[DEBUG] Loading command file: stafftickets.js
[DEBUG] Registering command: ticket
Successfully loaded command: ticket
[DEBUG] Loading command file: training.js
[DEBUG] Registering command: training
Successfully loaded command: training
[DEBUG] Loaded 6 commands. Preparing for Discord registration...
[DEBUG] Using Client ID: [redacted]
[DEBUG] Using Guild ID: [redeacted]
[DEBUG] Testing Discord API connection...
[DEBUG] Discord API test successful
[DEBUG] Beginning command registration...
[DEBUG] Starting command registration process...
[DEBUG] Preparing command registration payload...
[DEBUG] Command data being sent: ["aea","probation","profile","recruit","ticket","training"]
[DEBUG] Sending registration request to Discord...
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Where is that output ? Apologies, I'm trying to teach myself all of this lmao
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Oh well yeah thats what im saying... The console output is the same, it doesnt display anything different it is This is the full console output on startup
v21.7.3
:/home/container$ if [[ -d .git ]] && [[ ${AUTO_UPDATE} == "1" ]]; then git pull; fi; if [[ ! -z ${NODE_PACKAGES} ]]; then /usr/local/bin/npm install ${NODE_PACKAGES}; fi; if [[ ! -z ${UNNODE_PACKAGES} ]]; then /usr/local/bin/npm uninstall ${UNNODE_PACKAGES}; fi; if [ -f /home/container/package.json ]; then /usr/local/bin/npm install; fi; /usr/local/bin/node "/home/container/${MAIN_FILE}" ${NODE_ARGS}

up to date, audited 64 packages in 1s

10 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities

up to date, audited 64 packages in 681ms

10 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities
[DEBUG] Initializing Discord REST client...
[DEBUG] Connecting to MongoDB...
Connected to MongoDB
[DEBUG] Loading commands...
[DEBUG] Loading commands from: /home/container/commands
[DEBUG] Found command files: aea.js, probationList.js, profile.js, promote.js, recruit.js, stafftickets.js, training.js
[DEBUG] Loading command file: aea.js
[DEBUG] Registering command: aea
Successfully loaded command: aea
[DEBUG] Loading command file: probationList.js
[DEBUG] Registering command: probation
Successfully loaded command: probation
[DEBUG] Loading command file: profile.js
[DEBUG] Registering command: profile
Successfully loaded command: profile
[DEBUG] Loading command file: promote.js
[DEBUG] Registering command: promote
Successfully loaded command: promote
[DEBUG] Loading command file: recruit.js
[DEBUG] Registering command: recruit
Successfully loaded command: recruit
[DEBUG] Loading command file: stafftickets.js
[DEBUG] Registering command: ticket
Successfully loaded command: ticket
[DEBUG] Loading command file: training.js
[DEBUG] Registering command: training
Successfully loaded command: training
[DEBUG] Loaded 7 commands. Preparing for Discord registration...
[DEBUG] Using Client ID: 1293122744145149982
[DEBUG] Using Guild ID: 943705811576832071
[DEBUG] Testing Discord API connection...
[DEBUG] Discord API test successful
[DEBUG] Beginning command registration...
[DEBUG] Starting command registration process...
[DEBUG] Preparing command registration payload...
[DEBUG] Command data being sent: ["aea","probation","profile","promote","recruit","ticket","training"]
[DEBUG] Sending registration request to Discord...
v21.7.3
:/home/container$ if [[ -d .git ]] && [[ ${AUTO_UPDATE} == "1" ]]; then git pull; fi; if [[ ! -z ${NODE_PACKAGES} ]]; then /usr/local/bin/npm install ${NODE_PACKAGES}; fi; if [[ ! -z ${UNNODE_PACKAGES} ]]; then /usr/local/bin/npm uninstall ${UNNODE_PACKAGES}; fi; if [ -f /home/container/package.json ]; then /usr/local/bin/npm install; fi; /usr/local/bin/node "/home/container/${MAIN_FILE}" ${NODE_ARGS}

up to date, audited 64 packages in 1s

10 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities

up to date, audited 64 packages in 681ms

10 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities
[DEBUG] Initializing Discord REST client...
[DEBUG] Connecting to MongoDB...
Connected to MongoDB
[DEBUG] Loading commands...
[DEBUG] Loading commands from: /home/container/commands
[DEBUG] Found command files: aea.js, probationList.js, profile.js, promote.js, recruit.js, stafftickets.js, training.js
[DEBUG] Loading command file: aea.js
[DEBUG] Registering command: aea
Successfully loaded command: aea
[DEBUG] Loading command file: probationList.js
[DEBUG] Registering command: probation
Successfully loaded command: probation
[DEBUG] Loading command file: profile.js
[DEBUG] Registering command: profile
Successfully loaded command: profile
[DEBUG] Loading command file: promote.js
[DEBUG] Registering command: promote
Successfully loaded command: promote
[DEBUG] Loading command file: recruit.js
[DEBUG] Registering command: recruit
Successfully loaded command: recruit
[DEBUG] Loading command file: stafftickets.js
[DEBUG] Registering command: ticket
Successfully loaded command: ticket
[DEBUG] Loading command file: training.js
[DEBUG] Registering command: training
Successfully loaded command: training
[DEBUG] Loaded 7 commands. Preparing for Discord registration...
[DEBUG] Using Client ID: 1293122744145149982
[DEBUG] Using Guild ID: 943705811576832071
[DEBUG] Testing Discord API connection...
[DEBUG] Discord API test successful
[DEBUG] Beginning command registration...
[DEBUG] Starting command registration process...
[DEBUG] Preparing command registration payload...
[DEBUG] Command data being sent: ["aea","probation","profile","promote","recruit","ticket","training"]
[DEBUG] Sending registration request to Discord...
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
I don't understand why it wouldnt be though
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Is this referencing just within index.js or more-so in every file (commands, models, utils etc)
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Alright 1 sec
VeebS
VeebSOP2d ago
I did that... still pretty much the same output lol
up to date, audited 64 packages in 2s
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities

up to date, audited 64 packages in 687ms
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
[DEBUG] Initializing Discord REST client...
[DEBUG] Connecting to MongoDB...
Connected to MongoDB
[DEBUG] Loading commands...
[DEBUG] Loading commands from: /home/container/commands
[DEBUG] Found command files: aea.js, probationList.js, profile.js, promote.js, recruit.js, stafftickets.js, training.js
[DEBUG] Loading command file: aea.js
[DEBUG] Registering command: aea
Successfully loaded command: aea
[DEBUG] Loading command file: probationList.js
[DEBUG] Registering command: probation
Successfully loaded command: probation
[DEBUG] Loading command file: profile.js
[DEBUG] Registering command: profile
Successfully loaded command: profile
[DEBUG] Loading command file: promote.js
[DEBUG] Registering command: promote
Successfully loaded command: promote
[DEBUG] Loading command file: recruit.js
[DEBUG] Registering command: recruit
Successfully loaded command: recruit
[DEBUG] Loading command file: stafftickets.js
[DEBUG] Registering command: ticket
Successfully loaded command: ticket
[DEBUG] Loading command file: training.js
[DEBUG] Registering command: training
Successfully loaded command: training
Loaded a total of 7 commands
[DEBUG] Loaded 7 commands. Preparing for Discord registration...
[DEBUG] Using Client ID: 1293122744145149982
[DEBUG] Using Guild ID: 943705811576832071
[DEBUG] Testing Discord API connection...
[DEBUG] Discord API test successful
Discord API connection test passed
Discord API connection test passed
[DEBUG] Beginning command registration...
[DEBUG] Starting command registration process...
[DEBUG] Preparing command registration payload...
[DEBUG] Command data being sent: ["aea","probation","profile","promote","recruit","ticket","training"]
[DEBUG] Sending registration request to Discord...
up to date, audited 64 packages in 2s
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities

up to date, audited 64 packages in 687ms
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
[DEBUG] Initializing Discord REST client...
[DEBUG] Connecting to MongoDB...
Connected to MongoDB
[DEBUG] Loading commands...
[DEBUG] Loading commands from: /home/container/commands
[DEBUG] Found command files: aea.js, probationList.js, profile.js, promote.js, recruit.js, stafftickets.js, training.js
[DEBUG] Loading command file: aea.js
[DEBUG] Registering command: aea
Successfully loaded command: aea
[DEBUG] Loading command file: probationList.js
[DEBUG] Registering command: probation
Successfully loaded command: probation
[DEBUG] Loading command file: profile.js
[DEBUG] Registering command: profile
Successfully loaded command: profile
[DEBUG] Loading command file: promote.js
[DEBUG] Registering command: promote
Successfully loaded command: promote
[DEBUG] Loading command file: recruit.js
[DEBUG] Registering command: recruit
Successfully loaded command: recruit
[DEBUG] Loading command file: stafftickets.js
[DEBUG] Registering command: ticket
Successfully loaded command: ticket
[DEBUG] Loading command file: training.js
[DEBUG] Registering command: training
Successfully loaded command: training
Loaded a total of 7 commands
[DEBUG] Loaded 7 commands. Preparing for Discord registration...
[DEBUG] Using Client ID: 1293122744145149982
[DEBUG] Using Guild ID: 943705811576832071
[DEBUG] Testing Discord API connection...
[DEBUG] Discord API test successful
Discord API connection test passed
Discord API connection test passed
[DEBUG] Beginning command registration...
[DEBUG] Starting command registration process...
[DEBUG] Preparing command registration payload...
[DEBUG] Command data being sent: ["aea","probation","profile","promote","recruit","ticket","training"]
[DEBUG] Sending registration request to Discord...
I attachted my index.js if you'd like to see where they are
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
It's functional for all my previous commands, but for the new one promote.js , it just isn't showing up And the reason I thought it was related to index.js is because before (and still) it's meant to send the output Logged in As 13th MEU#xxxx but it doesn't and the last output is it trying to register a request with discord But yes, when i launch it, everything else works except the new command, just a bit confused so I thought I'd ask here
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Well the index.js registers them so yeah i guess?
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Shit... so maybe I'm just being rate limited by discord then?
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Ok so like a /register command that pushes the registration through?
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Same lol
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
How would that script work, would it pretty much be the same as what I have in my index.js? I haven't touched scripts in package.json worried I'd mess it up lmao
d.js docs
d.js docs2d ago
:guide: Creating Your Bot: Registering slash commands read more
VeebS
VeebSOP2d ago
Thanks, and yes I have. Now that I'm looking though the bot isnt actually starting
VeebS
VeebSOP2d ago
No description
VeebS
VeebSOP2d ago
Let me remove the registration sequence and update it as a script and see if that fixes it
VeebS
VeebSOP2d ago
@sïř.jõ 🌈 I don't have a config.json, do i need to add one?
No description
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
gotcha
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
No you're all good, let me do this script and remove the registration from index.js and ill see if that allows the bot to launch properly, i have restarted the BOT A LOT so it couldnt legimately just be rate limitting So do i just put this script below into the 'scripts' section of package.json ? Its saying to create a deploy-commands.js , so which one do i do?
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
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());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
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());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
VeebS
VeebSOP2d ago
Ok thank you ill give it a shot after i eat
Unknown User
Unknown User2d ago
Message Not Public
Sign In & Join Server To View
Amgelo
Amgelo2d ago
if you've already setup your entire logic to register commands on start, you could add an if check for an env variable, like REGISTER_COMMANDS or something or some command line variable that's what I personally do, specially helps if you have user-configured commands
VeebS
VeebSOP20h ago
@sïř.jõ 🌈 The bot launches fine now 🙂 Only thing is, when i type 'npm run deploy' in the console it doesnt do anything
treble/luna
treble/luna20h ago
are you running this in a separate terminal?
VeebS
VeebSOP20h ago
Wdym? I'm just using the normal console
VeebS
VeebSOP20h ago
No description
treble/luna
treble/luna20h ago
yeah thats doing nothing since your bot is running You run that file on your local host Since you only run it when you edit your commands
VeebS
VeebSOP19h ago
I think I understand but please explain cause I'm still learning lmao
treble/luna
treble/luna19h ago
You run the file on your computer, not on your host
VeebS
VeebSOP19h ago
How would that update the commands on the host though?
Want results from more Discord servers?
Add your server