Interactions overlapping? (I don't know what even happening anymore)

I have command that sends a ephemeral message with buttons, and then using message collector to get response from buttons.
const componentCollector = message.channel.createMessageComponentCollector({
filter: (int) => (int.user.id === interaction.user.id),
componentType: ComponentType.Button,
time: 60_000,
message,
max: 1,
})
const componentCollector = message.channel.createMessageComponentCollector({
filter: (int) => (int.user.id === interaction.user.id),
componentType: ComponentType.Button,
time: 60_000,
message,
max: 1,
})
I have a function that handles response:
componentCollector.on("collect", (buttonInteraction) => {
handleSelectedConvertType(buttonInteraction, interaction) // interaction - is initial interaction that comes when user executed /command
componentCollector.stop("collected")
})
componentCollector.on("collect", (buttonInteraction) => {
handleSelectedConvertType(buttonInteraction, interaction) // interaction - is initial interaction that comes when user executed /command
componentCollector.stop("collected")
})
In this function i'm getting options that user provide when executed /command, and creating some embeds with description Problem is here:
randomSelectedEmbed.description = randomSelectedEmbed.description.replace(
"%link%",
initialInteraction.user.toString()
)
randomSelectedEmbed.description = randomSelectedEmbed.description.replace(
"%link%",
initialInteraction.user.toString()
)
And somehow if two users manage to click button on the same time initialInteraction.user.toString() will be not what we expect. For example: I clicked button and should see in response my mention, but I see mention of my friend that manage to click it on the same time If I use buttonInteraction instead - all works fine. But i'm curious why initialInetraction picking up different user
DT
d.js toolkit92d 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
S
secre92d ago
In this example bot place mention of me instead of my friend. But I was doing literally NOTHING. I guess here problem with cache or maybe intents? Because I have no idea how bot picking up random people :DEAD:
DD
d.js docs92d ago
Tag suggestion for @secre: If you are waiting for button or select menu input from a specific message, don't create the collector on the channel. - Channel collectors return component interactions for any component within that channel.
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
S
secre92d ago
For more context callback for interactionCreate event
function handleCommand(interaction: ChatInputCommandInteraction) {
const commandName = interaction.commandName
const foundCommand = commands.find(({ name }) => name === commandName)

if (!foundCommand) return

foundCommand.exec(interaction)
}
function handleCommand(interaction: ChatInputCommandInteraction) {
const commandName = interaction.commandName
const foundCommand = commands.find(({ name }) => name === commandName)

if (!foundCommand) return

foundCommand.exec(interaction)
}
and intents that I'm currently using const client = new Client({ intents: [IntentsBitField.Flags.Guilds] }) Changed to that, and same bug appears anyways :)
A
Amgelo92d ago
probably why you're getting "random people", it's picking interactions from other components share your updated code
S
secre92d ago
On this example noone was executing command
const componentCollector = message.createMessageComponentCollector({
filter: (int) => int.user.id === interaction.user.id,
componentType: ComponentType.Button,
time: 60_000,
max: 1,
})
const componentCollector = message.createMessageComponentCollector({
filter: (int) => int.user.id === interaction.user.id,
componentType: ComponentType.Button,
time: 60_000,
max: 1,
})
the message:
const message = await interaction.deferReply({
ephemeral: true,
fetchReply: true,
})
const message = await interaction.deferReply({
ephemeral: true,
fetchReply: true,
})
A
Amgelo92d ago
can you share your "handleSelectedConvertType"?
S
secre92d ago
async function handleSelectedConvertType(
interaction: ButtonInteraction,
initialInteraction: ChatInputCommandInteraction
) {
await interaction.deferReply({ ephemeral: true })

const moderationChannel = await interaction.guild?.channels.fetch(
process.env.APPROV_CHANNEL_ID!
)

if (!moderationChannel || moderationChannel.type !== ChannelType.GuildText) {
return interaction.editReply({
content: "Ой.. произошла ошибка во время выполнения команды...",
})
}

const valentineText = initialInteraction.options.getString("текст", true)
const attachment = initialInteraction.options.getAttachment("картинка")
const user = initialInteraction.options.getUser("юзер", true)

const randomSelectedEmbed = getRandomResponse()

randomSelectedEmbed.description = randomSelectedEmbed.description.replace(
"%link%",
initialInteraction.user.toString()
)

const buildedEmbed = new EmbedBuilder(randomSelectedEmbed).setColor("#2b2d31")

const moderationEmbed = new EmbedBuilder()
.setDescription(valentineText)
.setFooter({
text: `${getConvertType(interaction.customId)} ${initialInteraction.user.id} ${
user.id
}`,
})
.setColor("#2b2d31")
.setAuthor({
name: initialInteraction.user.username,
iconURL: initialInteraction.user.displayAvatarURL(),
})

if (attachment) {
moderationEmbed.setImage(attachment.url)
}

interaction.editReply({ embeds: [buildedEmbed] }).catch((err) => {
console.log("Ошибка во время попытки ответить на выбор конверта", err)
})

moderationChannel
.send({
embeds: [moderationEmbed],
components: [createModerationRow()],
})
.catch((err) => {
console.log(`Ошибка во время отправки валентинки на модерацию`, err)
})
}
async function handleSelectedConvertType(
interaction: ButtonInteraction,
initialInteraction: ChatInputCommandInteraction
) {
await interaction.deferReply({ ephemeral: true })

const moderationChannel = await interaction.guild?.channels.fetch(
process.env.APPROV_CHANNEL_ID!
)

if (!moderationChannel || moderationChannel.type !== ChannelType.GuildText) {
return interaction.editReply({
content: "Ой.. произошла ошибка во время выполнения команды...",
})
}

const valentineText = initialInteraction.options.getString("текст", true)
const attachment = initialInteraction.options.getAttachment("картинка")
const user = initialInteraction.options.getUser("юзер", true)

const randomSelectedEmbed = getRandomResponse()

randomSelectedEmbed.description = randomSelectedEmbed.description.replace(
"%link%",
initialInteraction.user.toString()
)

const buildedEmbed = new EmbedBuilder(randomSelectedEmbed).setColor("#2b2d31")

const moderationEmbed = new EmbedBuilder()
.setDescription(valentineText)
.setFooter({
text: `${getConvertType(interaction.customId)} ${initialInteraction.user.id} ${
user.id
}`,
})
.setColor("#2b2d31")
.setAuthor({
name: initialInteraction.user.username,
iconURL: initialInteraction.user.displayAvatarURL(),
})

if (attachment) {
moderationEmbed.setImage(attachment.url)
}

interaction.editReply({ embeds: [buildedEmbed] }).catch((err) => {
console.log("Ошибка во время попытки ответить на выбор конверта", err)
})

moderationChannel
.send({
embeds: [moderationEmbed],
components: [createModerationRow()],
})
.catch((err) => {
console.log(`Ошибка во время отправки валентинки на модерацию`, err)
})
}
Damn my I should upload it to pastebin or something? It's a bit large in here :DEAD:
A
Amgelo92d ago
we're on a thread so ig it's fine
S
secre92d ago
I sent you code where I already changed initialInteraction to interaction, edited it to be more correct with info I provided Testing code with buttonInteraction that we receive in collector, and it putting different user anyway, lol
S
secre92d ago
I have this embed in moderation channel that as you can see getting ids, name, avatar from initiailInteraction and ids are correct, avatar and username correct too but in response embed it's different :Starege:
No description
A
Amgelo92d ago
the only thing that comes to mind is an issue by passing the reference instead of a copy of your "random embed" could be solved with
const newDescription = randomSelectedEmbed.description.replace(
"%link%",
initialInteraction.user.toString()
)

const buildedEmbed = new EmbedBuilder(randomSelectedEmbed).setDescription(newDescription).setColor("#2b2d31")
const newDescription = randomSelectedEmbed.description.replace(
"%link%",
initialInteraction.user.toString()
)

const buildedEmbed = new EmbedBuilder(randomSelectedEmbed).setDescription(newDescription).setColor("#2b2d31")
instead of directly editing randomSelectedEmbed
S
secre92d ago
But how it can be a problem? I will test your example fs but I can't understand why :yM_kekw: Let me show you example of those "embeds"
{
"description": `%link%, __Ваша__ валентинка получена, топаем к пункту распределения! ${process.env.RESPONSE_EMOJI}`,
"footer": { "text": "Отделение Yume №3 → Проверка → Валентинки." },
"thumbnail": { "url": "https://i.imgur.com/xntg0cd.png" },
},
{
"description": `%link%, __Ваша__ валентинка получена, топаем к пункту распределения! ${process.env.RESPONSE_EMOJI}`,
"footer": { "text": "Отделение Yume №3 → Проверка → Валентинки." },
"thumbnail": { "url": "https://i.imgur.com/xntg0cd.png" },
},
that's one of them. simple object of embed with %link% to put mention in the future
A
Amgelo92d ago
it would depend on how your getRandomResponse() actually works but you could try just in case if not no idea, maybe someone else could help try logging and see where it fails down the line ig
S
secre92d ago
export function getRandomResponse() {
return RESPONSES[Math.floor(Math.random() * RESPONSES.length)]
}
export function getRandomResponse() {
return RESPONSES[Math.floor(Math.random() * RESPONSES.length)]
}
I logging IDS and ITS all the way correct :KEKL: Just embed description where everything breaks
S
secre92d ago
Here my friend executed command 5 times, and 4 times he saw mention of me instead of him in response :yM_kekw: But as you can see here is no ID of mine
No description
S
secre92d ago
weird thing
A
Amgelo92d ago
yeah that seems to be passing a reference instead of a copy if you pass a reference, you're directly editing your responses object so your random embed would now be
{
"description": `<@shysecre>, __Ваша__ валентинка получена, топаем к пункту распределения! ${process.env.RESPONSE_EMOJI}`,
"footer": { "text": "Отделение Yume №3 → Проверка → Валентинки." },
"thumbnail": { "url": "https://i.imgur.com/xntg0cd.png" },
},
{
"description": `<@shysecre>, __Ваша__ валентинка получена, топаем к пункту распределения! ${process.env.RESPONSE_EMOJI}`,
"footer": { "text": "Отделение Yume №3 → Проверка → Валентинки." },
"thumbnail": { "url": "https://i.imgur.com/xntg0cd.png" },
},
S
secre92d ago
Oh wait :Deadge:
A
Amgelo92d ago
https://www.geeksforgeeks.org/pass-by-value-and-pass-by-reference-in-javascript/
In Pass by Reference, Function is called by directly passing the reference/address of the variable as an argument. So changing the value inside the function also change the original value. In JavaScript array and Object follows pass by reference property.
GeeksforGeeks
Pass by Value and Pass by Reference in Javascript - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
A
Amgelo92d ago
you could solve it by doing this or passing a shallow copy in your getRandomResponse instead
DD
d.js docs92d ago
:mdn: Shallow copy A shallow copy of an object is a copy whose properties share the same references (point to the same underlying values) as those of the source object from which the copy was made. As a result, when you change either the source or the copy, you may also cause the other object to change too. That behavior contrasts with the behavior of a deep copy, in which the source and copy are completely independent.
A
Amgelo92d ago
a shallow copy would work unless you also edit your footer objects (since it's nested), for that you'd need a deep copy could also do this instead
export function getRandomResponse() {
return new EmbedBuilder(RESPONSES[Math.floor(Math.random() * RESPONSES.length)])
}
export function getRandomResponse() {
return new EmbedBuilder(RESPONSES[Math.floor(Math.random() * RESPONSES.length)])
}
S
secre92d ago
What a newbie mistake goddammit :Deadge: Thanks, will fix
A
Amgelo92d ago
I don't blame you much since I also had a dumb issue like that once lol
S
secre92d ago
I guess we all had problems like this xd
A
Amgelo92d ago
it also messed up my brain for a while
A
Amgelo92d ago
I think this is the easiest way since you don't need to remember to make a copy every time or something
ACO
A cup of tea "Richard"92d ago
I was the one who tested this problem with him. I knew something was wrong with getRandomResponse() function 😭 It also was the promblem who didn't showed up immediatly, because we have like 3 messages in random pool. So somitems it can just take two different ones and it will work like a charm 💀
A
Amgelo92d ago
:kek:
ACO
A cup of tea "Richard"92d ago
Anyway thank u man for helping us fix this problem 🤝
A
Amgelo92d ago
np :blobreachReverse:
Want results from more Discord servers?
Add your server
More Posts
URL Audio Resource Streaming Stopped Workingidk whats going on so maybe one of you can help... my bot has been broken for a few months I thoughtHow to make an autocomplete list from mongodb entriesSo I have an array of objects, i want to display the name field of each object in a list, and then oSend message to specific channelHow can I send a message to a specific channel of my guild?Ticket SupportWhy when i run the bot, the terminal gave me this error?Can someone help to complete this command?I have a ticket command here, but I don't know how to make a channel that opens from a button:Webhook send channelId optionIs it possible to parse a channel ID on the webhook.send method for it to send to a thread rather thIssue with Select MenuHello, I'm new with select menus, I tried them today but the bot isn't responding to them. The consoinvalid from body```DiscordAPIError[50035]: Invalid Form Body 14.options[3][APPLICATION_COMMAND_OPTIONS_TYPE_INVALID]invalid from body```DiscordAPIError[50035]: Invalid Form Body 14.options[3][APPLICATION_COMMAND_OPTIONS_TYPE_INVALID]LatencyAfter I created shards for bot, latency went from 8-10 to 200 and this happens sometimesmodal submit unknown interaction```js await interaction.showModal(modal); //ButtonInteraction const filter = (i) => MODALhey, how can add textlabel in modal please?Add points to multiple users at onceI want to make 3 optional options to add points to multiple users at once, How can I achieve that wiAuthentication failed at WebSocketShard.onCloseI get this error once every few weeks and discord resets my bot's token. ```Unhandled rejection: AutFor some reason my collecter won't work?It doesn't give me an error or anything and ive been debugging for about 6 hours now. Any pointers aEmbed is only sending once every time the slash command is ran every active sessionBy every active session I mean every time the bot is online. I have a slash command that is like anDownload Node JS without admin rightsHello i want to know if it's possible to install node js npm without admin rights please403 Error due to new image expiration?Hey all, I'm unfortunately having issues with a ticket transcript system that I created for my discoGetting: Invalid bitfield flag or number: VIEW_CHANNEL. (creating a text channel)dont rlly know. code: ```js collector.on('collect', async(i) => { const selectioAnonymous bot sub-users (PluralKit)How would I create anonymous bot sub users like what PluralKit and similar bots do? The users are m