#Rebuilding buttons, SocketMessageComponent, and TypeReader errors

1 messages · Page 1 of 1 (latest)

small sigil
#

In my InteractionModule.cs, I have a [ComponentInteraction] that is mean to rebuild an array of buttons upon being pressed. When I run my bot, I get the following error:

System.ArgumentException: 'No type TypeReader is defined for this Discord.WebSocket.SocketMessageComponent (Parameter 'type')'

To my understanding, a TypeReader will allow me to pass the customIds of the buttons I'm regenerating. For this context, I am confused on how to implement a TypeReader (or rather, where to put it, and how to convert data for my use).
Here's the section of my InteractionModule.cs I am using:

 [ComponentInteraction("button*")]
        public async Task RebuilderHandler(SocketMessageComponent component)
        {
            void generateButtonGrid(ComponentBuilder builder, int rows, int cols, string id)
            {

                string buttonName = "button";
                int buttonNumber = 0;

                for (int i = 0; i < rows; i++)
                {
                    buttonNumber++;
                    buttonName = "button";
                    buttonName += buttonNumber.ToString();

                    if (buttonName == id)
                    {
                        builder.WithButton("\n", buttonName, ButtonStyle.Success, disabled: true, row: i);
                    }
                    else
                    {
                        builder.WithButton("\n", buttonName, ButtonStyle.Secondary, row: i);
                    }

                    for (int j = 0; j < cols - 1; j++)
                    {
                        buttonNumber++;
                        buttonName = "button";
                        buttonName += buttonNumber.ToString();

                        if (buttonName == id)
                        {
                            builder.WithButton("\n", buttonName, ButtonStyle.Success, disabled: true, row: i);
                        }
                        else
                        {
                            builder.WithButton("\n", buttonName, ButtonStyle.Secondary, row: i);
                        }
                    }
                }
            }

            var builder = new ComponentBuilder();
            generateButtonGrid(builder, 5, 5, component.Data.CustomId);
            await component.UpdateAsync(x => x.Components = builder.Build());
        }

Maybe there is something else I'm missing, or perhaps I wrote something wrong. Help is much appreciated moon2S

keen relic
#

uhmmmm

#

why do you have a void inside a Task

#

that's offtopic

#

IF will try to parse a wildcard part of the custom id & convert it to the parameter - to SocketMessageComponent in your case

#

but this does not make any sense

#

if you need to get components of the message the button is attached to - do the following

#
var msg = (Context.Interaction as IComponentInteraction).Message;
var builder = ComponentBuilder.FromMessage(msg);
#

and remove the SocketMessageComponent component parameter

small sigil
#

Since the component parameter was allowing me to grab the customId of the button being pressed, how would I get that data from the code you gave above?