#getting a button in another statement
158 messages · Page 1 of 1 (latest)
Why did you reply to a year old post wtf
currently i got a apply button that when u click it it shows a modal and after it sends the modal inputed values to a specified channel
and it has a button called accept what i want to do that when i click accept it gives the person who clicked the apply button a role but it gives me when i do that
Show the relevant code on how you add the role
Also, you sure the guy who clicked accept should get the role, not the one who made the modal?
nope not sure did many things like collector and still cant get the one clicked the modal apply
i did collector but still so i just removed what i did and currently nothing is defined as it
So... someone makes a modal and submits it...
the stuff from the modal get posted to a message with a button
and whoever clicks that button gets the role?
no
if u submitted
and i clicked the button
u get the roles
thats not what your initial message says xD
well either use awaitModalSubmit and give the member from that interaction the role, or do it in your interactionCreate event, no difference really
but i just want to give roles if i clicked accept button
- 2 diffrent statements 1 has the apply button 1 has the accept
so idk how to get the member in the first statement
nope, still doesnt really make sense for me
from what, thats the big question 🥸
uhhh
2 statments
if custom id === apply
shows modal
<channel>.send(modal inputted value)
}
if custom id === accepted
the member who sent the apply button.roles.add(role)
}
but i cant get the member who clicked the apply button in the accepted statement
interaction.member
that refers to the one who triggered the interaction
ye but if i did let member = interaction.member in apply button
and did member.roles.add in accepted it will asy member is not defined
stop defining stuff you need in other scopes inside of a scope unreachable by other scopes?
just use interaction.member
there is no point in using an extra variable for this
then who tf is the applier
who is clicking the button
so far you gave no information about who gets the role and when at what interaction
yes, makes sense so far
shows a modal with 4 input text
then
shows this
the 4 inputted text
and apply again
and accept
what i want that
if clicked the accpet
it gives the person who applied a role
but idk how to define within 2 diffrent statements
did u get it now?
so YOU press accept and the person who posted the MODAL gets the role
ye
then you will have to save the member id either in the customId or you wait for the button click via collector and use .member from the modal interaction where you send the message with the 4 buttons
or save the id in the embed author field and parse it later
can i save it in a db?
will be easier to type
this should be pretty easy to do
how to get it again?
interaction.message.embeds[0].author.name to get the whole name set in the embed author field
then you have to parse it to get the id, how you do that is up to you and depends how you format the author field
if(interaction.customId == "accepted") {
let member2 = interaction.message.embeds[0].author.id;
let member3 = interaction.guild.members.cache.get(member2)
let role = "710603812502765605"
member3.roles.add(role)
interaction.reply({content: 'Done, Accepted', ephemeral : true })
}
did this but cannot find prop of undefined roles
yes, no, this isnt how this works
embed.author is an embedauthor object, containing name, iconurl and url
not an id
thats why I told you to parse it from the name
how did you do it now
also you have to fetch the member, not grab them from cache
await interaction.guild.members.fetch('id')
member2 instead of id ?
member3.roles.add(role)
^
TypeError: Cannot read properties of undefined (reading 'add')
bru
h
show the new code
if(interaction.customId == "accepted") {
let member2 = interaction.message.embeds[0].author.name;
let member3 = interaction.guild.members.fetch('id')
let role = "710603812502765605"
member3.roles.add(role)
interaction.reply({content: 'Done, Accepted', ephemeral : true })
}
tried member2 instead of id too
put the actual id in place of 'id'
but its not a specified member
wdym
im trying to get from the embed author id
EmbedAuthorData
The options to provide for setting an author for a [MessageEmbed](<https://discord.js.org/#/docs/discord.js/stable/class/MessageEmbed>).
it doesn't has an id property
ye
but im getting the name
then id of the name
let member2 = interaction.message.embeds[0].author.name;
let member3 = interaction.guild.members.fetch(member2)
tried to do this
ut still
guild.members.fetch({ query: name, limit: 1 }) try this
name is not defined
put the name you want there
member3.roles.add(role)
^
TypeError: Cannot read properties of undefined (reading 'add')
await the fetch
still
show code
if(interaction.customId == "accepted") {
let member2 = interaction.message.embeds[0].author.name;
let member3 = await interaction.guild.members.fetch({ query: member2, limit: 1 })
let role = "710603812502765605"
member3.roles.add(role)
interaction.reply({content: 'Done, Accepted', ephemeral : true })
}
and whats in the embed author field actually now
interaction.user.username
member2 gave me the id of the applier
that cant even be the case if you set it to username
that's impossible 
this is a bit messed up, User.username can never be numbers, User.id can never be undefined at all
can you log interaction and make sure it's an actual interaction?
the id and username are clearly there on user and they are correct fields too, so they can't be undefined and username can't be the id either
they are still referring to embedauthor.id
log interaction.message.embeds[0]
showed the embed info
show us...
MessageEmbed {
type: 'rich',
title: 'server name',
description: null,
url: null,
color: 9451399,
timestamp: null,
fields: [
{ value: '2', name: 'الاسم :', inline: false },
{ value: '3', name: 'العمر :', inline: false },
{ value: '4', name: 'التفاعل :', inline: false },
{ value: '5', name: 'الخبرات :', inline: false }
],
thumbnail: null,
image: null,
video: null,
author: {
name: '712096981303951430',
url: undefined,
iconURL: 'https://cdn.discordapp.com/embed/avatars/1.png',
proxyIconURL: 'https://images-ext-2.discordapp.net/external/GyQicPLz_zQO15bOMtiGTtC4Kud7JjQbs1Ecuz7RrtU/https/cdn.discordapp.com/embed/avatars/1.png'
},
provider: null,
footer: { text: 'By Mohamed', iconURL: undefined, proxyIconURL: undefined }
}
this is not how you set the author name of the embed then
i followed the guide 🙂
dont blame it on the guide now, thanks
the code you showed does not match what you are logging
then take it and test it ur self
dont need to, cuz I know what user.username returns
definitely not the id
share the whole code of all relevant files in a bin and send it here
u just told me do the name
