Lixeiro Charmoso
Lixeiro Charmoso
DIAdiscord.js - Imagine an app
Created by Lixeiro Charmoso on 7/29/2024 in #djs-questions
How to get attachments from a message?
Hey, i'm recently having some issues with attachments. I want to get the attachment that an user uploaded and then resend in through the bot. I have this code which used to work, but in the last months it stopped working
let files = msg.attachments.map((obj) => new AttachmentBuilder(obj.proxyURL))
console.log(files)
channel.send({ content: `xxx`, embeds: [Embed], components: [Buttons], files: files });
let files = msg.attachments.map((obj) => new AttachmentBuilder(obj.proxyURL))
console.log(files)
channel.send({ content: `xxx`, embeds: [Embed], components: [Buttons], files: files });
The log from console.log
[
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842175291496/Screenshot_1.png?ex=66a93325&is=66a7e1a5&hm=6c87f01db84a1c96ea
344fa4775eb54ed5542a554f9e896712b7d9cea0c10c91&',
name: undefined,
description: undefined
},
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842527871068/image.png?ex=66a93325&is=66a7e1a5&hm=3056040ffca4396f5d957f522
71659be379dd00a3cc02811ecb0fb70a7257d65&',
name: undefined,
description: undefined
}
]
[
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842175291496/Screenshot_1.png?ex=66a93325&is=66a7e1a5&hm=6c87f01db84a1c96ea
344fa4775eb54ed5542a554f9e896712b7d9cea0c10c91&',
name: undefined,
description: undefined
},
AttachmentBuilder {
attachment: 'https://media.discordapp.net/attachments/1267551776593150105/12
67551842527871068/image.png?ex=66a93325&is=66a7e1a5&hm=3056040ffca4396f5d957f522
71659be379dd00a3cc02811ecb0fb70a7257d65&',
name: undefined,
description: undefined
}
]
5 replies
DIAdiscord.js - Imagine an app
Created by Lixeiro Charmoso on 2/1/2024 in #djs-questions
Is possible to trigger an ephemeral message without setting "ephemeral: true"?
I'm having some strange behaviours from my bot recently and i'm not having idea what is happening. Right now an user sent me this screenshot: https://cdn.discordapp.com/attachments/821436197745197086/1202546935957946409/Screenshot_2024-02-01-10-31-34-07_572064f74bd5f9fa804b05334aa4f912.jpg In this screenshot that second message "To open a support ticket....." is a ephemeral message to him, right? BUT WHY? Below is the snippet that generates this message, there is nothing about ephemeral. Also, if i try myself, i cannot reproduce this behavior (i've tried in many ways). The correct behavior is: when user choose something in this select menu, this message is deleted and after the deletion it shows the next message "Paste here the tbx ID.....".
if (i.customId == "startuser"){
const coupons = await client.db.query('SELECT * FROM coupons WHERE is_active = 1 AND expire_date >= NOW() ORDER BY id DESC LIMIT 1');
const Options = new ActionRowBuilder();
const selectMenuBuilder = new StringSelectMenuBuilder()
.setCustomId('select')
.setPlaceholder('➡️ Click here to select action...');

if (coupons.length > 0) {
selectMenuBuilder.addOptions([
{
label: 'Redeem Coupon',
description: 'Redeem your coupon code for ' + coupons[0].script_name,
value: 'redeemCoupon',
emoji: `💰`
},
]);
}

selectMenuBuilder.addOptions([
{
label: 'Support Ticket',
description: 'Select here if you have purchased a product',
value: 'flux1',
emoji: `☎`
},
{
label: 'Purchase Ticket',
description: 'Select here if you have questions before purchasing a script',
value: 'flux2',
emoji: `💸`
},
{
label: 'Claim Customer Role',
description: 'Select here if you want to receive the customer role',
value: 'claimrole',
emoji: `🔴`
},
]);

Options.addComponents(selectMenuBuilder);

const Embed = new EmbedBuilder()
.setColor(client.config.mainColor)
.setDescription(`To open a support ticket select one of the options below to proceed.`)
.setFooter({text: 'You have 3 minutes to choose!'})
await i.reply({embeds: [Embed], components: [Options]})
await Buttons.components[0].setDisabled(true);
await i.message.edit({components: [Buttons]})

const collectorBack = channel.createMessageComponentCollector({ componentType: ComponentType.StringSelect, max: 1, time: client.config.msTimeToInteractWithButtons });
collectorBack.on('end', (collected, reason) => {
Utils.deleteChannel(collected, reason, channel, client, member.id);
});
}
if (i.customId == "startuser"){
const coupons = await client.db.query('SELECT * FROM coupons WHERE is_active = 1 AND expire_date >= NOW() ORDER BY id DESC LIMIT 1');
const Options = new ActionRowBuilder();
const selectMenuBuilder = new StringSelectMenuBuilder()
.setCustomId('select')
.setPlaceholder('➡️ Click here to select action...');

if (coupons.length > 0) {
selectMenuBuilder.addOptions([
{
label: 'Redeem Coupon',
description: 'Redeem your coupon code for ' + coupons[0].script_name,
value: 'redeemCoupon',
emoji: `💰`
},
]);
}

selectMenuBuilder.addOptions([
{
label: 'Support Ticket',
description: 'Select here if you have purchased a product',
value: 'flux1',
emoji: `☎`
},
{
label: 'Purchase Ticket',
description: 'Select here if you have questions before purchasing a script',
value: 'flux2',
emoji: `💸`
},
{
label: 'Claim Customer Role',
description: 'Select here if you want to receive the customer role',
value: 'claimrole',
emoji: `🔴`
},
]);

Options.addComponents(selectMenuBuilder);

const Embed = new EmbedBuilder()
.setColor(client.config.mainColor)
.setDescription(`To open a support ticket select one of the options below to proceed.`)
.setFooter({text: 'You have 3 minutes to choose!'})
await i.reply({embeds: [Embed], components: [Options]})
await Buttons.components[0].setDisabled(true);
await i.message.edit({components: [Buttons]})

const collectorBack = channel.createMessageComponentCollector({ componentType: ComponentType.StringSelect, max: 1, time: client.config.msTimeToInteractWithButtons });
collectorBack.on('end', (collected, reason) => {
Utils.deleteChannel(collected, reason, channel, client, member.id);
});
}
13 replies
DIAdiscord.js - Imagine an app
Created by Lixeiro Charmoso on 12/17/2023 in #djs-questions
How to create a button with permission
No description
11 replies
DIAdiscord.js - Imagine an app
Created by Lixeiro Charmoso on 5/16/2023 in #djs-questions
Import client variable in a SlashCommandBuilder function
Hello, i'm trying to use the client variable inside a command but its not accessible.
20 replies
DIAdiscord.js - Imagine an app
Created by Lixeiro Charmoso on 3/29/2023 in #djs-questions
New error magically appeared xD
About to 40 minutes ago my bot crashed with a very uncommon error. Then tried to restart it and now it keeps crashing with same error. No changes in code were made, so my first thought is that discord updated something in his API. Here is the error code
C:\Users\Leona\Desktop\dashboard_bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:50
if (channel && !channel.isTextBased()) return;
^

