listening to buttons...

this is the handler for components that i use, but i want to be able to listen to buttons also only by the first argument in the array of their customId.split('_')[0]. handler https://sourceb.in/TjIgnV1V9u interactionCreate event https://sourceb.in/4W7NWPrkV7 button module example https://sourceb.in/DIOCZiJsIF message send command https://sourceb.in/CiELYf68Re
4 Replies
d.js toolkit
d.js toolkit14mo 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! - Marked as resolved by OP
Massicraft
MassicraftOP14mo ago
? in this case, for example, i want to be able to listen to both the buttons with customId 'prova_1' and 'prova2' by listening to 'prova' so `const component = client.collection.components.buttons.get(interaction.customId).split('')[0];` ? ? so
const customId = interaction.customId.split(‘_’)[0]
const component = client.collection.components.buttons.get(customId);
const customId = interaction.customId.split(‘_’)[0]
const component = client.collection.components.buttons.get(customId);
?
ْكِج
ْكِج14mo ago
I would first ensure that the customId has "_" if I were you
Massicraft
MassicraftOP14mo ago
obviously infact i want to be able to listen also to buttons with normal custom ids however, how to do that? @Qjuh so is this correct ? ok thanks yeah and it doesn’t work TypeError: Cannot read properties of undefined (reading 'split') no same error i tried both btw
const config = require('../../config');
const { log } = require('../../functions');
const ExtendedClient = require('../../class/ExtendedClient');

module.exports = {
event: 'interactionCreate',
/**
*
* @param {ExtendedClient} client
* @param {import('discord.js').Interaction} interaction
* @returns
*/
run: (client, interaction) => {

if (interaction.isButton()) {
const customId = interaction.customId.split('_')[0];

const component = client.collection.components.buttons.get(customId);
if (!component) return;

try {
component.run(client, interaction);
} catch (error) {
log(error, 'error');
};

return;
};
const config = require('../../config');
const { log } = require('../../functions');
const ExtendedClient = require('../../class/ExtendedClient');

module.exports = {
event: 'interactionCreate',
/**
*
* @param {ExtendedClient} client
* @param {import('discord.js').Interaction} interaction
* @returns
*/
run: (client, interaction) => {

if (interaction.isButton()) {
const customId = interaction.customId.split('_')[0];

const component = client.collection.components.buttons.get(customId);
if (!component) return;

try {
component.run(client, interaction);
} catch (error) {
log(error, 'error');
};

return;
};
ok so it works but i want, when executing the button, to be able to get the other arguments in the button customid array it wasnt working bc i put this in the button file ${interaction.customI.split('')[1]} in this case it has a indeed the customid infact is prova_1 ok fixed thank you very much
Want results from more Discord servers?
Add your server