【发布时间】:2021-10-16 05:44:12
【问题描述】:
这就是我创建和发送按钮的方式:
client.on('messageCreate', (message) => {
/* ... Checking Command ... */
const actionRow = new MessageActionRow().addComponents(
new MessageButton()
.setStyle("PRIMARY")
.setLabel("X")
.setCustomId("test"));
message.channel.send({ content: "Test", components: [actionRow] });
}
如预期的那样,聊天中会出现一个蓝色按钮。
这是我的按钮监听器:
client.on("interactionCreate", (interaction) => {
if (interaction.isButton()) {
if (interaction.customId === "test") {
//Before: console.log(interaction.component);
interaction.component.setStyle("DANGER");
//After: console.log(interaction.component);
}
}
});
在.setStyle("DANGER") 之前和之后记录组件对象还显示,样式已成功从主要更改为危险。
但在我的 Discord 客户端中,样式/颜色没有改变,除此之外,我收到一个错误,说交互失败。
样式属性似乎不是只读的:https://discord.js.org/#/docs/main/stable/class/MessageButton?scrollTo=style
那我做错了什么?
【问题讨论】:
标签: javascript node.js discord discord.js