#getting a button in another statement

158 messages · Page 1 of 1 (latest)

autumn silo
raw cedar
lofty hull
#

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

raw cedar
#

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?

lofty hull
lofty hull
raw cedar
#

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?

lofty hull
#

if u submitted

#

and i clicked the button

#

u get the roles

raw cedar
#

thats not what your initial message says xD

lofty hull
#

i cant explain

#

anyways did u get what i mean

raw cedar
#

well either use awaitModalSubmit and give the member from that interaction the role, or do it in your interactionCreate event, no difference really

lofty hull
#

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

raw cedar
#

nope, still doesnt really make sense for me

lofty hull
#

bruh

#

so how can i get the member

raw cedar
#

from what, thats the big question 🥸

lofty hull
#

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

raw cedar
#

interaction.member

lofty hull
#

that will refer to me

#

i will do it in the accepted statement

raw cedar
#

that refers to the one who triggered the interaction

lofty hull
#

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

raw cedar
#

makes sense

#

welcome to scopes

lofty hull
#

...

#

@raw cedardo u know how or no

raw cedar
#

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

lofty hull
#

ok but i did that

#

it gave me

#

not the applier

raw cedar
#

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

lofty hull
#

lemme explain more

#

an apply button

raw cedar
#

yes, makes sense so far

lofty hull
#

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?

raw cedar
#

so YOU press accept and the person who posted the MODAL gets the role

lofty hull
#

ye

raw cedar
#

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

lofty hull
#

can i save it in a db?

raw cedar
#

sure I guess?

#

but I dont think you need a db for that

lofty hull
#

will be easier to type

raw cedar
lofty hull
#

how to get it again?

raw cedar
#

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

lofty hull
raw cedar
#

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

lofty hull
#

ohh

#

but even same error

raw cedar
#

how did you do it now

#

also you have to fetch the member, not grab them from cache

#

await interaction.guild.members.fetch('id')

lofty hull
#

member2 instead of id ?

#

member3.roles.add(role)
^

TypeError: Cannot read properties of undefined (reading 'add')

#

bru

#

h

devout dagger
lofty hull
#

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

devout dagger
lofty hull
devout dagger
#

wdym

lofty hull
#

the command will be for all members

#

can apply

devout dagger
#

How are you getting the id of member3

#

or do you have any id of member3

lofty hull
#

im trying to get from the embed author id

young mapleBOT
devout dagger
#

it doesn't has an id property

lofty hull
#

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

devout dagger
#

guild.members.fetch({ query: name, limit: 1 }) try this

lofty hull
#

name is not defined

devout dagger
lofty hull
#

member3.roles.add(role)
^

TypeError: Cannot read properties of undefined (reading 'add')

devout dagger
#

await the fetch

lofty hull
#

still

devout dagger
#

show code

lofty hull
#

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 })
}

raw cedar
#

and whats in the embed author field actually now

lofty hull
raw cedar
#

show it

#

or log member2 and member3

lofty hull
raw cedar
#

you mean the name

#

it cant be the id if you set it to username

lofty hull
#

it gave the id 🙂

raw cedar
#

that cant even be the case if you set it to username

lofty hull
#

how then

#

did this and still giving i

#

d

devout dagger
#

that's impossible meguFace

lofty hull
#

gave undefined

devout dagger
#

this is a bit messed up, User.username can never be numbers, User.id can never be undefined at all

devout dagger
# lofty hull

can you log interaction and make sure it's an actual interaction?

devout dagger
#

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

raw cedar
raw cedar
lofty hull
raw cedar
#

show us...

lofty hull
#

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 }
}

raw cedar
#

????

#

how

raw cedar
# lofty hull

this is not how you set the author name of the embed then

lofty hull
#

i followed the guide 🙂

raw cedar
#

dont blame it on the guide now, thanks

#

the code you showed does not match what you are logging

lofty hull
#

wdym LOL

#

that is what i logged

#

the embed

#

u told me log the embed i did

raw cedar
#

Yes

#

Doesnt change the fact that it doesnt match the code you showed

lofty hull
#

then take it and test it ur self

raw cedar
#

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

lofty hull
raw cedar
#

again, the code you send does NOT match the logged embed
user.username does NOT return an id, it returns a USERNAME as you showed at the beginning of this post

#

so idfk how you managed to get an id in there without having the code do it