StellarFr0st
StellarFr0st
DIAdiscord.js - Imagine an app
Created by StellarFr0st on 11/25/2024 in #djs-questions
Slash commands not working
So I have registered my / commands and when I type them, I have a console log to show that it has received the interaction and which one was executed, but it doesn't actually execute the commands. This is my interactionCreate handler
const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
console.log(`Interaction received: ${interaction.commandName}`);
if (interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command found for ${interaction.commandName}`);
return;
}

try {
await command.execute(interaction);
} catch (e) {
console.error(`Error executing command ${interaction.commandName}: ${e}`);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'An error occurred while executing the command.', ephmeral: true });
} else {
await interaction.reply({ content: 'An error occurred while executing the command.', ephmeral: true });
}
}
},
}
const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
console.log(`Interaction received: ${interaction.commandName}`);
if (interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command found for ${interaction.commandName}`);
return;
}

try {
await command.execute(interaction);
} catch (e) {
console.error(`Error executing command ${interaction.commandName}: ${e}`);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'An error occurred while executing the command.', ephmeral: true });
} else {
await interaction.reply({ content: 'An error occurred while executing the command.', ephmeral: true });
}
}
},
}
and this is my event handler
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, async (...args) => await event.execute(...args));
}
}
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, async (...args) => await event.execute(...args));
}
}
7 replies
DIAdiscord.js - Imagine an app
Created by StellarFr0st on 5/24/2024 in #djs-questions
Help with OAuth
Hey, im trying to get oauth working but i cannot figure out whats gone wrong. im using html and php to do this but i think ive done something wrong somewhere. HTML code: https://pastebin.com/vtziBY47 JS code: https://pastebin.com/HSjpmrTn PHP code: https://pastebin.com/d18rkuJj and i get this when i press authorize on the discord login page
<br />
<b>Warning</b>: Undefined array key "access_token" in <b>/var/www/landing/php/oauth.php</b> on line <b>31</b><br />
<br />
<b>Warning</b>: Undefined array key "username" in <b>/var/www/landing/php/oauth.php</b> on line <b>49</b><br />
<br />
<b>Warning</b>: Undefined array key "id" in <b>/var/www/landing/php/oauth.php</b> on line <b>50</b><br />
{"username":null,"id":null}
<br />
<b>Warning</b>: Undefined array key "access_token" in <b>/var/www/landing/php/oauth.php</b> on line <b>31</b><br />
<br />
<b>Warning</b>: Undefined array key "username" in <b>/var/www/landing/php/oauth.php</b> on line <b>49</b><br />
<br />
<b>Warning</b>: Undefined array key "id" in <b>/var/www/landing/php/oauth.php</b> on line <b>50</b><br />
{"username":null,"id":null}
i honestly dont know what i could've done wrong
6 replies