TTastic
TTastic
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
Tested with 4 accounts this time. Seems to have worked nicely! Thank you again @wolvinny🌈 for being patient with me. I understand what I messed up well enough to hopefully avoid it in the future! 🙂
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
I would assume, just looks too easy! lol. Thanks, gonna test it thouroughly here.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
Does that look correct for setting it to the message as opposed to channel?
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
// Respond with the location info embed and buttons
await interaction.editReply({
embeds: [locationEmbed],
components: [rowActivities],
});


const locationMessage = await interaction.editReply({
embeds: [locationEmbed],
components: [rowActivities],
});


//Define the collector for the button components
const collector = locationMessage.createMessageComponentCollector({
componentType: ComponentType.Button,
filter: (i) => i.user.id === interaction.user.id, // Filter so only the person who used the command can react
});
// Respond with the location info embed and buttons
await interaction.editReply({
embeds: [locationEmbed],
components: [rowActivities],
});


const locationMessage = await interaction.editReply({
embeds: [locationEmbed],
components: [rowActivities],
});


//Define the collector for the button components
const collector = locationMessage.createMessageComponentCollector({
componentType: ComponentType.Button,
filter: (i) => i.user.id === interaction.user.id, // Filter so only the person who used the command can react
});
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
Sorry, ctrl+z'd a bit much. Was setting up to store message. One sec.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
Should I store the editReply message in a variable and set collector to that?
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
This is the full code, relevant collector lines start at around line 85
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
I understand you're saying to do that - I'm not sure how. From what I've read even after your reply, I'm still of the mind that my code should already be attaching it directly to the interaction message. Obviously that's not working, so I'm trying again to re-read the documentation.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
As far as I'm aware my code already should be attaching the collector directly to the interaction, so
const collector = interaction.channel.createMessageComponentCollector
const collector = interaction.channel.createMessageComponentCollector
If thats only attaching it to the channel the buttons are in, whats the correct way to do it? I'm not logging any errors when it runs as posted, but others are able to respond regardless of the filter.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
Actually did not solve, seemed to at first. But I will keep as 'Button' and attempt to attach the collector instead to the message as recommended.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
I kept it as interaction.channel.createMessageComponentCollector and ONLY changed BUTTON to Button...that did the trick! I'm getting some other unrelated error now but I can solve that one. Thanks for the help 🙂
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
Oh wait ok, sorry, I'm self taught and really bad with terminology. Based on what you said I assume that line means I'm attaching the collector to the interactions channel and not to the interaction message itself and that's why others can respond? And by setting the collector instead to the actual interaction message it'll achieve the desired effect? Sorry, just wanting to make sure I understand the logic so I can stop myself from making the mistake in the future.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
Are you saying I should replace to = interaction.message.createMessageComponentCollector ?
const collector = interaction.channel.createMessageComponentCollector
const collector = interaction.channel.createMessageComponentCollector
Or do you mean the componenttype where I have the button? Sorry, just trying to clarify what you mean. It seems I should have the collector be only for the interaction and not the channel, but if I change it to interaction.message I start getting typeerrors.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/11/2023 in #djs-questions
Issue understanding collector filters
The collector is on the main script for a slash command, I ran the command myself and the buttons appeared. I have someone next to me in real life click one of the buttons on my interaction on their discord account and it ran for them sucessfully even though it was my accounts interaction.
30 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/9/2023 in #djs-questions
Deferrals
Just wanted to pop back and let you know everything seems smoother now. It never clicked with me the await was taking the time up even though that makes perfect sense. Thanks again for helping a rookie out 🙂
20 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/9/2023 in #djs-questions
Deferrals
Absolutely, I appreciate the advice on best practices. Just frutsrating trying to learn how to diagnose whether is a user issue or network issue on my end lol. (90% of the time its me 😛 )
20 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/9/2023 in #djs-questions
Deferrals
Thank you, Im still trying to catchup and learn to use proper terminology. I appreciate the breakdown. 🙂 Im gonna try a few things with that. Even if Im self hosting with my slow connection, everything should still go through without the 10062 if I set it up properly, right?
20 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/9/2023 in #djs-questions
Deferrals
OH WAIT. Sorry, like I said, new. I see what you're saying. I need to defer it before I declare that constant which checks my database...right?
20 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/9/2023 in #djs-questions
Deferrals
It scans a collection in my database to see if the user has any associated information so Im guessing that may be it. Im relatively new to this, so are you saying to run the deferReply before the try block or to just remove the await from the initial defer altogether?
20 replies
DIAdiscord.js - Imagine an app
Created by TTastic on 9/9/2023 in #djs-questions
Deferrals
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { checkHearthProfile } = require('../utils/verifications/profileVerify'); // Import profile verification function

module.exports = {
data: new SlashCommandBuilder()
.setName('location')
.setDescription("Check your current location in the game world"),

async run({ interaction }) {

try {

const userWhoRan = interaction.user;
const hasHearthProfile = await checkHearthProfile(interaction, userWhoRan.id);
console.log(`💻User who ran the /location command: ${userWhoRan.tag}`);

// Defer the initial response, more than 3 seconds without a response will cause a Discord API error
await interaction.deferReply();

if (!hasHearthProfile) {
await interaction.reply('Oops! You need to register!');
return;
} else {

// If a profile is found, respond with a "Location placeholder" embed
const profileFoundEmbed = new EmbedBuilder()
.setTitle(' :warning: Location placeholder')
.setColor('#FFD700') // Dark yellow color
.setDescription('This is coming soon.');

// Respond with the "Location placeholder" embed
await interaction.editReply({ embeds: [profileFoundEmbed] });
}

// Additional logic for the location command

} catch (error) {
console.error(':no_entry_sign:Error while querying the database:', error);
}
},

options: {
// deleted: true;
devOnly: true,
},
};
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { checkHearthProfile } = require('../utils/verifications/profileVerify'); // Import profile verification function

module.exports = {
data: new SlashCommandBuilder()
.setName('location')
.setDescription("Check your current location in the game world"),

async run({ interaction }) {

try {

const userWhoRan = interaction.user;
const hasHearthProfile = await checkHearthProfile(interaction, userWhoRan.id);
console.log(`💻User who ran the /location command: ${userWhoRan.tag}`);

// Defer the initial response, more than 3 seconds without a response will cause a Discord API error
await interaction.deferReply();

if (!hasHearthProfile) {
await interaction.reply('Oops! You need to register!');
return;
} else {

// If a profile is found, respond with a "Location placeholder" embed
const profileFoundEmbed = new EmbedBuilder()
.setTitle(' :warning: Location placeholder')
.setColor('#FFD700') // Dark yellow color
.setDescription('This is coming soon.');

// Respond with the "Location placeholder" embed
await interaction.editReply({ embeds: [profileFoundEmbed] });
}

// Additional logic for the location command

} catch (error) {
console.error(':no_entry_sign:Error while querying the database:', error);
}
},

options: {
// deleted: true;
devOnly: true,
},
};
20 replies