Comments (4)
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.
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.
@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.
@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)
- Network errors still happening HOT 4
- TypeError: thread.members._add is not a function HOT 4
- Application Emojis HOT 2
- Client being destroyed before ready event when shard receives unexpected response 520 HOT 1
- Bot crash due to TypeError: Cannot read properties of undefined (reading 'get') handing THREAD_MEMBERS_UPDATE packet HOT 2
- Error [GuildMembersTimeout]: Members didn't arrive in time.
- Music is not playing in voice channel HOT 2
- WebSocketManager trying to access shard info while shard or shardId could be undefined HOT 6
- InteractionWebhook methods crash the app if an invalid token is provided HOT 4
- Unexpected end of JSON input when using `ZlibNative` & `zlib-stream` transport compression HOT 1
- Add USE_EXTERNAL_APPS Permission to permissionOverwrites HOT 1
- message.mentions.users.first() returns undefined HOT 2
- Group buttons produce no data in version `14.15.3` HOT 2
- Newly created emojis aren't added to cache HOT 4
- Error: Specified member is not UserResolvable. - TypeError [InvalidType]: Specified member is not a UserResolvable (ThreadMemberManager.add ) HOT 3
- Add type safety to interface AuditLogChange
- OAuth2 method for token revoke endpoint HOT 2
- Error happens when trying to edit a followup message: [Could not find the channel where this message came from in the cache!] HOT 8
- Bot prematurely ends output audio stream when I stop speaking HOT 1
- Type error with permissionOverwrites HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discord.js.