Giter Club home page Giter Club logo

Comments (4)

Jiralite avatar Jiralite commented on August 23, 2024 1

data is the data you set for the button builder, and data.data is the immutable data received from the API, if at all. API data is not supposed to be mutable. Otherwise, the representation of the received button would be incorrect. This is not a bug.

from discord.js.

Jiralite avatar Jiralite commented on August 23, 2024 1

API data is passed into the constructor, so it accepts the JSON payload.

If you want to edit a given button before sending it back to the API, you would use ButtonBuilder#from():

import { type ButtonInteraction, ActionRowBuilder, ButtonBuilder } from "discord.js";

declare const buttonInteraction: ButtonInteraction;
const { component } = buttonInteraction;

// We want to disable the button that was interacted with.
// First, we need to create a new button builder from the immutable API data.
const button = ButtonBuilder.from(component);

// Proceed as normal.
button.setDisabled(true);

// Make a new action row to put the button in.
// To reuse the action row, follow the same semantics as above.
const actionRow = new ActionRowBuilder<ButtonBuilder>().setComponents(button);

// Respond to the interaction.
buttonInteraction.update({ components: [actionRow] });

from discord.js.

MatthewFallon avatar MatthewFallon commented on August 23, 2024

@Jiralite Thank you for the update, perhaps I'm misunderstanding the intent of the class constructor then. I am using Typescript so I am seeing the typings allowed to the constructor. Why does the ButtonBuilder class constructor accept ButtonComponent (based on it being API compliant) if it then creates an action row builder that cannot resolve without manually setting every field again? My general expectation was that if I provide the mutable ButtonBuilder class an immutable ButtonComponent class it would essentially clone that class in some manner to allow me to edit a given button before sending it back to the API.

from discord.js.

MatthewFallon avatar MatthewFallon commented on August 23, 2024

@Jiralite thank youuuu! sorry about the invalid issue then, 😅 I definitely missed that helper function. that rationale makes sense on why it is made that way then.

from discord.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.