𝙚𝙡𝙮𝙣𝙖𝙧𝙞
𝙚𝙡𝙮𝙣𝙖𝙧𝙞
DIAdiscord.js - Imagine an app
Created by 𝙚𝙡𝙮𝙣𝙖𝙧𝙞 on 9/6/2024 in #djs-questions
Having issues with embed buttons / parsing custom IDs
ahh thank you so much that was it! I add a check for single part customids before it tries to parse it for a context, it works now, I appreciate it!
11 replies
DIAdiscord.js - Imagine an app
Created by 𝙚𝙡𝙮𝙣𝙖𝙧𝙞 on 9/6/2024 in #djs-questions
Having issues with embed buttons / parsing custom IDs
ahh, here I believe:
client.on('interactionCreate', async (interaction) => {
if (interaction.isButton() || interaction.isCommand()) {
try {
if (interaction.isCommand()) {
console.log(`Command interaction received: ${interaction.commandName}`);
await handleCommandInteraction(interaction);
} else if (interaction.isButton()) {
console.log(`Button interaction received: ${interaction.customId}`);

const { action, currentPage, userId, context } = parseCustomId(interaction.customId);

switch (context) {
case 'store':
await handleCyberwareInteraction(interaction, action, currentPage);
break;
case 'unverified':
await handleUnverifiedPagination(interaction, action, currentPage);
break;
case 'profile':
await handleProfileButtonInteraction(interaction, action, userId);
break;
default:
console.error(`Unknown context: ${context}`);
return await interaction.reply({ content: 'An error occurred while processing the button interaction.', ephemeral: true });
}
}
} catch (error) {
console.error(`Error handling interaction: ${error.message}`);
if (!interaction.replied && !interaction.deferred) {
await interaction.reply({ content: '⚠ There was an error while executing this command!', ephemeral: true });
} else if (interaction.deferred) {
await interaction.editReply({ content: '⚠ There was an error while executing this command!', ephemeral: true });
}
}
}
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isButton() || interaction.isCommand()) {
try {
if (interaction.isCommand()) {
console.log(`Command interaction received: ${interaction.commandName}`);
await handleCommandInteraction(interaction);
} else if (interaction.isButton()) {
console.log(`Button interaction received: ${interaction.customId}`);

const { action, currentPage, userId, context } = parseCustomId(interaction.customId);

switch (context) {
case 'store':
await handleCyberwareInteraction(interaction, action, currentPage);
break;
case 'unverified':
await handleUnverifiedPagination(interaction, action, currentPage);
break;
case 'profile':
await handleProfileButtonInteraction(interaction, action, userId);
break;
default:
console.error(`Unknown context: ${context}`);
return await interaction.reply({ content: 'An error occurred while processing the button interaction.', ephemeral: true });
}
}
} catch (error) {
console.error(`Error handling interaction: ${error.message}`);
if (!interaction.replied && !interaction.deferred) {
await interaction.reply({ content: '⚠ There was an error while executing this command!', ephemeral: true });
} else if (interaction.deferred) {
await interaction.editReply({ content: '⚠ There was an error while executing this command!', ephemeral: true });
}
}
}
});
11 replies
DIAdiscord.js - Imagine an app
Created by 𝙚𝙡𝙮𝙣𝙖𝙧𝙞 on 9/6/2024 in #djs-questions
Having issues with embed buttons / parsing custom IDs
if thats what you mean? sorry if i misunderstand
11 replies
DIAdiscord.js - Imagine an app
Created by 𝙚𝙡𝙮𝙣𝙖𝙧𝙞 on 9/6/2024 in #djs-questions
Having issues with embed buttons / parsing custom IDs
here:
async function handleSinglePartCustomId(interaction, action) {

switch (action) {
case 'verify':
await interaction.reply({
content: 'You can send your Year of Birth in chat and wait for a staff member to manually verify you. No need to send any ID or private details.',
ephemeral: true
});
break;
case 'partner':
await interaction.reply({
content: 'For partnerships, please DM <@1256824247515480115> directly. Include your ad and avoid using everyone or here pings.',
ephemeral: true
});
break;
case 'giveaway':
await interaction.reply({
content: 'Congratulations! Please wait for a staff member to assist you with your giveaway claim.',
ephemeral: true
});
break;
case 'suggestion':
await interaction.reply({
content: 'Please write your suggestion, and a staff member will review it shortly.',
ephemeral: true
});
break;
default:
console.error(`Unknown action for single-part customId: ${action}`);
await interaction.reply({ content: '⚠ Unknown action.', ephemeral: true });
}
}
async function handleSinglePartCustomId(interaction, action) {

switch (action) {
case 'verify':
await interaction.reply({
content: 'You can send your Year of Birth in chat and wait for a staff member to manually verify you. No need to send any ID or private details.',
ephemeral: true
});
break;
case 'partner':
await interaction.reply({
content: 'For partnerships, please DM <@1256824247515480115> directly. Include your ad and avoid using everyone or here pings.',
ephemeral: true
});
break;
case 'giveaway':
await interaction.reply({
content: 'Congratulations! Please wait for a staff member to assist you with your giveaway claim.',
ephemeral: true
});
break;
case 'suggestion':
await interaction.reply({
content: 'Please write your suggestion, and a staff member will review it shortly.',
ephemeral: true
});
break;
default:
console.error(`Unknown action for single-part customId: ${action}`);
await interaction.reply({ content: '⚠ Unknown action.', ephemeral: true });
}
}
11 replies
DIAdiscord.js - Imagine an app
Created by 𝙚𝙡𝙮𝙣𝙖𝙧𝙞 on 9/6/2024 in #djs-questions
Having issues with embed buttons / parsing custom IDs
[email protected] Node.js v20.16.0.
11 replies