my bot cannot be connect to discord

I am doing my first bot, and my first command, but my bot do an error when i execute my command
26 Replies
d.js toolkit
d.js toolkit2y 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!
treble/luna
treble/luna2y ago
can you show that error too and your code
Cat²
Cat²OP2y ago
ok
const fs = require('node:fs');
const path = require('node:path');

const { Client, Events, GatewayIntentBits, Collection } = require('discord.js');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const { token } = require('./config.json');

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

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);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}




}

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.on(Events.InteractionCreate, interaction => {
if (!interaction.isChatInputCommand()) return;
console.log(interaction)
});



client.login(token);
const fs = require('node:fs');
const path = require('node:path');

const { Client, Events, GatewayIntentBits, Collection } = require('discord.js');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const { token } = require('./config.json');

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

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);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}




}

client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.on(Events.InteractionCreate, interaction => {
if (!interaction.isChatInputCommand()) return;
console.log(interaction)
});



client.login(token);
, but i don't have error, i just have the message Couldn't connect to Discord via RPC: Error: Could not connect comment faire
treble/luna
treble/luna2y ago
can you show the error and did you deploy your commands?
Cat²
Cat²OP2y ago
I don't have an error.
treble/luna
treble/luna2y ago
or well the message you get
Cat²
Cat²OP2y ago
Couldn't connect to discord via RCP: error: could not connect The application don't work
treble/luna
treble/luna2y ago
did you deploy your commands and that message you get doesnt seem to come from this code
Cat²
Cat²OP2y ago
I try
treble/luna
treble/luna2y ago
do you get any 'read, logged in as ....' message?
Cat²
Cat²OP2y ago
That not come from the code, just my bot and discord I think. Because my bot is online but the command don't reply to my slash
treble/luna
treble/luna2y ago
. if thats all the code you have, i am assuming you do not in which case
d.js docs
d.js docs2y ago
guide Creating Your Bot: Registering slash commands read more
treble/luna
treble/luna2y ago
follow that
Cat²
Cat²OP2y ago
Ok I see the success message but the command don't work
treble/luna
treble/luna2y ago
define dont work does the command show up at all?
Cat²
Cat²OP2y ago
i can chose the command but she not work
treble/luna
treble/luna2y ago
well in the above code you dont have any code that replies to the command so yes, it will indeed not work, other than logging the interaction
Cat²
Cat²OP2y ago
ok but how can i fix it
treble/luna
treble/luna2y ago
by writing code to reply to it
Cat²
Cat²OP2y ago
ok
treble/luna
treble/luna2y ago
i assume you followed the guide up until this point, just keep following
Cat²
Cat²OP2y ago
ok I have the message
the app is not responding
the app is not responding
on my discord server
treble/luna
treble/luna2y ago
and do you reply to the interaction
invictus
invictus2y ago
Continue the code, bro. All you did is just logging the interaction.
Cat²
Cat²OP2y ago
Okk

Did you find this page helpful?