TypeError: channel.isTextBased is not a function
at InteractionCreateAction.handle (C:\Users\Leona\Desktop\dashboard_bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:50:33)
at Object.module.exports [as INTERACTION_CREATE] (C:\Users\Leona\Desktop\dashboard_bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
C:\Users\Leona\Desktop\dashboard_bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:50
if (channel && !channel.isTextBased()) return;
^

TypeError: channel.isTextBased is not a function
at InteractionCreateAction.handle (C:\Users\Leona\Desktop\dashboard_bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:50:33)
at Object.module.exports [as INTERACTION_CREATE] (C:\Users\Leona\Desktop\dashboard_bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
Anyone knows what could happened? The error is inside the node modules
52 replies
DIAdiscord.js - Imagine an app
Created by Lixeiro Charmoso on 2/4/2023 in #djs-questions
Clean code without nesting on('collect'
I'm trying to get 5 sequential infos from the user but the only way to do that was nesting a lot of callbacks. Is there another way to do it without nesting and without using forms? Example code:
try {

const cbResourceName = channel.createMessageComponentCollector({ filter: filterResourceName, componentType: ComponentType.StringSelect, time: 300000, max: 1 });

cbResourceName.on('end', collected => {
interaction.deleteReply().catch((e) => {})
});

cbResourceName.on('collect', async (userMsgResourceName) => {

const cbVersion = interaction.channel.createMessageCollector({ filter: filterVersion, max: 1,time: 300000 });

cbVersion.on('end', collected => {
botMsgVersion.delete().catch(e => {});
});

cbVersion.on('collect', async (userVersion) => {

const csChangelog = interaction.channel.createMessageCollector({ filter: filterChangelog, max: 1,time: 300000 });

csChangelog.on('end', collected => {
botMsgChangelog.delete().catch(e => {});
});

csChangelog.on('collect', async (userMsgChangelog) => {

const cbChanges = interaction.channel.createMessageCollector({ filter: filterChanges, max: 1,time: 300000 });

cbChanges.on('end', collected => {
botMsgChanges.delete().catch(e => {});
});

cbChanges.on('collect', async (userMsgChanges) => {

const csImgLink = interaction.channel.createMessageCollector({ filter: filterImgLink, max: 1,time: 300000 });

csImgLink.on('end', collected => {
botMsgImgLink.delete().catch(e => {});
});

csImgLink.on('collect', async (userMsgImgLink) => {

})
})
})
})
})
try {

const cbResourceName = channel.createMessageComponentCollector({ filter: filterResourceName, componentType: ComponentType.StringSelect, time: 300000, max: 1 });

cbResourceName.on('end', collected => {
interaction.deleteReply().catch((e) => {})
});

cbResourceName.on('collect', async (userMsgResourceName) => {

const cbVersion = interaction.channel.createMessageCollector({ filter: filterVersion, max: 1,time: 300000 });

cbVersion.on('end', collected => {
botMsgVersion.delete().catch(e => {});
});

cbVersion.on('collect', async (userVersion) => {

const csChangelog = interaction.channel.createMessageCollector({ filter: filterChangelog, max: 1,time: 300000 });

csChangelog.on('end', collected => {
botMsgChangelog.delete().catch(e => {});
});

csChangelog.on('collect', async (userMsgChangelog) => {

const cbChanges = interaction.channel.createMessageCollector({ filter: filterChanges, max: 1,time: 300000 });

cbChanges.on('end', collected => {
botMsgChanges.delete().catch(e => {});
});

cbChanges.on('collect', async (userMsgChanges) => {

const csImgLink = interaction.channel.createMessageCollector({ filter: filterImgLink, max: 1,time: 300000 });

csImgLink.on('end', collected => {
botMsgImgLink.delete().catch(e => {});
});

csImgLink.on('collect', async (userMsgImgLink) => {

})
})
})
})
})
17 replies