#Passing variables on or something?

1 messages · Page 1 of 1 (latest)

mystic summit
#

Pass the string to your view class

#

Yes

#

No...

#

You pass the variable to the class, and receive such variable on the class init

#

And then you make it a class attribute

#

Then you need to learn OOP.

#

Pycord is based on OOP

#

You will keep getting stuck

#

"For such a simple thing"

spare island
#

you need that for every discord bot

mystic summit
#

just learn OOP frfr

lilac carbon
#

it'd prob be smth like```py
classname:
def init(self, variablename):
self.varname = variablename

def button_callback(args):
await ctx.send(self.varname)``` no clue what exactly you are doing tho

mystic summit
#

Except classname should be Classname(discord.ui.View):

#

Because youre subclassing a view

lilac carbon
#

fair

mystic summit
#

And you have to add super().__init__() inside your init

tight vectorBOT
#

Here's the confirm example.

mystic summit
#

That's a simple example ^

lilac carbon
mystic summit
#

You have to

#

super init inits the View class which gives you attributes, methods and other stuff for the view to work

lilac carbon
#

hmhm

#

only really used attributes in view classes once

#

Usually just have like 2-3 buttons inside it and not even an init def lol

maiden carbon
#

Can you pass variables to a modal in similar way?

#

(answer is yes, got it working) ty for useful info from this thread

lilac carbon
#

.close

torn houndBOT
#

Done with your help thread?

Please close your own help thread by using </close:1009144375709814897> with @tight vector.

Backup bot: </solved:1109625445990793246> (or .solved) with @torn hound.