1

I'm having a problem with delivering a variable value to a function inside a class.

The specific issue occurs in the following code:

@discord.ui.select(
    row = 0,
    options = self.r
)

Here is the relevant code for the class:

class MyView(discord.ui.View):
    def __init__(self, no):
        super().__init__()
        self.no = no
        self.manga = None
        self.chapters = None
        self.startnum = -25
        self.endnum = 0 # add 25
        self.twentyfives = 0
        self.r = []
        r = []
        for i in data: 
            if  str(i["MangaName"]).lower() == no:
                self.manga =i 
                break
        if self.manga != None:
            self.chapters = int(self.manga["ChaptersNumber"])
            self.twentyfives = (self.chapters // 25)+1  
        self.startnum += 25
    
        if self.endnum + 25 > self.chapters: 
            self.endnum = self.chapters
        else: 
            self.endnum +=25
            self.startnum +=25
        for title in range(self.startnum,self.endnum):
            self.r.append(discord.SelectOption(
            label=self.manga["Chaptersinfo"][title])) 
        r = self.r
    @discord.ui.select(
        row = 0,
        options = self.r
    )
    async def select_callback(self, select, interaction): # the function called when the user is done selecting options
            manga_selected = select.values[0]
            await interaction.response.send_message(f"Awesome! I like {select.values[0]} too!")

i tried using different function to store the data then receive it again but it didn't work and i tried to let

async def select_callback 

and

 @discord.ui.select

inside the class but the async def select_callback didn't work and the options didn't show

ihl
  • 21
  • 3
  • My initial thought is that self is not available for reference for the `discord.ui.select` decorator, but I assume this would throw an error although I haven't tried this before. See the answer here: https://stackoverflow.com/a/11731208/10828043 – Michael Bridges Jan 10 '23 at 01:27

0 Answers0