The application did not respond

Why are the commands not working. I fixed it earlier but after some editing on the code it doesn't work anymore.
No description
23 Replies
d.js toolkit
d.js toolkit3w 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!
AzcenD
AzcenD3w ago
index.js
const {token} = require('./config.json');
const {Client, Events, GatewayIntentBits, Collection} = require ('discord.js');

const fs = require('node:fs');
const path = require('node:path');

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

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);

if(event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}

client.login(token);
const {token} = require('./config.json');
const {Client, Events, GatewayIntentBits, Collection} = require ('discord.js');

const fs = require('node:fs');
const path = require('node:path');

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

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);

if(event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}

client.login(token);
deploy-commands.js
const fs = require('node:fs');
const path = require('node:path');
const {REST} = require('@discordjs/rest');
const {Routes} = require('discord.js');
const {clientId, guildId, token} = require('./config.json');

function getFiles(dir) {
const files = fs.readdirSync(dir, {
withFileTypes: true
});
let commandFiles = [];

for (const file of files) {
if(file.isDirectory()){
commandFiles = [
...commandFiles,
...getFiles(`${dir}/${file.name}`),
]
} else if (file.name.endsWith(".js")) {
commandFiles.push(`${dir}/${file.name}`);
}
}

return commandFiles;
}

let commands = [];
const commandFiles = getFiles('./commands');

for (const file of commandFiles) {
const command = require(file);
commands.push(command.data.toJSON());
}

const rest = new REST({verson: '10'}).setToken(token);

rest.put(Routes.applicationGuildCommands(clientId, guildId), {body: commands})
.then(() => console.log('Secessfully registered application commands!'))
.catch(console.error);
const fs = require('node:fs');
const path = require('node:path');
const {REST} = require('@discordjs/rest');
const {Routes} = require('discord.js');
const {clientId, guildId, token} = require('./config.json');

function getFiles(dir) {
const files = fs.readdirSync(dir, {
withFileTypes: true
});
let commandFiles = [];

for (const file of files) {
if(file.isDirectory()){
commandFiles = [
...commandFiles,
...getFiles(`${dir}/${file.name}`),
]
} else if (file.name.endsWith(".js")) {
commandFiles.push(`${dir}/${file.name}`);
}
}

return commandFiles;
}

let commands = [];
const commandFiles = getFiles('./commands');

for (const file of commandFiles) {
const command = require(file);
commands.push(command.data.toJSON());
}

const rest = new REST({verson: '10'}).setToken(token);

rest.put(Routes.applicationGuildCommands(clientId, guildId), {body: commands})
.then(() => console.log('Secessfully registered application commands!'))
.catch(console.error);
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
interactionCtreate.js
const {Client, Collection, GatewayIntentBits} = require('discord.js');
const fs = require('node:fs');
const client = new Client({intents: [GatewayIntentBits.Guilds]});

client.commands = getCommands('./commands');

module.exports = {
name: 'interactionCreate',

async execute(interaction) {
if (!interaction.isChatInputCommand())
return;

let command = client.commands.get(!interaction.commandName);

try{
if (interaction.replied)
return;
} catch (error) {
console.error(error);
}

command.execute(interaction);
}
}

function getCommands(dir) {
let commands = new Collection();
const commandFiles = getFiles(dir);

for(const commandFile of commandFiles) {
const command = require("." + commandFile);
commands.set(command.data.toJSON().name, command);
}

return commands;
}

function getFiles(dir) {
const files = fs.readdirSync(dir, {
withFileTypes: true
});
let commandFiles = [];

for (const file of files) {
if(file.isDirectory()){
commandFiles = [
...commandFiles,
...getFiles(`${dir}/${file.name}`),
]
} else if (file.name.endsWith(".js")) {
commandFiles.push(`${dir}/${file.name}`);
}
}

return commandFiles;
}
const {Client, Collection, GatewayIntentBits} = require('discord.js');
const fs = require('node:fs');
const client = new Client({intents: [GatewayIntentBits.Guilds]});

client.commands = getCommands('./commands');

module.exports = {
name: 'interactionCreate',

async execute(interaction) {
if (!interaction.isChatInputCommand())
return;

let command = client.commands.get(!interaction.commandName);

try{
if (interaction.replied)
return;
} catch (error) {
console.error(error);
}

command.execute(interaction);
}
}

function getCommands(dir) {
let commands = new Collection();
const commandFiles = getFiles(dir);

for(const commandFile of commandFiles) {
const command = require("." + commandFile);
commands.set(command.data.toJSON().name, command);
}

return commands;
}

function getFiles(dir) {
const files = fs.readdirSync(dir, {
withFileTypes: true
});
let commandFiles = [];

for (const file of files) {
if(file.isDirectory()){
commandFiles = [
...commandFiles,
...getFiles(`${dir}/${file.name}`),
]
} else if (file.name.endsWith(".js")) {
commandFiles.push(`${dir}/${file.name}`);
}
}

return commandFiles;
}
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
ready.js
module.exports = {
name: 'ready',
once: true,

async execute(client) {
console.log(`Logged in as ${client.user.username}`);
}
}
module.exports = {
name: 'ready',
once: true,

async execute(client) {
console.log(`Logged in as ${client.user.username}`);
}
}
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
hello.js
const { AutoModerationActionExecution } = require("discord.js");

const {SlashCommandBuilder} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('hello')
.setDescription('Says hello to someone')
.addUserOption(option =>
option
.setName('user')
.setDescription('The use to say hello to')
.setRequired(false)
),

async execute(interaction) {
const user = interaction.options.getUser("user") || interaction.user;
interaction.reply(`Hello ${interaction.user.username}!`)
}
}
const { AutoModerationActionExecution } = require("discord.js");

const {SlashCommandBuilder} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('hello')
.setDescription('Says hello to someone')
.addUserOption(option =>
option
.setName('user')
.setDescription('The use to say hello to')
.setRequired(false)
),

async execute(interaction) {
const user = interaction.options.getUser("user") || interaction.user;
interaction.reply(`Hello ${interaction.user.username}!`)
}
}
Svitkona
Svitkona3w ago
it looks like you're creating a new Client in interactionCreate.js ?
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs3w ago
:guide: Creating Your Bot: Event handling read more :guide: Creating Your Bot: Command handling read more
AzcenD
AzcenD3w ago
oh yeah missed that i just looked at the guide and their was a new client there as well
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
how do i import the already initialized client And how do i pass it into the file?
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
no i have not used javascript earlier
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
I have played around with c++ and c# earlier c++ was my first language i used to learn basic programming and making game in UE and c# to make games in unity
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
where can i find those
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View
AzcenD
AzcenD3w ago
I guess i will just learn some basic Javascript instead the support for it is clearly bigger
Unknown User
Unknown User3w ago
Message Not Public
Sign In & Join Server To View